From 3e24a2cbe440de80fd2d310dc5db677618f86b45 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 20 Jun 2014 17:31:32 +0200 Subject: [PATCH] Paginator/SlidingWithBorder: use less space Showing less items right now. It would be great if we could steer this by parameter. IMO we should also think about dropping ZF pagination and use a custom tiny widget. --- .../ScrollingStyle/SlidingWithBorder.php | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php b/library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php index 23b0b7639..94a4fe4f6 100644 --- a/library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php +++ b/library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php @@ -43,6 +43,7 @@ class Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder implements Zend_Pagi */ public function getPages(Zend_Paginator $paginator, $pageRange = null) { + // This is unused if ($pageRange === null) { $pageRange = $paginator->getPageRange(); } @@ -51,40 +52,52 @@ class Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder implements Zend_Pagi $pageCount = count($paginator); $range = array(); - if ($pageCount < 15) { - for ($i = 1; $i < 15; $i++) { + if ($pageCount < 10) { + // Show all pages if we have less than 10. + + for ($i = 1; $i < 10; $i++) { if ($i > $pageCount) { break; } $range[$i] = $i; } } else { + // More than 10 pages: + foreach (array(1, 2) as $i) { $range[$i] = $i; } - if ($pageNumber > 8) { - $range[] = '...'; - $start = 5; - if ($pageCount - $pageNumber < 8) { - $start = 9 - ($pageCount - $pageNumber); + if ($pageNumber < 6 ) { + // We are on page 1-5 from + for ($i = 1; $i <= 7; $i++) { + $range[$i] = $i; } - for ($i = $pageNumber - $start; $i < $pageNumber + (10 - $start); $i++) { + } else { + // Current page > 5 + $range[] = '...'; + + // Less than 5 pages left + if (($pageCount - $pageNumber) < 5) { + $start = 5 - ($pageCount - $pageNumber); + } else { + $start = 1; + } + + for ($i = $pageNumber - $start; $i < ($pageNumber + (4 - $start)); $i++) { if ($i > $pageCount) { break; } $range[$i] = $i; } - } else { - for ($i = 3; $i <= 10; $i++) { - $range[$i] = $i; - } } - if ($pageNumber < ($pageCount - 7)) { + if ($pageNumber < ($pageCount - 2)) { $range[] = '...'; - foreach (array($pageCount - 1, $pageCount) as $i) { - $range[$i] = $i; - } } + + foreach (array($pageCount - 1, $pageCount) as $i) { + $range[$i] = $i; + } + } if (empty($range)) { $range[] = 1;