From 6c0aa04610dde7e6bdc69394da0f0c8133b10280 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Thu, 21 Jul 2011 16:04:17 +0200 Subject: [PATCH] Paginating Sanity: MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Nur Seiten anzeigen die... - Erste oder letzte Seite sind - In der Nähe der aktuellen Seite (+-3) - 10,50,100,500,1000,5000 Seiten von der aktuellen entfernt sind --- SL/DB/Helper/Paginated.pm | 15 +++++++++++++-- templates/webpages/common/paginate.html | 10 ++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/SL/DB/Helper/Paginated.pm b/SL/DB/Helper/Paginated.pm index a5a07d067..df5a6e3d9 100644 --- a/SL/DB/Helper/Paginated.pm +++ b/SL/DB/Helper/Paginated.pm @@ -6,6 +6,8 @@ require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(paginate); +use List::MoreUtils qw(any); + sub paginate { my ($self, %params) = @_; my $page = $params{page} || 1; @@ -47,12 +49,21 @@ sub make_common_pages { my ($cur, $max) = @_; return [ map { - active => $_ != $cur, - page => $_, + active => $_ != $cur, + page => $_, + visible => }, 1 .. $max ]; } +sub calc_visibility { + my ($cur, $max, $this) = @_; + any { $_ } abs($cur - $this) < 5, + $cur <= 3, + $cur == $max, + any { ! abs ($cur - $this) % $_ } 10, 50, 100, 500, 1000, 5000; +} + 1; __END__ diff --git a/templates/webpages/common/paginate.html b/templates/webpages/common/paginate.html index 6611f774c..3724f8e8b 100644 --- a/templates/webpages/common/paginate.html +++ b/templates/webpages/common/paginate.html @@ -1,10 +1,8 @@ [%- IF pages.max > 1 %] -[%- IF pages.cur > 1 %]« [%- END %] +[%- IF pages.cur > 1 %]« [% ELSE %]« [% END %] [%- FOR p = pages.common %] - [%- IF p.active %][% p.page %] - [%- ELSE %][% p.page %] - [%- END %] - [%- ' ' UNLESS loop.last %] + [%- NEXT UNLESS p.visible %] + [%- IF p.active %][% p.page %] [% ELSE %][% p.page %] [%- END %] [%- END %] -[%- IF pages.cur < pages.max %] »[%- END %] +[%- IF pages.cur < pages.max %]»[% ELSE %]»[%- END %] [%- END %] -- 2.20.1