}
sub list {
- my ($thing, $lang, $env, $ct) = @_;
+ my ($thing, $lang, $env) = @_;
my %thing = %$thing;
- my $req = Plack::Request->new($env);
- debug $env => "Contest is $ct";
- $thing{makers} //= sub { shift->resultset($thing{rsname}) };
- my $rs = $thing{makers}->(db $env)->search(undef, {order_by => 'me.id'});
- if (my $page = $req->param('page')) {
+ #debug $env => "Contest is $ct";
+ $thing{makers} //= sub { db(shift)->resultset($thing{rsname}) };
+ my $rs = $thing{makers}->($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;
$rs = $rs->search(undef, {offset => ($page - 1) * PAGE_SIZE, ($page == $pages ? () : (rows => PAGE_SIZE))});
}
}
sub entry {
- my ($thing, $lang, $env, $id, $ct) = @_;
+ my ($thing, $lang, $env, $id) = @_;
my %thing = %$thing;
- ($id, $ct) = ($ct, $id) if $ct;
debug $env => "Rsname is $thing{rsname} and id is $id";
- $thing{makers} //= sub { shift->resultset($thing{rsname}) };
- my %params = map {+ rs => $_, $_->get_columns } $thing{makers}->(db $env)->find($id);
- $params{contest} = $ct if $ct;
+ $thing{makers} //= sub { db(shift)->resultset($thing{rsname}) };
+ my %params = map {+ rs => $_, $_->get_columns } $thing{makers}->($env)->find($id);
$thing{mangle}->(local $_ = \%params) if exists $thing{mangle};
wantarray ? %params : \%params
}
thing {
params qw/pb Problem Problems/;
prefetch 'owner';
- makers { my ($db, $ct) = @_; $ct ? $db->contest($ct)->problems : $db->problems->search({private => 0}) };
+ makers {
+ my $env = $_[0];
+ my $db = db $env;
+ return $db->contest($env->{'gruntmaster.contest'})->problems->search(undef, {order_by => 'problem.id'}) if exists $env->{'gruntmaster.contest'};
+ return $db->problems->search({owner => $env->{'gruntmaster.user'}}) if exists $env->{'gruntmaster.user'};
+ $db->problems->search({private => 0});
+ };
sortby { $a->{name} cmp $b->{name}};
group { $_->{level} };
mangle {
thing {
params qw/log Job/, 'Job log';
prefetch 'owner', 'problem';
- makers { shift->jobs->search({contest => shift}) };
+ makers {
+ my $env = $_[0];
+ my $db = db $env;
+ return $db->jobs->search({'me.owner' => $env->{'gruntmaster.user'}}) if exists $env->{'gruntmaster.user'};
+ return $db->jobs->search({problem => $env->{'gruntmaster.problem'}}) if exists $env->{'gruntmaster.problem'};
+ $db->jobs->search({contest => $env->{'gruntmaster.contest'}})
+ };
sortby { $b->{id} <=> $a->{id}};
mangle {
$_->{results} &&= decode_json $_->{results};