X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FLog.pm;h=a86b1532feef74dd1764a26ffc621948f8efd380;hb=cd9af27e94244e6454c3db787a8ca6811f44fc16;hp=c92bf4d82ab962cfbab64f9df3a31b1ddd6db562;hpb=6d28cb383168de84cebad84aa43900844341bf5d;p=plack-app-gruntmaster.git diff --git a/lib/Gruntmaster/Page/Log.pm b/lib/Gruntmaster/Page/Log.pm index c92bf4d..a86b153 100644 --- a/lib/Gruntmaster/Page/Log.pm +++ b/lib/Gruntmaster/Page/Log.pm @@ -8,16 +8,15 @@ our @EXPORT_OK = qw/generate/; our $VERSION = '0.001'; use constant TITLE => 'Job log'; +use constant PAGE_SIZE => 10; -use Fcntl qw/:flock/; use HTML::Template::Compiled; -use IO::File; use POSIX qw/strftime/; -use YAML::Any qw/LoadFile/; use Gruntmaster::Page::Common qw/header footer/; +use Gruntmaster::Data qw/job_date job_file job_name job_private job_problem job_result job_result_text job_user/; my %templates = ( - en => <<'HTML', + en => <<'HTML',
IDProblemDateSizeUserResult @@ -25,7 +24,7 @@ my %templates = (
- data-private> +
@@ -36,27 +35,23 @@ $templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates; $templates{$_} .= footer $_ for keys %templates; sub generate{ - my ($path, $lang) = @_; - $path =~ s,/index\.html$,,; - my $template = $templates{$lang}; - my $htc = HTML::Template::Compiled->new(scalarref => \$template); - IO::File->new(">$path/meta.yml")->close unless -f "$path/meta.yml"; - flock my $metafh = IO::File->new("<$path/meta.yml"), LOCK_SH; - my $meta = LoadFile "$path/meta.yml"; - my @log = sort { $b->{id} <=> $a->{id} } map { - my $meta = LoadFile "$path/$_/meta.yml"; - +{ id => $_, - date => (exists $meta->{date} ? strftime ('%c' => localtime $meta->{date}) : '?'), - user => $meta->{user}, - result => $meta->{result}, - name => $meta->{name}, - problem => $meta->{problem}, - filename => $meta->{files}{prog}{name}, - (defined $meta->{private} ? (private => $meta->{private}) : ()), - size => sprintf ("%.2f KiB", (-s "$path/$_/in/" . $meta->{files}{prog}{name}) / 1024), - result_text => $meta->{result_text}} } 1 .. $meta->{last}; - $htc->param(log => \@log); - $htc->output + $_[0] =~ m,^(?:ct/([^/]+)/)?log/(\w+)\.html$,; + local $Gruntmaster::Data::contest = $1; + my $page = $2 eq 'index' ? 0 : $2; + + my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]}); + my @log = sort { $b->{id} <=> $a->{id} } map +{ + id => $_, + (job_private() ? (private => job_private) : ()), + date => (job_date() ? strftime ('%c' => localtime job_date) : '?'), + name => job_name, + problem => job_problem, + result => job_result, + result_text => job_result_text, + size => sprintf ("%.2f KiB", (length job_file) / 1024), + user => job_user}, ($page - 1) * PAGE_SIZE + 1 .. $page * PAGE_SIZE; + $htc->param(log => \@log); + $htc->output } 1