From: Marius Gavrilescu Date: Thu, 13 Aug 2015 10:11:10 +0000 (+0300) Subject: Update for new Gruntmaster::Data X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=25ed3a342819b81afaf9d04c8c6f8db372a22392;p=plack-app-gruntmaster.git Update for new Gruntmaster::Data --- diff --git a/app.psgi b/app.psgi index 3a6be21..80ed1a2 100644 --- 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->(@_) } diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index 77b3748..2c07bd5 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -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) { diff --git a/lib/Plack/App/Gruntmaster/HTML.pm b/lib/Plack/App/Gruntmaster/HTML.pm index b67ef29..5c108d1 100644 --- a/lib/Plack/App/Gruntmaster/HTML.pm +++ b/lib/Plack/App/Gruntmaster/HTML.pm @@ -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); }