]> iEval git - gruntmaster-page.git/blobdiff - lib/Gruntmaster/Page/Generic.pm
Pass env to mangle in Generic
[gruntmaster-page.git] / lib / Gruntmaster / Page / Generic.pm
index 9e07d4c8a68814aa11189b8a8f5a30e7d9390864..e0eb290edc86991394206ecf67d0971f30b33a5a 100644 (file)
@@ -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/' : '';
        }
 };
 
This page took 0.022815 seconds and 4 git commands to generate.