]> iEval git - gruntmaster-page.git/blame - lib/Gruntmaster/Page/Log.pm
Move header / footer to a separate module and update MANIFEST
[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';
11
12use Fcntl qw/:flock/;
13use HTML::Template::Compiled;
14use IO::File;
15use POSIX qw/strftime/;
16use YAML::Any qw/LoadFile/;
832cb45e 17use Gruntmaster::Page::Common qw/header footer/;
42546e6c
MG
18
19my %templates = (
20 en => <<'HTML',
21<table border>
22<thead>
23<tr><th>ID<th>Problem<th>Date<th>Size<th>User<th>Result
24<tbody>
25<tmpl_loop log><tr><td><a href="<tmpl_var id>"><tmpl_var id></a>
26<td><a href="/pb/<tmpl_var problem>"><tmpl_var name></a>
27<td><tmpl_var date>
28<td><a href="<tmpl_var id>/in/<tmpl_var filename>"<tmpl_if private> data-private</tmpl_if>><tmpl_var size></a>
29<td><tmpl_var user><td class="r<tmpl_var result>"><tmpl_var result_text>
30</tmpl_loop>
31</table>
32HTML
33);
34
35$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
36$templates{$_} .= footer $_ for keys %templates;
37
38sub generate{
fe78f0c1
MG
39 my ($path, $lang) = @_;
40 $path =~ s,/index\.html$,,;
41 my $template = $templates{$lang};
42546e6c 42 my $htc = HTML::Template::Compiled->new(scalarref => \$template);
fe78f0c1
MG
43 IO::File->new(">$path/meta.yml")->close unless -f "$path/meta.yml";
44 flock my $metafh = IO::File->new("<$path/meta.yml"), LOCK_SH;
45 my $meta = LoadFile "$path/meta.yml";
42546e6c 46 my @log = sort { $b->{id} <=> $a->{id} } map {
fe78f0c1 47 my $meta = LoadFile "$path/$_/meta.yml";
42546e6c 48 +{ id => $_,
c259ad15 49 date => (exists $meta->{date} ? strftime ('%c' => localtime $meta->{date}) : '?'),
42546e6c
MG
50 user => $meta->{user},
51 result => $meta->{result},
52 name => $meta->{name},
53 problem => $meta->{problem},
54 filename => $meta->{files}{prog}{name},
55 (defined $meta->{private} ? (private => $meta->{private}) : ()),
fe78f0c1 56 size => sprintf ("%.2f KiB", (-s "$path/$_/in/" . $meta->{files}{prog}{name}) / 1024),
42546e6c
MG
57 result_text => $meta->{result_text}} } 1 .. $meta->{last};
58 $htc->param(log => \@log);
59 $htc->output
60}
61
621
This page took 0.028941 seconds and 4 git commands to generate.