]>
Commit | Line | Data |
---|---|---|
42546e6c MG |
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 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{ | |
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 | ||
62 | 1 |