X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FGeneric.pm;h=e0eb290edc86991394206ecf67d0971f30b33a5a;hb=66d79db1f31814685e69add0078dd2f8c7f9a871;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..e0eb290 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,11 +163,13 @@ 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'} == -1 ? 'page/' : ''; } };