X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FPlack%2FApp%2FGruntmaster%2FHTML.pm;h=eb3c56765964e4d1ec09fb70d14b7865c64b3738;hb=90f613d3964e01ed8cc18ca07a89ffff87f72f4c;hp=52afd1129128f719d235a7bf4017ac2115e31418;hpb=a33e01dd99675a6b875dc923a30329978a3b164e;p=plack-app-gruntmaster.git diff --git a/lib/Plack/App/Gruntmaster/HTML.pm b/lib/Plack/App/Gruntmaster/HTML.pm index 52afd11..eb3c567 100644 --- a/lib/Plack/App/Gruntmaster/HTML.pm +++ b/lib/Plack/App/Gruntmaster/HTML.pm @@ -32,7 +32,7 @@ sub HTML::Element::iter3 { } sub HTML::Element::fid { shift->look_down(id => shift) } -sub HTML::Element::fclass { shift->look_down(class => shift) } +sub HTML::Element::fclass { shift->look_down(class => qr/\b$_[0]\b/) } sub HTML::Element::namedlink { my ($self, $id, $name) = @_; @@ -115,10 +115,14 @@ sub process_ct_entry { my ($tree, %args) = @_; $_->edit_href (sub {s/contest_id/$args{id}/}) for $tree->find('a'); $tree->fid('links')->detach unless $args{started}; + my $status = ($args{time} < $args{start} ? 'starts' : 'ends'); + $tree->fclass('timer')->attr('data-stop', $status eq 'ends' ? $args{stop} : $args{start}); $tree->content_handler( start => ftime $args{start}, stop => ftime $args{stop}, + status => $status, description => literal $args{description}); + $tree->fid('ctcountdown')->detach if $args{time} >= $args{stop}; } sub process_ct { @@ -147,25 +151,24 @@ sub process_pb_entry { if ($args{contest_stop}) { $tree->fid('solution')->detach; $tree->fid('solution_modal')->detach; - my $countdown = $tree->fid('countdown'); - $countdown->attr('data-start' => $args{open_time}); - $countdown->attr('data-stop' => $args{contest_stop}); - $countdown->attr('data-time' => $args{time}); - my $left = $args{contest_stop} - $args{time}; - $countdown->replace_content(sprintf '%02d:%02d:%02d', $left/60/60, $left/60%60, $left%60); - $tree->fid('score')->attr('data-value' => $args{value}); - $tree->fid('score')->replace_content(Gruntmaster::Data::Result::Contest::calc_score($args{value}, $args{time} - $args{open_time}, 0, $args{contest_stop} - $args{contest_start})); + my $score = $tree->fid('score'); + $score->attr('data-start' => $args{open_time}); + $score->attr('data-stop' => $args{contest_stop}); + $score->attr('data-value' => $args{value}); + $tree->fid('countdown')->attr('data-stop' => $args{contest_stop}); } else { $tree->fid('solution')->detach unless $args{solution}; $_->detach for $tree->fclass('rc'); # requires contest $tree->fid('solution_modal')->fclass('modal-body')->replace_content(literal $args{solution}); } if ($args{cansubmit}) { + $tree->fid('nosubmit')->detach; $tree->look_down(name => 'problem')->attr(value => $args{id}); my $contest = $tree->look_down(name => 'contest'); $contest->attr(value => $args{contest}) if $args{contest}; $contest->detach unless $args{contest} } else { + $tree->fid('nosubmit')->find('a')->edit_href(sub{s/id/$args{id}/}); $tree->fid('submit')->detach } } @@ -192,6 +195,7 @@ sub process_pb { $div->find('tbody')->find('tr')->iter3($args{$data}, $titer); }; $tree->fid('beginner')->iter3([grep {$args{$_}} qw/beginner easy medium hard/], $iter); + $tree->fid('open-alert')->detach unless $args{contest}; } sub process_log_entry { @@ -246,7 +250,7 @@ sub process_log { next unless $elem; delete $args{args}{page}; my $str = join '&', map { $_ . '=' . $args{args}{$_} } keys %{$args{args}}; - $elem->find('a')->edit_href(sub{s/$/&$str/}); + $elem->find('a')->edit_href(sub{s/$/&$str/}) if $str; } $tree->fclass('current')->replace_content("Page $args{current_page} of $args{last_page}"); } @@ -280,6 +284,6 @@ 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 = map { @{$args{$_} // []} } qw/beginner easy medium hard/; $tree->fclass('well')->iter3(\@pb, $iter); }