]> iEval git - plack-app-gruntmaster.git/commitdiff
Update for new Gruntmaster::Data
authorMarius Gavrilescu <marius@ieval.ro>
Thu, 13 Aug 2015 10:11:10 +0000 (13:11 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Thu, 13 Aug 2015 11:15:08 +0000 (14:15 +0300)
app.psgi
lib/Plack/App/Gruntmaster.pm
lib/Plack/App/Gruntmaster/HTML.pm

index 3a6be219ec8fe3f4a5a53a714247e9a8dbdcfa22..80ed1a2268195992ddfb5cc40d35226d8944b356 100644 (file)
--- a/app.psgi
+++ b/app.psgi
@@ -28,7 +28,7 @@ my $dbinit;
 sub add_database {
        my $app = $_[0];
        sub {
-               Gruntmaster::Data::init $ENV{GRUNTMASTER_DSN} // 'dbi:Pg:' unless $dbinit;
+               dbinit $ENV{GRUNTMASTER_DSN} // 'dbi:Pg:' unless $dbinit;
                $dbinit = 1;
                $app->(@_)
        }
index 77b374894e7a254fa4eb9271b260386c1eb40151..2c07bd569017005b29bc1fab078529229b74aef8 100644 (file)
@@ -80,7 +80,7 @@ sub dispatch_request{
                sub (/robots.txt) { NOT_FOUND },
 
                sub (/src/:job) {
-                       my $job = job_full $_{job};
+                       my $job = db->select(jobs => '*', {id => $_{job}})->hash;
                        return NOT_FOUND if !$job;
                        my $isowner = remote_user && remote_user->{id} eq $job->{owner};
                        my $contest = $job->{contest} && contest_entry $job->{contest};
@@ -105,13 +105,16 @@ sub dispatch_request{
                        },
                },
 
-               sub (/st/:contest) { response st => 'Standings', standings($_{contest}), 10 },
+               sub (/st/:contest) {
+                       my @pb = map { [$_->{id}, $_->{name}] } @{problem_list contest => $_{contest}};
+                       response st => 'Standings', {problems => \@pb, st => standings $_{contest}}, 10
+               },
 
                sub (/ed/:contest) {
-                       my $contest = contest_full $_{contest};
-                       forbid !$contest->{finished};
+                       my $contest = db->select(contests => '*', {id => $_{contest}})->hash;
+                       forbid time < $contest->{stop};
                        my $pblist = problem_list contest => $_{contest}, solution => 1;
-                       response ed => 'Editorial of ' . $contest->{name}, {%$pblist, editorial => $contest->{editorial}}
+                       response ed => 'Editorial of ' . $contest->{name}, {pb => $pblist, editorial => $contest->{editorial}}
                },
 
                sub (/login) {
@@ -122,16 +125,17 @@ sub dispatch_request{
                sub (/ct/:contest/log/st) { redirect "/st/$_{contest}" },
 
                sub (/us/)                                        { response us => 'Users', {us => user_list} },
-               sub (/ct/  + ?:owner~)                            { response ct => 'Contests', contest_list(%_), 300 },
+               sub (/ct/  + ?:owner~)                            { response ct => 'Contests', {ct => contest_list(%_)}, 300 },
                sub (/log/ + ?:contest~&:owner~&:page~&:problem~&:private~&:result~) {
                        forbid $_{private};
-                       response log => 'Job list', job_list(%_), 5
+                       my ($jobs, $pageinfo) = job_list(%_);
+                       response log => 'Job list', {log => $jobs, %$pageinfo}, 5
                },
                sub (/pb/  + ?:owner~&:contest~&:private~)                  {
                        forbid $_{private};
                        my $pending = $_{contest} && !contest_entry($_{contest})->{started};
                        forbid $pending;
-                       response pb => 'Problems', problem_list %_
+                       response pb => 'Problems', {pb => problem_list %_}
                },
 
                sub (/us/:user)    {
index b67ef296cf544a0164e7ecadb175a33485680d6c..5c108d1a7a035618c3cafd23828f581276a215c6 100644 (file)
@@ -14,7 +14,7 @@ my $optional_end_tags = {%HTML::Tagset::optionalEndTag, tr => 1, td => 1, th =>
 sub ftime ($)   { POSIX::strftime '%c', localtime shift }
 sub literal ($) {
        my ($html) = @_;
-       return unless $html;
+       return '' unless $html;
        my $b = HTML::TreeBuilder->new;
        $b->ignore_unknown(0);
        $b->parse($html);
@@ -161,6 +161,10 @@ sub process_ct {
                $tr->fclass('name')->namedlink($data->{id}, $data->{name});
                $tr->fclass('owner')->namedlink($data->{owner}, $data->{owner_name});
        };
+       for (@{$args{ct}}) {
+               my $state = $_->{finished} ? 'finished' : $_->{started} ? 'running' : 'pending';
+               push @{$args{$state} //= []}, $_;
+       }
        $args{$_} ? $tree->fid($_)->find('tbody')->find('tr')->iter3($args{$_}, $iter) : $tree->fid($_)->detach for qw/running pending finished/;
 }
 
@@ -221,6 +225,7 @@ sub process_pb {
                $div->find('h2')->replace_content(ucfirst $data);
                $div->find('tbody')->find('tr')->iter3($args{$data}, $titer);
        };
+       push @{$args{$_->{level}} //= []}, $_ for @{$args{pb}};
        $tree->fid('beginner')->iter3([grep {$args{$_}} qw/beginner easy medium hard/], $iter);
        $tree->fid('open-alert')->detach unless $args{contest};
 }
@@ -310,7 +315,7 @@ sub process_ed {
                $div->set_child_content(class => 'solution', literal $data->{solution});
                $div->fclass('problem')->namedlink($data->{id}, $data->{name});
        };
-       my @pb = map { @{$args{$_} // []} } qw/beginner easy medium hard/;
+       my @pb = sort { $a->{value} <=> $b->{value} } @{$args{pb}};
        $tree->fclass('well')->iter3(\@pb, $iter);
 }
 
This page took 0.033514 seconds and 4 git commands to generate.