X-Git-Url: http://git.ieval.ro/?p=gruntmaster-page.git;a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FGeneric.pm;h=256add635bed2a31ed85d929cab7e710722ea57f;hp=2cb82d91d86720a5e79e3ff3573a72e83f34e9d0;hb=491e82eb192b76e7e8eece5aaf43b7aebb81a12d;hpb=d3200993969efcd4d9c0ce6a5666a012815ad2d5 diff --git a/lib/Gruntmaster/Page/Generic.pm b/lib/Gruntmaster/Page/Generic.pm index 2cb82d9..256add6 100644 --- a/lib/Gruntmaster/Page/Generic.pm +++ b/lib/Gruntmaster/Page/Generic.pm @@ -29,13 +29,13 @@ sub makepkg { } 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))}); } @@ -55,13 +55,11 @@ sub list { } 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 } @@ -114,7 +112,13 @@ thing { 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 { @@ -142,7 +146,13 @@ thing { 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};