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/];
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 {