From 9a4806b3c49eef940ac5d2d2b38f9d47b346d544 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Mon, 1 Dec 2014 15:23:35 +0200 Subject: [PATCH] Add non-interactive score and countdown on pb_entry --- lib/Plack/App/Gruntmaster.pm | 1 + lib/Plack/App/Gruntmaster/HTML.pm | 12 ++++++++++++ tmpl/pb_entry.en | 2 ++ 3 files changed, 15 insertions(+) diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index 3e37ef1..4dd497f 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -76,6 +76,7 @@ sub response { $params = $title; $title = 'No title'; } + $params->{time} = time; bless {template => $template, title => $title, params => $params}, __PACKAGE__.'::Response' } diff --git a/lib/Plack/App/Gruntmaster/HTML.pm b/lib/Plack/App/Gruntmaster/HTML.pm index 16ae617..0412782 100644 --- a/lib/Plack/App/Gruntmaster/HTML.pm +++ b/lib/Plack/App/Gruntmaster/HTML.pm @@ -122,6 +122,18 @@ sub process_pb_entry { statement => literal $args{statement}, author => $args{author}, owner => $args{owner_name} || $args{owner}); + if ($args{contest_stop}) { + my $countdown = $tree->fid('countdown'); + $countdown->attr('data-start' => $args{contest_start}); + $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::calc_score($args{value}, $args{time} - $args{contest_start}, 0, $args{contest_stop} - $args{contest_start})); + } else { + $_->detach for $tree->fclass('rc'); # requires contest + } if ($args{cansubmit}) { $tree->look_down(name => 'problem')->attr(value => $args{id}); my $contest = $tree->look_down(name => 'contest'); diff --git a/tmpl/pb_entry.en b/tmpl/pb_entry.en index 8189d0b..4e0d324 100644 --- a/tmpl/pb_entry.en +++ b/tmpl/pb_entry.en @@ -7,6 +7,8 @@
Author
author
Owner
owner
+
Score
50
+
Contest ends in
01:30
Job log -- 2.39.2