From 5b22ebf0e0e3cf62364dfb46a7f2de28f90289da Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 23 Nov 2012 12:15:39 +0100 Subject: [PATCH] =?utf8?q?Refactoring:=20In=20R=C3=BCckgabewert=20vom=20Pa?= =?utf8?q?ginated-DB-Helfer=20'cur'=20in=20'page'=20umbenennen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Dient Konsistenz der Eingangs- und Ausgangsparameter. Dadurch entfällt auch das Hin- und Herbenennen im Paginated-Controller-Helfer/im L-Plugin. --- SL/Controller/Helper/Paginated.pm | 10 ++-------- SL/DB/Helper/Paginated.pm | 6 +++--- SL/Template/Plugin/L.pm | 6 +----- templates/webpages/common/paginate.html | 4 ++-- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/SL/Controller/Helper/Paginated.pm b/SL/Controller/Helper/Paginated.pm index 1683aada0..15997b8e9 100644 --- a/SL/Controller/Helper/Paginated.pm +++ b/SL/Controller/Helper/Paginated.pm @@ -61,16 +61,10 @@ sub get_current_paginate_params { : $spec->{PAGINATE_ARGS} ? do { my $sub = $spec->{PAGINATE_ARGS}; %{ $self->$sub() } } : (); my $calculated_params = "SL::DB::Manager::$spec->{MODEL}"->paginate(%paginate_params, args => \%paginate_args); - %paginate_params = ( - page => min($paginate_params{page}, $calculated_params->{max}), - per_page => $paginate_params{per_page}, - num_pages => $calculated_params->{max}, - common_pages => $calculated_params->{common}, - ); - # $::lxdebug->dump(0, "get_current_paginate_params: ", \%paginate_params); + # $::lxdebug->dump(0, "get_current_paginate_params: ", $calculated_params); - return %paginate_params; + return %{ $calculated_params }; } sub disable_pagination { diff --git a/SL/DB/Helper/Paginated.pm b/SL/DB/Helper/Paginated.pm index a0ad02cb8..27daffedd 100644 --- a/SL/DB/Helper/Paginated.pm +++ b/SL/DB/Helper/Paginated.pm @@ -17,12 +17,12 @@ sub paginate { $ret->{per_page} = per_page($self, %params); $ret->{max} = ceil($self->get_all_count(%args), $ret->{per_page}) || 1; - $ret->{cur} = $page < 1 ? 1 + $ret->{page} = $page < 1 ? 1 : $page > $ret->{max} ? $ret->{max} : $page; - $ret->{common} = make_common_pages($ret->{cur}, $ret->{max}); + $ret->{common} = make_common_pages($ret->{page}, $ret->{max}); - $params{args}{page} = $ret->{cur}; + $params{args}{page} = $ret->{page}; $params{args}{per_page} = $ret->{per_page}; delete $params{args}{limit}; delete $params{args}{offset}; diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index 95d225441..c590082cf 100644 --- a/SL/Template/Plugin/L.pm +++ b/SL/Template/Plugin/L.pm @@ -689,11 +689,7 @@ sub paginate_controls { my %paginate_params = $controller->get_current_paginate_params; my %template_params = ( - pages => { - cur => $paginate_params{page}, - max => $paginate_params{num_pages}, - common => $paginate_params{common_pages}, - }, + pages => \%paginate_params, url_maker => sub { my %url_params = _hashify(@_); $url_params{ $paginate_spec->{FORM_PARAMS}->[0] } = delete $url_params{page}; diff --git a/templates/webpages/common/paginate.html b/templates/webpages/common/paginate.html index 089972947..c833904b8 100644 --- a/templates/webpages/common/paginate.html +++ b/templates/webpages/common/paginate.html @@ -8,11 +8,11 @@ [%- END %] [%- IF pages.max > 1 %]
-[%- IF pages.cur > 1 %]« [% 'prev' | $T8 %] [% ELSE %]« [% END %] +[%- IF pages.page > 1 %]« [% 'prev' | $T8 %] [% ELSE %]« [% END %] [%- FOR p = pages.common %] [%- NEXT UNLESS p.visible %] [%- IF p.active %][% p.page %] [% ELSE %][% p.page %] [%- END %] [%- END %] -[%- IF pages.cur < pages.max %][% 'next' | $T8 %] »[% ELSE %]»[%- END %] +[%- IF pages.page < pages.max %][% 'next' | $T8 %] »[% ELSE %]»[%- END %]
[%- END %] -- 2.20.1