X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FGeneric.pm;h=317fc6a6a2e35d3599d30e8ed5a2fbc844b299b8;hb=42c8356688bc0e47b2fe95debbbf51f632757eca;hp=9e07d4c8a68814aa11189b8a8f5a30e7d9390864;hpb=e63eaf407e505337cd02d7bc7ca3010ab6337348;p=plack-app-gruntmaster.git diff --git a/lib/Gruntmaster/Page/Generic.pm b/lib/Gruntmaster/Page/Generic.pm index 9e07d4c..317fc6a 100644 --- a/lib/Gruntmaster/Page/Generic.pm +++ b/lib/Gruntmaster/Page/Generic.pm @@ -38,6 +38,7 @@ sub list { $rs = $rs->search(undef, {order_by => 'me.id'}) unless $rs->is_ordered; if (my $page = $env->{'gruntmaster.page'}) { my $pages = int ($rs->count / PAGE_SIZE); + $pages = 1 if $pages < 1; $page = $pages if $page == -1; @params{'page', 'pages'} = ($page, $pages); $rs = $rs->search(undef, {offset => ($page - 1) * PAGE_SIZE, ($page == $pages ? () : (rows => PAGE_SIZE))}); @@ -47,7 +48,7 @@ sub list { exists $thing{columns} ? (columns => $thing{columns}) : (), }); my @thing = map +{rs => $_, $_->get_columns}, $rs->all; - @thing = map { $thing{mangle}->(); $_ } @thing if exists $thing{mangle}; + @thing = map { $thing{mangle}->($env); $_ } @thing if exists $thing{mangle}; @thing = grep { $thing{choose}->() } @thing if exists $thing{choose}; @thing = sort { $thing{sortby}->() } @thing if exists $thing{sortby}; $thing{group} //= sub { $thing{id} }; @@ -64,7 +65,8 @@ sub entry { my %thing = %$thing; debug $env => "Rsname is $thing{rsname} and id is $id"; my %params = map {+ rs => $_, $_->get_columns } db($env)->resultset($thing{rsname})->find($id); - $thing{mangle}->(local $_ = \%params) if exists $thing{mangle}; + local $_ = \%params; + $thing{mangle}->($env) if exists $thing{mangle}; wantarray ? %params : \%params } @@ -161,15 +163,18 @@ thing { }; sortby { $b->{id} <=> $a->{id}}; mangle { + my $env = shift; $_->{results} &&= decode_json $_->{results}; $_->{owner_name} = $_->{rs}->owner->name; $_->{problem_name} = $_->{rs}->problem->name; $_->{size} = length $_->{source}; delete $_->{source}; + $_->{pageprefix} = $env->{'gruntmaster.page'} && $env->{'gruntmaster.page'} == -1 ? 'page/' : ''; } }; putsym 'Gruntmaster::Page::Pb::Entry::vary', sub { 'Authorization' }; putsym 'Gruntmaster::Page::Pb::Entry::max_age', sub { 600 }; +putsym 'Gruntmaster::Page::Log::max_age', sub { 10 }; 1