From: Marius Gavrilescu Date: Fri, 26 Sep 2014 21:31:19 +0000 (+0300) Subject: Add page information to job_list X-Git-Tag: 5999.000_009~2 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=3473324bb17b1f31ce24bd465ded432c1c9f2f5b;p=gruntmaster-data.git Add page information to job_list --- diff --git a/lib/Gruntmaster/Data.pm b/lib/Gruntmaster/Data.pm index 608ca50..e8ce571 100644 --- a/lib/Gruntmaster/Data.pm +++ b/lib/Gruntmaster/Data.pm @@ -20,6 +20,7 @@ our $VERSION = '5999.000_008'; use Lingua::EN::Inflect qw/PL_N/; use JSON qw/decode_json/; use List::Util qw/sum/; +use PerlX::Maybe qw/maybe/; use Sub::Name qw/subname/; use constant PROBLEM_PUBLIC_COLUMNS => [qw/id author writer level name owner private statement timeout olimit value/]; @@ -157,19 +158,25 @@ sub contest_entry { sub job_list { my ($self, %args) = @_; $args{page} //= 1; - my $rs = $self->jobs->search(undef, {order_by => {-desc => 'me.id'}, prefetch => ['problem', 'owner'], rows => JOBS_PER_PAGE, offset => ($args{page} - 1) * JOBS_PER_PAGE}); + my $rs = $self->jobs->search(undef, {order_by => {-desc => 'me.id'}, prefetch => ['problem', 'owner'], rows => JOBS_PER_PAGE, page => $args{page}}); $rs = $rs->search({'me.owner' => $args{owner}}) if $args{owner}; $rs = $rs->search({contest => $args{contest}}) if $args{contest}; $rs = $rs->search({problem => $args{problem}}) if $args{problem}; - [map { - my %params = $_->get_columns; - $params{owner_name} = $_->owner->name; - $params{problem_name} = $_->problem->name; - $params{results} &&= decode_json $params{results}; - $params{size} = length $params{source}; - delete $params{source}; - \%params - } $rs->all] + return { + log => [map { + my %params = $_->get_columns; + $params{owner_name} = $_->owner->name; + $params{problem_name} = $_->problem->name; + $params{results} &&= decode_json $params{results}; + $params{size} = length $params{source}; + delete $params{source}; + \%params + } $rs->all], + current_page => $rs->pager->current_page, + maybe previous_page => $rs->pager->previous_page, + maybe next_page => $rs->pager->next_page, + maybe last_page => $rs->pager->last_page, + } } sub job_entry {