$env->{'gruntmaster.problem'} = $1 if s,^/pb/$word/,/,;
$env->{'gruntmaster.contest'} = $1 if s,^/ct/$word/,/,;
$env->{'gruntmaster.user'} = $1 if s,^/us/$word/,/,;
+ $env->{'gruntmaster.page'} //= -1 if m,^/log/$,;
}
$app->($env);
}
$rs = $rs->search(undef, {order_by => 'me.id'}) unless $rs->is_ordered;
if (my $page = $env->{'gruntmaster.page'}) {
my $pages = $rs->count / PAGE_SIZE;
+ $page = $pages if $page == -1;
$rs = $rs->search(undef, {offset => ($page - 1) * PAGE_SIZE, ($page == $pages ? () : (rows => PAGE_SIZE))});
}
$rs = $rs->search(undef, {prefetch => $thing{prefetch}}) if exists $thing{prefetch};
};
sub generate{
- my ($self, $format, $env, $ct, $job, $ext) = @_;
- debug $env => "Contest is $ct, job is $job and extension is $ext";
+ my ($self, $format, $env, $job, $ext) = @_;
+ debug $env => "Job is $job and extension is $ext";
[200, ['Content-Type' => CONTENT_TYPES->{$ext}, 'Cache-Control' => 'max-age=604800', 'X-Forever' => 1], [db($env)->job($job)->source] ]
}
}
sub _generate{
- my ($self, $htc, $lang, $env, $ct) = @_;
- debug $env => "language is '$lang' and contest is '$ct'";
+ my ($self, $htc, $lang, $env) = @_;
+ #debug $env => "language is '$lang'";
- $ct &&= db($env)->contest($ct);
+ my $ct = $env->{'gruntmaster.contest'} && db($env)->contest($env->{'gruntmaster.contest'});
- my @problems = map { $_->problem } db($env)->contest_problems->search({contest => $ct->id}, {qw/join problem order_by problem.level/});
+ my @problems = map { $_->problem } db($env)->contest_problems->search({contest => $ct && $ct->id}, {qw/join problem order_by problem.level/});
my (%scores, %tries);
- for my $job (db($env)->jobs->search({contest => $ct->id})) {
+ for my $job (db($env)->jobs->search({contest => $ct && $ct->id})) {
if ($ct) {
my $time = $job->date - $ct->start;
}
}
- my @st = sort { $b->{score} <=> $a->{score} or $a->{user} cmp $b->{user}} map {
+ my @st = sort { $b->{score} <=> $a->{score} or $a->{user}->id cmp $b->{user}->id} map {
my $user = $_;
+{
user => db($env)->user($user),
get qr,/css/$word\.css, => 'CSS';
get qr,/js\.js, => 'JS';
+ get qr,/log/st, => 'St';
generic qw/us ct pb log/;
- get qr,/log/st, => 'St';
get qr,/log/src/$number\.$word, => 'Src';
post qr,/pb/$word/submit, => 'Submit';