]> iEval git - gruntmaster-data.git/commitdiff
Add page information to job_list
authorMarius Gavrilescu <marius@ieval.ro>
Fri, 26 Sep 2014 21:31:19 +0000 (00:31 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Fri, 26 Sep 2014 21:31:19 +0000 (00:31 +0300)
lib/Gruntmaster/Data.pm

index 608ca50d9350b5fc0b8860c168f81e6f8d8cc98f..e8ce571cba8c3b378300f18e965c36afb34e9e88 100644 (file)
@@ -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 {
This page took 0.019045 seconds and 4 git commands to generate.