TPac: Add paging to My Lists
authorBob Wicksall <bwicksall@pls-net.org>
Fri, 29 Jun 2012 18:33:22 +0000 (14:33 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 10 Jul 2012 21:27:01 +0000 (17:27 -0400)
- Added paging to My Lists based on the code from the Checkout History tab.
- Fixed a bug where adding more than 10 items to the Temporary list failed
- After adding paging renaming a list on page 2+ would fail.  Fixed.
- Redirect after saving a list now leaves you on the same page
- Paging was bleeding between My Lists, Holds History and Circ History.
  Fixed.

List contents were also limited to the first 10.  I have upped the limit to
1000 rather than having nested paging.  This should be revisited.

CSV download of lists is still limited to the first 10.  Not sure where to
fix this.

Signed-off-by: Bob Wicksall <bwicksall@pls-net.org>
Signed-off-by: Ben Shum <bshum@biblio.org>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm
Open-ILS/src/templates/opac/myopac/lists.tt2
Open-ILS/src/templates/opac/parts/myopac/base.tt2

index 2346542..5038851 100644 (file)
@@ -1620,6 +1620,11 @@ sub load_myopac_bookbags {
     my $self = shift;
     my $e = $self->editor;
     my $ctx = $self->ctx;
+    my $limit = $self->cgi->param('limit') || 10;
+    my $offset = $self->cgi->param('offset') || 0;
+
+    $ctx->{bookbags_limit} = $limit;
+    $ctx->{bookbags_offset} = $offset;
 
     my ($sorter, $modifier) = $self->_get_bookbag_sort_params("sort");
     $e->xact_begin; # replication...
@@ -1634,8 +1639,8 @@ sub load_myopac_bookbags {
         [
             {owner => $e->requestor->id, btype => 'bookbag'}, {
                 order_by => {cbreb => 'name'},
-                limit => $self->cgi->param('limit') || 10,
-                offset => $self->cgi->param('offset') || 0
+                limit => $limit,
+                offset => $offset
             }
         ],
         {substream => 1}
@@ -1653,48 +1658,50 @@ sub load_myopac_bookbags {
         my ($bookbag) =
             grep { $_->id eq $self->cgi->param("bbid") } @{$ctx->{bookbags}};
 
-        if (!$bookbag) {
-            $e->rollback;
-            return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
-        }
-
-        if ( ($self->cgi->param("action") || '') eq "editmeta") {
-            if (!$self->_update_bookbag_metadata($bookbag))  {
-                $e->rollback;
-                return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
-            } else {
-                $e->commit;
-                my $url = $self->ctx->{opac_root} . '/myopac/lists?bbid=' .
-                    $bookbag->id;
+        if ($bookbag) {
+            if ( ($self->cgi->param("action") || '') eq "editmeta") {
+                if (!$self->_update_bookbag_metadata($bookbag))  {
+                    $e->rollback;
+                    return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
+                } else {
+                    $e->commit;
+                    my $url = $self->ctx->{opac_root} . '/myopac/lists?bbid=' .
+                        $bookbag->id;
 
-                foreach my $param (('loc', 'qtype', 'query', 'sort')) {
-                    if ($self->cgi->param($param)) {
-                        $url .= ";$param=" . uri_escape($self->cgi->param($param));
+                    foreach my $param (('loc', 'qtype', 'query', 'sort', 'offset', 'limit')) {
+                        if ($self->cgi->param($param)) {
+                            $url .= ";$param=" . uri_escape($self->cgi->param($param));
+                        }
                     }
-                }
 
-                return $self->generic_redirect($url);
+                    return $self->generic_redirect($url);
+                }
             }
-        }
 
-        my $query = $self->_prepare_bookbag_container_query(
-            $bookbag->id, $sorter, $modifier
-        );
+            my $query = $self->_prepare_bookbag_container_query(
+                $bookbag->id, $sorter, $modifier
+            );
 
-        # XXX we need to limit the number of records per bbag; use third arg
-        # of bib_container_items_via_search() i think.
-        my $items = $U->bib_container_items_via_search($bookbag->id, $query)
-            or return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
+            # XXX Limiting to 1000 for now.  This way you should be able to see entire
+            # list contents.  Need to add paging here instead.
+            my $args = {
+                "limit" => 1000,
+                "offset" => 0
+            };
 
-        my (undef, @recs) = $self->get_records_and_facets(
-            [ map {$_->target_biblio_record_entry->id} @$items ],
-            undef, 
-            {flesh => '{mra}'}
-        );
+            my $items = $U->bib_container_items_via_search($bookbag->id, $query, $args)
+                or return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
+
+            my (undef, @recs) = $self->get_records_and_facets(
+                [ map {$_->target_biblio_record_entry->id} @$items ],
+                undef, 
+                {flesh => '{mra}'}
+            );
 
-        $ctx->{bookbags_marc_xml}{$_->{id}} = $_->{marc_xml} for @recs;
+            $ctx->{bookbags_marc_xml}{$_->{id}} = $_->{marc_xml} for @recs;
 
-        $bookbag->items($items);
+            $bookbag->items($items);
+        }
     }
 
     $e->rollback;
index 6cc6796..ba7a6ce 100644 (file)
@@ -38,7 +38,11 @@ sub fetch_mylist {
     if (@$list) {
         my ($sorter, $modifier) = $self->_get_bookbag_sort_params("anonsort");
         my $query = $self->_prepare_anonlist_sorting_query($list, $sorter, $modifier);
-        $list = $U->bib_record_list_via_search($query) or
+        my $args = {
+            "limit" => 1000,
+            "offset" => 0
+        };
+        $list = $U->bib_record_list_via_search($query, $args) or
             return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
     }
 
index efefd4d..88972c6 100644 (file)
@@ -1,7 +1,10 @@
 [%  PROCESS "opac/parts/header.tt2";
     PROCESS "opac/parts/misc_util.tt2";
     WRAPPER "opac/parts/myopac/base.tt2";
-    myopac_page = "lists"  %]
+    myopac_page = "lists"  
+    limit = ctx.bookbags_limit;
+    offset = ctx.bookbags_offset;
+%]
 <div id='myopac_bookbag_div' style="padding:5px;">
 
     <!-- new list creation -->
     <h1>[% l("Your existing lists") %]</h1>
     [% INCLUDE "opac/parts/anon_list.tt2" %]
     [% IF ctx.bookbags.size %]
+    <div class="header_middle">
+        <span class="float-left">[% l('Saved Lists') %]</span>
+        <span class='float-left' style='padding-left: 10px;'>
+            <a href='[% mkurl(ctx.opac_root _ '/myopac/lists', {limit => limit, offset => (offset - limit)}) %]'
+                [% IF offset == 0 %] class='invisible' [% END %]><span class="nav_arrow_fix">&#9668;</span>[% l('Previous') %]</a>
+            [%# TODO: get total to prevent paging off then end of the list.. %]
+            <a href='[% mkurl(ctx.opac_root _ '/myopac/lists', {limit => limit, offset => (offset + limit)}) %]'
+               [% IF ctx.bookbags.size < limit %] class='invisible' [% END %] >[% l('Next') %]<span class="nav_arrow_fix">&#9658;</span></a>
+        </span>
+    </div>
+    <div class="clear-both"></div>
+
     <div id='acct_lists_prime'>
         [% FOR bbag IN ctx.bookbags %]
         <div class="bookbag-controls-holder">
                 <form method="POST">
                     <input type="hidden" name="bbid" value="[% bbag.id %]" />
                     <input type="hidden" name="action" value="editmeta" />
+                    <input type="hidden" name="limit" value="[% limit %]" />
+                    <input type="hidden" name="offset" value="[% offset %]" />
                     [%- INCLUDE "opac/parts/preserve_params.tt2"; %]
                     <table id="bbag-name-desc-form">
                         <tr>
index 763e65b..c433c6a 100644 (file)
@@ -23,7 +23,7 @@
                     ELSE;
                         cls_which = "acct-tab-off";
                     END -%]
-                <a href="[% mkurl(ctx.opac_root _ '/myopac/' _ page.url, {}, ['bbid']) %]"
+                <a href="[% mkurl(ctx.opac_root _ '/myopac/' _ page.url, {}, ['bbid', 'offset', 'limit']) %]"
                     class="[% cls_which %]">[% page.name; %]</a>
                 [% END %]
             </div>