X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;ds=sidebyside;f=lib%2FGruntmaster%2FPage%2FLog.pm;h=2379e804815c816f81cae63081b441bee514569a;hb=b83e43dc480771137fcff41589815556881b1243;hp=c92bf4d82ab962cfbab64f9df3a31b1ddd6db562;hpb=832cb45e325364ca1de645a2256efa69284fcf06;p=plack-app-gruntmaster.git
diff --git a/lib/Gruntmaster/Page/Log.pm b/lib/Gruntmaster/Page/Log.pm
index c92bf4d..2379e80 100644
--- a/lib/Gruntmaster/Page/Log.pm
+++ b/lib/Gruntmaster/Page/Log.pm
@@ -3,60 +3,53 @@ package Gruntmaster::Page::Log;
use 5.014000;
use strict;
use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base log => 'Job log';
+our @ISA = qw/Gruntmaster::Page::Base/;
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/;
-
-my %templates = (
- en => <<'HTML',
+use constant TEMPLATES => {
+ en => <<'HTML',
+
+Prev page
+Next page
HTML
-);
-
-$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
+};
+
+sub _generate{
+ my ($self, $htc, $path, $lang) = @_;
+
+ $path =~ m,^(?:ct/([^/]+)/)?log/(\w+)\.html$,;
+ local $Gruntmaster::Data::contest = $1 if $1;
+ my $pages = POSIX::floor (jobcard / PAGE_SIZE);
+ my $page = $2 eq 'index' ? $pages : $2;
+
+ my @log = sort { $b->{id} <=> $a->{id} } map +{
+ id => $_,
+ (job_private() ? (private => job_private) : ()),
+ date => (job_date() ? strftime ('%c' => localtime job_date) : '?'),
+ extension => job_extension,
+ name => problem_name job_problem,
+ problem => job_problem,
+ result => job_result,
+ result_text => job_result_text,
+ size => sprintf ("%.2f KiB", job_filesize() / 1024),
+ user => job_user}, ($page - 1) * PAGE_SIZE + 1 .. ($page == $pages ? jobcard : $page * PAGE_SIZE);
+ $htc->param(log => \@log);
+ $htc->param(next => $page + 1) unless $page == $pages;
+ $htc->param(prev => $page - 1) unless $page == 1;
}
1