X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FGeneric.pm;h=eefa9080e3f41d52ecca6a89a247895bcc4d304c;hb=251f53e4ff1871fdaee0202f994bf3d6b28b8ec9;hp=35d89adab97874619da159b1a8a24ea5023a6b43;hpb=2e2be9fd67d19611a43a37f39d4bb720f4357cf3;p=plack-app-gruntmaster.git diff --git a/lib/Gruntmaster/Page/Generic.pm b/lib/Gruntmaster/Page/Generic.pm index 35d89ad..eefa908 100644 --- a/lib/Gruntmaster/Page/Generic.pm +++ b/lib/Gruntmaster/Page/Generic.pm @@ -38,6 +38,7 @@ sub list { $rs = $rs->search(undef, {order_by => 'me.id'}) unless $rs->is_ordered; if (my $page = $env->{'gruntmaster.page'}) { my $pages = int ($rs->count / PAGE_SIZE); + $pages = 1 if $pages < 1; $page = $pages if $page == -1; @params{'page', 'pages'} = ($page, $pages); $rs = $rs->search(undef, {offset => ($page - 1) * PAGE_SIZE, ($page == $pages ? () : (rows => PAGE_SIZE))}); @@ -123,7 +124,7 @@ thing { my $db = db $env; return $db->problems->search({owner => $env->{'gruntmaster.user'}}) if exists $env->{'gruntmaster.user'}; return $db->problems->search({'contest_problems.contest' => $env->{'gruntmaster.contest'}}, {join => 'contest_problems'}) if exists $env->{'gruntmaster.contest'}; - $db->problems->search({-or => ['contest_problems.contest' => undef, 'contest.stop' => {'<=', time}], 'me.private' => 0}, {join => {'contest_problems' => 'contest'}}); + $db->problems->search({-or => ['contest_problems.contest' => undef, 'contest.stop' => {'<=', time}], 'me.private' => 0}, {join => {'contest_problems' => 'contest'}, distinct => 1}); }; sortby { $a->{name} cmp $b->{name}}; group { $_->{level} }; @@ -161,11 +162,13 @@ thing { }; sortby { $b->{id} <=> $a->{id}}; mangle { + my $env = shift; $_->{results} &&= decode_json $_->{results}; $_->{owner_name} = $_->{rs}->owner->name; $_->{problem_name} = $_->{rs}->problem->name; $_->{size} = length $_->{source}; delete $_->{source}; + $_->{pageprefix} = $env->{'gruntmaster.page'} == -1 ? 'page/' : ''; } };