[Rt-commit] rt branch 5.0/update-search-result-paging created. rt-5.0.3-227-g448dd21f2d

BPS Git Server git at git.bestpractical.com
Fri Jan 13 14:07:15 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/update-search-result-paging has been created
        at  448dd21f2d4807a07c60d7fcc3dbcf45d70915d2 (commit)

- Log -----------------------------------------------------------------
commit 448dd21f2d4807a07c60d7fcc3dbcf45d70915d2
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Jan 13 08:51:24 2023 -0500

    Remove Data::Page::Pageset from dependencies
    
    Include Data::Page directly. Previously it was pulled in
    as a dependency of Data::Page::Pageset.

diff --git a/etc/cpanfile b/etc/cpanfile
index 842371301e..f058f66d87 100644
--- a/etc/cpanfile
+++ b/etc/cpanfile
@@ -15,7 +15,7 @@ requires 'CSS::Minifier::XS';
 requires 'CSS::Squish', '>= 0.06';
 requires 'Data::GUID';
 requires 'Data::ICal';
-requires 'Data::Page::Pageset';
+requires 'Data::Page';
 requires 'Date::Extract', '>= 0.02';
 requires 'Date::Manip';
 requires 'DateTime', '>= 0.44';

commit 269d5d3e2a0d3f141d3daf4ebeef84cf19d6cb64
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Jan 9 17:00:58 2023 -0500

    Add box to jump to search results page

diff --git a/share/html/Elements/CollectionListPaging b/share/html/Elements/CollectionListPaging
index 94b0455b40..15ed494b2b 100644
--- a/share/html/Elements/CollectionListPaging
+++ b/share/html/Elements/CollectionListPaging
@@ -102,3 +102,22 @@ else{
 
 $m->out(qq{</div>});
 </%INIT>
+% if ( $Pages > 1 ) {
+<div class="page-jump mx-auto">
+  <form>
+% foreach my $key ( keys(%$URLParams) ) {
+%   next if $key eq $PageParam;
+    <input type="hidden" class="hidden" name="<% $key %>" value="<% $URLParams->{$key} // '' %>" />
+% }
+    <div class="form-row">
+      <div class="label col-6"><&|/l&>Jump to page</&>:</div>
+      <div class="col-4">
+        <input type="text" class="form-control" name="<% $PageParam %>" value="" />
+      </div>
+      <div class="col-2">
+        <input type="submit" class="button btn btn-primary form-control" value="<&|/l&>Go</&>" />
+      </div>
+    </div>
+  </form>
+</div>
+% }
diff --git a/share/static/css/elevator-light/ticket-lists.css b/share/static/css/elevator-light/ticket-lists.css
index b92436548e..0c23e94772 100644
--- a/share/static/css/elevator-light/ticket-lists.css
+++ b/share/static/css/elevator-light/ticket-lists.css
@@ -57,3 +57,7 @@ li.page-item.active > a.page-link {
     background-color: #3858a3;
     border-color: #3858a3;
 }
+
+.page-jump {
+    width: 200px;
+}

commit f2a30626bd929afb64d321646b9ac029e581b00b
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Jan 3 09:44:10 2023 -0500

    Update search results to use Bootstrap pagination styles
    
    For large sets of search results, this update also replaces
    the huge block of numbers with a simpler begining, middle,
    end set of page numbers. This still allows navigation without
    the giant list of number ranges.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 7de6dcf3fc..e5291ce861 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -5304,6 +5304,69 @@ sub GetDashboards {
     return \%dashboards;
 }
 
+=head2 BuildSearchResultPagination
+
+Accepts a Data::Page object loaded with information about a set of
+search results.
+
+Returns an array with the pages from that set to include when displaying
+pagination for those search results. This array can then be used to
+generate the desired links and other UI.
+
+=cut
+
+sub BuildSearchResultPagination {
+    my $pager = shift;
+    my @pages;
+
+    # For 10 or less, show all pages in a line, no breaks
+    if ( $pager->last_page < 11 ) {
+        push @pages, 1 .. $pager->last_page;
+    }
+    else {
+        # For more pages, need to insert ellipsis for breaks
+        # This creates 1 2 3...10 11 12...51 52 53
+        @pages = ( 1, 2, 3 );
+
+        if ( $pager->current_page() == 3 ) {
+            # When on page 3, show 4 so you can keep going
+            push @pages, ( 4 );
+        }
+        elsif ( $pager->current_page() == 4 ) {
+            # Handle 4 and 5 without ellipsis
+            push @pages, ( 4, 5 );
+        }
+        elsif ( $pager->current_page() == 5 ) {
+            # Handle 4 and 5 without ellipsis
+            push @pages, ( 4, 5, 6 );
+        }
+        elsif ( $pager->current_page() > 5 && $pager->current_page() < ($pager->last_page - 4) ) {
+            push @pages, ( 'ellipsis',
+            $pager->current_page() - 1, $pager->current_page(), $pager->current_page() + 1 );
+        }
+
+        push @pages, 'ellipsis';
+
+        # Add padding at the end, the reverse of the above
+        if ( $pager->current_page() == ($pager->last_page - 2) ) {
+            push @pages, $pager->last_page - 3;
+        }
+
+        if ( $pager->current_page() == ($pager->last_page - 3) ) {
+            push @pages, ( $pager->last_page - 4, $pager->last_page - 3 );
+        }
+
+        if ( $pager->current_page() == ($pager->last_page - 4) ) {
+            push @pages, ( $pager->last_page - 5, $pager->last_page - 4, $pager->last_page - 3 );
+        }
+
+        # Add the end of the list
+        push @pages, ( $pager->last_page - 2, $pager->last_page - 1, $pager->last_page );
+    }
+
+    return @pages;
+}
+
 package RT::Interface::Web;
 RT::Base->_ImportOverlays();
 
diff --git a/share/html/Elements/CollectionListPaging b/share/html/Elements/CollectionListPaging
index 1ba778c499..94b0455b40 100644
--- a/share/html/Elements/CollectionListPaging
+++ b/share/html/Elements/CollectionListPaging
@@ -60,51 +60,44 @@ $BaseURL = $m->interp->apply_escapes($BaseURL, 'h');
 
 $m->out(qq{<div class="paging">});
 if ($Pages == 1) {
-  $m->out(loc('Page 1 of 1'));
+    $m->out(loc('Page 1 of 1'));
 }
 else{
-  $m->out(loc('Page') . ' ');
+    $m->out(qq{<ul class="pagination justify-content-center">});
+    use Data::Page;
 
-  use Data::Page;
-  use Data::Page::Pageset;
+    my $pager = Data::Page->new();
+    $pager->total_entries($TotalFound);
+    $pager->entries_per_page($Rows);
+    $pager->current_page($CurrentPage);
 
-  my $pager = Data::Page->new();
-  $pager->total_entries($TotalFound);
-  $pager->entries_per_page($Rows);
-  $pager->current_page($CurrentPage);
-  my $pageset = Data::Page::Pageset->new($pager);
+    my @pages = BuildSearchResultPagination( $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(
+    foreach my $page ( @pages ) {
+
+        my $active_item = '';
+        $active_item = " active" if ( $page =~ /^\d+/ && $page == $pager->current_page() );
+
+        if ( $page eq 'ellipsis' ) {
+            $m->out(qq{<li class="page-item disabled">});
+            $m->out(qq{<a class="page-link" href="#" tabindex="-1">...</a>});
+            $m->out(qq{</li>});
+            next;
+        }
+        else {
+            # Build the link
+            my $query_string = $m->interp->apply_escapes(
                 $m->comp('/Elements/QueryString',
-                  %$URLParams,
-                  $PageParam => $number
-                ),
+                    %$URLParams,
+                    $PageParam => $page, ),
                 'h',
-              );
-              $m->out(qq{<a href="$BaseURL$qs">$number</a> });
-            }
+            );
+
+            $m->out(qq{<li class="page-item$active_item">});
+            $m->out(qq{<a class="page-link rt-page-link" href="$BaseURL$query_string">$page</a>});
+            $m->out(qq{</li>});
         }
-    } else {
-      my $qs = $m->interp->apply_escapes(
-        $m->comp('/Elements/QueryString',
-          %$URLParams,
-          $PageParam => $chunk->first,
-        ),
-        'h',
-      );
-      $m->out(qq{<a href="$BaseURL$qs">$chunk</a>});
     }
-    $m->out(qq{</span>});
-  }
-
 }
 
 $m->out(qq{</div>});
diff --git a/share/static/css/elevator-light/misc.css b/share/static/css/elevator-light/misc.css
index 6e1d5c0e0a..6a047883ef 100644
--- a/share/static/css/elevator-light/misc.css
+++ b/share/static/css/elevator-light/misc.css
@@ -142,11 +142,6 @@ h1#transaction-extra-info {
     padding-top: 0.4rem;
 }
 
-/* Prevent page links from running off the side of the page for Firefox */
-span.pagenum {
-    display: inline-block;
-}
-
 /* Do not change background color on click of dropdown items like "Show
  * full headers" in ticket history */
 .btn-group.dropdown .dropdown-item:active {
diff --git a/share/static/css/elevator-light/ticket-lists.css b/share/static/css/elevator-light/ticket-lists.css
index cd30418fec..b92436548e 100644
--- a/share/static/css/elevator-light/ticket-lists.css
+++ b/share/static/css/elevator-light/ticket-lists.css
@@ -49,19 +49,11 @@ table.queue-summary th.collection-as-table {
   vertical-align: middle;
 }
 
-.pagenum *,
-.paging a.nav {
-    padding: .5em;
-}
-
-.currentpage {
-    text-decoration: none;
-    font-weight: bold;
-    background: #eee;
+li.page-item > a.rt-page-link {
+    color: #3858a3;
 }
 
-div.paging {
-    font-size: 1.07em;
-    text-align: center;
-    padding-bottom: 1em;
+li.page-item.active > a.page-link {
+    background-color: #3858a3;
+    border-color: #3858a3;
 }

commit 7e05402d2033151bd3f568a59ba6ccadb640f48f
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu Jan 5 14:15:48 2023 -0500

    Convert to preferred constructor for Data::Page
    
    The documentation for Data::Page says the constructor that
    accepts arguments is deprecated, so switch to using the
    provided methods to set page data on the pager object.

diff --git a/share/html/Elements/CollectionListPaging b/share/html/Elements/CollectionListPaging
index 766e41d57d..1ba778c499 100644
--- a/share/html/Elements/CollectionListPaging
+++ b/share/html/Elements/CollectionListPaging
@@ -68,7 +68,10 @@ else{
   use Data::Page;
   use Data::Page::Pageset;
 
-  my $pager = Data::Page->new($TotalFound, $Rows, $CurrentPage);
+  my $pager = Data::Page->new();
+  $pager->total_entries($TotalFound);
+  $pager->entries_per_page($Rows);
+  $pager->current_page($CurrentPage);
   my $pageset = Data::Page::Pageset->new($pager);
 
   for my $chunk ( $pageset->total_pagesets ) {

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list