[Catalyst-commits] r9298 - in
Catalyst-Controller-DBIC-API/1.001/branches/pagination: .
lib/Catalyst/Controller/DBIC lib/Catalyst/Controller/DBIC/API
abraxxa at dev.catalyst.perl.org
abraxxa at dev.catalyst.perl.org
Fri Feb 13 16:51:26 GMT 2009
Author: abraxxa
Date: 2009-02-13 16:51:25 +0000 (Fri, 13 Feb 2009)
New Revision: 9298
Modified:
Catalyst-Controller-DBIC-API/1.001/branches/pagination/Changes
Catalyst-Controller-DBIC-API/1.001/branches/pagination/lib/Catalyst/Controller/DBIC/API.pm
Catalyst-Controller-DBIC-API/1.001/branches/pagination/lib/Catalyst/Controller/DBIC/API/Base.pm
Log:
Added pagination support + docs
Modified: Catalyst-Controller-DBIC-API/1.001/branches/pagination/Changes
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/pagination/Changes 2009-02-13 16:39:35 UTC (rev 9297)
+++ Catalyst-Controller-DBIC-API/1.001/branches/pagination/Changes 2009-02-13 16:51:25 UTC (rev 9298)
@@ -4,7 +4,8 @@
- Removed duplicate tests in t/rpc/list.t and t/rest/list.t
- Fixed searches on columns which have a rel with the same name
and vice versa + tests
-- Added search by json + test
+- Added search by json + docs + test
+- Added pagination support + docs
1.001000
- Added setup_list_method configuration flag (jshirley)
- Added support for setting config params in stash
Modified: Catalyst-Controller-DBIC-API/1.001/branches/pagination/lib/Catalyst/Controller/DBIC/API/Base.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/pagination/lib/Catalyst/Controller/DBIC/API/Base.pm 2009-02-13 16:39:35 UTC (rev 9297)
+++ Catalyst-Controller-DBIC-API/1.001/branches/pagination/lib/Catalyst/Controller/DBIC/API/Base.pm 2009-02-13 16:51:25 UTC (rev 9298)
@@ -71,17 +71,29 @@
$args->{rows} = $req_params->{list_count} || $self->list_count;
$args->{select} = $req_params->{list_returns} || ((scalar(@{$self->list_returns})) ? $self->list_returns : undef);
$args->{join} = $join;
+
+ # handle pagination
+ my $rows = $c->req->params->{rows};
+ my $page = defined $c->req->params->{page}
+ && $c->req->params->{start} =~ /^\d+$/xms
+ ? int($c->req->params->{start} / $rows) +1
+ : 1;
+ if (defined $rows && $rows =~ /^\d+$/xms && defined $page && $page =~ /^\d+$/xms) {
+ $c->stash->{rows_per_page} = $rows;
+ $args->{page} = $page;
+ $args->{rows} = $rows;
+ }
return [$params, $args];
}
sub _format_search {
- my ($self, $p) = @_;
- my $params = $p->{params};
- my $source = $p->{source};
- my $base = $p->{base} || 'me';
+ my ($self, $p) = @_;
+ my $params = $p->{params};
+ my $source = $p->{source};
+ my $base = $p->{base} || 'me';
- my $join = {};
+ my $join = {};
my %relname_map = map { $_ => 1 } $source->relationships;
my %search_params;
Modified: Catalyst-Controller-DBIC-API/1.001/branches/pagination/lib/Catalyst/Controller/DBIC/API.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/branches/pagination/lib/Catalyst/Controller/DBIC/API.pm 2009-02-13 16:39:35 UTC (rev 9297)
+++ Catalyst-Controller-DBIC-API/1.001/branches/pagination/lib/Catalyst/Controller/DBIC/API.pm 2009-02-13 16:51:25 UTC (rev 9298)
@@ -178,6 +178,14 @@
$rs->search({ name => 'fred', 'cd.artist' => 'luke' }, { join => ['cd'] })
+If pagination is needed it's possible to pass the 'rows' and 'page' request parameters:
+
+ ?page=2&rows=20
+
+Would result in this search:
+
+ $rs->search({}, { page => 2, rows => 20 })
+
The L</format_list> method is used to format the results, so override that as required.
=head2 format_list
More information about the Catalyst-commits
mailing list