]> iEval git - gruntmaster-page.git/blame - lib/Gruntmaster/Page/Log.pm
More bug fixes
[gruntmaster-page.git] / lib / Gruntmaster / Page / Log.pm
CommitLineData
42546e6c
MG
1package Gruntmaster::Page::Log;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/Exporter/;
7our @EXPORT_OK = qw/generate/;
8our $VERSION = '0.001';
9
10use constant TITLE => 'Job log';
cd9af27e 11use constant PAGE_SIZE => 10;
42546e6c 12
3da9c3c2
MG
13use constant FORMAT_EXTENSION => {
14 CPP => 'cpp',
15};
16
42546e6c 17use HTML::Template::Compiled;
42546e6c 18use POSIX qw/strftime/;
832cb45e 19use Gruntmaster::Page::Common qw/header footer/;
e5f2bda6 20use Gruntmaster::Data qw/jobcard job_date job_extension job_filesize problem_name job_private job_problem job_result job_result_text job_user/;
42546e6c
MG
21
22my %templates = (
cd9af27e 23 en => <<'HTML',
42546e6c
MG
24<table border>
25<thead>
26<tr><th>ID<th>Problem<th>Date<th>Size<th>User<th>Result
27<tbody>
e5f2bda6 28<tmpl_loop log><tr><td><a href="job/<tmpl_var id>.var"><tmpl_var id></a>
3da9c3c2 29<td><a href="../pb/<tmpl_var problem>"><tmpl_var name></a>
42546e6c 30<td><tmpl_var date>
e5f2bda6 31<td><a href="src/<tmpl_var id>.<tmpl_var extension>"<tmpl_if private> data-private</tmpl_if>><tmpl_var size></a></a>
42546e6c
MG
32<td><tmpl_var user><td class="r<tmpl_var result>"><tmpl_var result_text>
33</tmpl_loop>
34</table>
35HTML
36);
37
38$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
39$templates{$_} .= footer $_ for keys %templates;
40
41sub generate{
cd9af27e
MG
42 $_[0] =~ m,^(?:ct/([^/]+)/)?log/(\w+)\.html$,;
43 local $Gruntmaster::Data::contest = $1;
e5f2bda6
MG
44 my $pages = jobcard / PAGE_SIZE;
45 my $page = $2 eq 'index' ? $pages : $2;
cd9af27e
MG
46
47 my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
48 my @log = sort { $b->{id} <=> $a->{id} } map +{
49 id => $_,
50 (job_private() ? (private => job_private) : ()),
51 date => (job_date() ? strftime ('%c' => localtime job_date) : '?'),
e5f2bda6 52 extension => job_extension,
3da9c3c2 53 name => problem_name job_problem,
cd9af27e
MG
54 problem => job_problem,
55 result => job_result,
56 result_text => job_result_text,
e5f2bda6
MG
57 size => sprintf ("%.2f KiB", job_filesize() / 1024),
58 user => job_user}, ($page - 1) * PAGE_SIZE + 1 .. $page == $pages ? jobcard : $page * PAGE_SIZE;
cd9af27e
MG
59 $htc->param(log => \@log);
60 $htc->output
42546e6c
MG
61}
62
631
This page took 0.026842 seconds and 4 git commands to generate.