X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FLog.pm;h=5a2b4c6a91d36cb13a846479f91f6baedb79ff05;hb=3da9c3c228106c819530a0b8e4c646981e6f71c9;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..5a2b4c6 100644 --- a/lib/Gruntmaster/Page/Log.pm +++ b/lib/Gruntmaster/Page/Log.pm @@ -8,24 +8,27 @@ our @EXPORT_OK = qw/generate/; our $VERSION = '0.001'; use constant TITLE => 'Job log'; +use constant PAGE_SIZE => 10; + +use constant FORMAT_EXTENSION => { + CPP => 'cpp', +}; -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 problem_name job_private job_problem job_result job_result_text job_user/; my %templates = ( - en => <<'HTML', + en => <<'HTML',
IDProblemDateSizeUserResult
- + - data-private> + data-private>
@@ -36,27 +39,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 => problem_name job_problem, + 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