X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FGeneric.pm;h=15b887ea03c64d778fbf38738c3c5857d75603cf;hb=a122bb9b5954e4384b8f1c3f52bcdda74b421f25;hp=35d89adab97874619da159b1a8a24ea5023a6b43;hpb=2e2be9fd67d19611a43a37f39d4bb720f4357cf3;p=gruntmaster-page.git diff --git a/lib/Gruntmaster/Page/Generic.pm b/lib/Gruntmaster/Page/Generic.pm index 35d89ad..15b887e 100644 --- a/lib/Gruntmaster/Page/Generic.pm +++ b/lib/Gruntmaster/Page/Generic.pm @@ -38,6 +38,8 @@ 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); + $params{default_page} = $page == -1; + $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))}); @@ -47,7 +49,7 @@ sub list { exists $thing{columns} ? (columns => $thing{columns}) : (), }); my @thing = map +{rs => $_, $_->get_columns}, $rs->all; - @thing = map { $thing{mangle}->(); $_ } @thing if exists $thing{mangle}; + @thing = map { $thing{mangle}->($env); $_ } @thing if exists $thing{mangle}; @thing = grep { $thing{choose}->() } @thing if exists $thing{choose}; @thing = sort { $thing{sortby}->() } @thing if exists $thing{sortby}; $thing{group} //= sub { $thing{id} }; @@ -64,7 +66,8 @@ sub entry { my %thing = %$thing; debug $env => "Rsname is $thing{rsname} and id is $id"; my %params = map {+ rs => $_, $_->get_columns } db($env)->resultset($thing{rsname})->find($id); - $thing{mangle}->(local $_ = \%params) if exists $thing{mangle}; + local $_ = \%params; + $thing{mangle}->($env) if exists $thing{mangle}; wantarray ? %params : \%params } @@ -123,7 +126,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} }; @@ -132,10 +135,11 @@ thing { $_->{owner_name} = $_->{rs}->owner->name; $_->{cansubmit} = $env->{'gruntmaster.contest'} ? time < db($env)->contest($env->{'gruntmaster.contest'})->stop : 1; eval { - db($env)->open->create({ + db($env)->opens->create({ contest => $env->{'gruntmaster.contest'}, problem => $_->{id}, owner => $env->{REMOTE_USER}, + time => time, }) } if $env->{'gruntmaster.contest'} && time >= db($env)->contest($env->{'gruntmaster.contest'})->start; }; @@ -161,6 +165,7 @@ thing { }; sortby { $b->{id} <=> $a->{id}}; mangle { + my $env = shift; $_->{results} &&= decode_json $_->{results}; $_->{owner_name} = $_->{rs}->owner->name; $_->{problem_name} = $_->{rs}->problem->name; @@ -171,5 +176,6 @@ thing { putsym 'Gruntmaster::Page::Pb::Entry::vary', sub { 'Authorization' }; putsym 'Gruntmaster::Page::Pb::Entry::max_age', sub { 600 }; +putsym 'Gruntmaster::Page::Log::max_age', sub { 10 }; 1