[Rt-commit] rt branch, 4.4/new-paging, created. rt-4.2.11-189-g7fa746d

Dustin Graves dustin at bestpractical.com
Fri Sep 25 17:17:45 EDT 2015


The branch, 4.4/new-paging has been created
        at  7fa746d00245f3ef379d459c714744b58da547ff (commit)

- Log -----------------------------------------------------------------
commit 7fa746d00245f3ef379d459c714744b58da547ff
Author: Wallace Reis <wreis at bestpractical.com>
Date:   Mon Sep 8 15:10:59 2014 -0400

    Improve paging for large resultsets
    
    Our current solution works fine, except for the use case of having a large
    resultset and so having a lot of page numbers to list. For instance, it
    makes difficult to the user being on page 5 of 100 and wants to quickly
    jump to page 55.
    
    We pondered on having a box for one typing "55" to jump there, but although
    that is the most functional solution, we think it's a awful UX.
    
    Fixes #30374.

diff --git a/sbin/rt-test-dependencies.in b/sbin/rt-test-dependencies.in
index b16bae3..48fcb14 100644
--- a/sbin/rt-test-dependencies.in
+++ b/sbin/rt-test-dependencies.in
@@ -200,6 +200,7 @@ Crypt::Eksblowfish
 CSS::Minifier::XS
 CSS::Squish 0.06
 Data::GUID
+Data::Page::Pageset
 Date::Extract 0.02
 Date::Manip
 DateTime 0.44
diff --git a/share/html/Elements/CollectionListPaging b/share/html/Elements/CollectionListPaging
index a7f2aee..09a09c4 100644
--- a/share/html/Elements/CollectionListPaging
+++ b/share/html/Elements/CollectionListPaging
@@ -62,49 +62,46 @@ if ($Pages == 1) {
   $m->out(loc('Page 1 of 1'));
 }
 else{
-$m->out(loc('Page') . ' ');
-my $prev = $m->interp->apply_escapes($m->comp(
-                    '/Elements/QueryString',
-                    %$URLParams,
-                    Page    => ( $CurrentPage - 1 )
-                   ), 'h');
-my $next = $m->interp->apply_escapes($m->comp(
-                    '/Elements/QueryString',
-                    %$URLParams,
-                    Page    => ( $CurrentPage + 1 )
-                   ), 'h');
-my %show;
-$show{1} = 1;
-$show{$_} = 1 for (($CurrentPage - 2)..($CurrentPage + 2));
-$show{$Pages} = 1;
-my $dots;
+  $m->out(loc('Page') . ' ');
 
-for my $number ( 1 .. $Pages ) {
-    if ( $show{$number} ) {
-        $dots = undef;
-        my $qs =
-          $m->interp->apply_escapes($m->comp( '/Elements/QueryString', %$URLParams, Page => $number ), 'h');
-        $m->out(qq{<span class="pagenum">});
-        if ( $number == $CurrentPage ) {
-            $m->out(qq{<span class="currentpage">$number</span> });
-        }
-        else {
-            $m->out(qq{<a href="$BaseURL$qs">$number</a> });
+  use Data::Page;
+  use Data::Page::Pageset;
+
+  my $pager = Data::Page->new($TotalFound, $Rows, $CurrentPage);
+  my $pageset = Data::Page::Pageset->new($pager);
+
+  for my $chunk ( $pageset->total_pagesets ) {
+    $m->out(qq{<span class="pagenum">});
+    if ( $chunk->is_current ) {
+        for my $number ( $chunk->first .. $chunk->last ) {
+            if ( $number == $CurrentPage ) {
+              $m->out(qq{<span class="currentpage">$number</span> });
+            }
+            else {
+              my $qs = $m->interp->apply_escapes(
+                $m->comp('/Elements/QueryString',
+                  %$URLParams,
+                  Page => $number
+                ),
+                'h',
+              );
+              $m->out(qq{<a href="$BaseURL$qs">$number</a> });
+            }
         }
-    }
-    elsif ( not $dots ) {
-        $dots = 1;
-        $m->out(qq{<span class="dots">...</span>});
+    } else {
+      my $qs = $m->interp->apply_escapes(
+        $m->comp('/Elements/QueryString',
+          %$URLParams,
+          Page => $chunk->first,
+        ),
+        'h',
+      );
+      $m->out(qq{<a href="$BaseURL$qs">$chunk</a>});
     }
     $m->out(qq{</span>});
-}
+  }
 
-if ($CurrentPage > 1) {
-  $m->out(qq{<a href="$BaseURL$prev" class="nav">}.loc('Previous') . qq{</a>});
-}
-if (($CurrentPage * $Rows) < $TotalFound) {
-  $m->out(qq{<a href="$BaseURL$next" class="nav">}.loc('Next').qq{</a>});
-}
 }
+
 $m->out(qq{</div>});
 </%INIT>

-----------------------------------------------------------------------


More information about the rt-commit mailing list