From 3473324bb17b1f31ce24bd465ded432c1c9f2f5b Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sat, 27 Sep 2014 00:31:19 +0300 Subject: [PATCH] Add page information to job_list --- lib/Gruntmaster/Data.pm | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) 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 { -- 2.39.2