]> iEval git - gruntmaster-page.git/blame - lib/Gruntmaster/Page/Log.pm
Use Redis and reindent code
[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
42546e6c 13use HTML::Template::Compiled;
42546e6c 14use POSIX qw/strftime/;
832cb45e 15use Gruntmaster::Page::Common qw/header footer/;
cd9af27e 16use Gruntmaster::Data qw/job_date job_file job_name job_private job_problem job_result job_result_text job_user/;
42546e6c
MG
17
18my %templates = (
cd9af27e 19 en => <<'HTML',
42546e6c
MG
20<table border>
21<thead>
22<tr><th>ID<th>Problem<th>Date<th>Size<th>User<th>Result
23<tbody>
24<tmpl_loop log><tr><td><a href="<tmpl_var id>"><tmpl_var id></a>
25<td><a href="/pb/<tmpl_var problem>"><tmpl_var name></a>
26<td><tmpl_var date>
cd9af27e 27<td><tmpl_var size></a>
42546e6c
MG
28<td><tmpl_var user><td class="r<tmpl_var result>"><tmpl_var result_text>
29</tmpl_loop>
30</table>
31HTML
32);
33
34$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
35$templates{$_} .= footer $_ for keys %templates;
36
37sub generate{
cd9af27e
MG
38 $_[0] =~ m,^(?:ct/([^/]+)/)?log/(\w+)\.html$,;
39 local $Gruntmaster::Data::contest = $1;
40 my $page = $2 eq 'index' ? 0 : $2;
41
42 my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
43 my @log = sort { $b->{id} <=> $a->{id} } map +{
44 id => $_,
45 (job_private() ? (private => job_private) : ()),
46 date => (job_date() ? strftime ('%c' => localtime job_date) : '?'),
47 name => job_name,
48 problem => job_problem,
49 result => job_result,
50 result_text => job_result_text,
51 size => sprintf ("%.2f KiB", (length job_file) / 1024),
52 user => job_user}, ($page - 1) * PAGE_SIZE + 1 .. $page * PAGE_SIZE;
53 $htc->param(log => \@log);
54 $htc->output
42546e6c
MG
55}
56
571
This page took 0.02803 seconds and 4 git commands to generate.