]> iEval git - gruntmaster-page.git/blob - lib/Gruntmaster/Page/Log.pm
c92bf4d82ab962cfbab64f9df3a31b1ddd6db562
[gruntmaster-page.git] / lib / Gruntmaster / Page / Log.pm
1 package Gruntmaster::Page::Log;
2
3 use 5.014000;
4 use strict;
5 use warnings;
6 use parent qw/Exporter/;
7 our @EXPORT_OK = qw/generate/;
8 our $VERSION = '0.001';
9
10 use constant TITLE => 'Job log';
11
12 use Fcntl qw/:flock/;
13 use HTML::Template::Compiled;
14 use IO::File;
15 use POSIX qw/strftime/;
16 use YAML::Any qw/LoadFile/;
17 use Gruntmaster::Page::Common qw/header footer/;
18
19 my %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>
32 HTML
33 );
34
35 $templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
36 $templates{$_} .= footer $_ for keys %templates;
37
38 sub generate{
39 my ($path, $lang) = @_;
40 $path =~ s,/index\.html$,,;
41 my $template = $templates{$lang};
42 my $htc = HTML::Template::Compiled->new(scalarref => \$template);
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";
46 my @log = sort { $b->{id} <=> $a->{id} } map {
47 my $meta = LoadFile "$path/$_/meta.yml";
48 +{ id => $_,
49 date => (exists $meta->{date} ? strftime ('%c' => localtime $meta->{date}) : '?'),
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}) : ()),
56 size => sprintf ("%.2f KiB", (-s "$path/$_/in/" . $meta->{files}{prog}{name}) / 1024),
57 result_text => $meta->{result_text}} } 1 .. $meta->{last};
58 $htc->param(log => \@log);
59 $htc->output
60 }
61
62 1
This page took 0.049543 seconds and 4 git commands to generate.