From f6a0fc36bf876094d9cc422fc6407613019ec048 Mon Sep 17 00:00:00 2001 From: Kyle Tomita Date: Wed, 27 Mar 2013 10:23:20 -0700 Subject: [PATCH] LP1160596 - Add pagination for items in My Lists Added pagination with page numbers when viewing the items in a list. Signed-off-by: Kyle Tomita Signed-off-by: Pasi Kallinen --- .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 71 ++++++++++++++++++++-- Open-ILS/src/templates/opac/myopac/lists.tt2 | 57 ++++++++++++++++- 2 files changed, 122 insertions(+), 6 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index ec7bb9658a..f10a53acc5 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -1686,6 +1686,12 @@ sub load_myopac_bookbags { $ctx->{bookbags_limit} = $limit; $ctx->{bookbags_offset} = $offset; + # for list item pagination + my $itemLimit = 10; + my $itemPage = $self->cgi->param('itemPage') || 1; + my $itemOffset = ($itemPage - 1) * $itemLimit; + $ctx->{bookbags_itemPage} = $itemPage; + my ($sorter, $modifier) = $self->_get_bookbag_sort_params("sort"); $e->xact_begin; # replication... @@ -1724,13 +1730,69 @@ sub load_myopac_bookbags { $ctx->{bookbag_count} = $r->[0]->{'count'}; # If the user wants a specific bookbag's items, load them. - # XXX add bookbag item paging support if ($self->cgi->param("bbid")) { my ($bookbag) = grep { $_->id eq $self->cgi->param("bbid") } @{$ctx->{bookbags}}; if ($bookbag) { + # Calculate total count of the items in selected bookbag. + # This total includes record entries that have no assets available. + my $iq = { + 'select' => { 'acn' => [ { 'column' => 'record', 'distinct' => 'true', 'transform' => 'count', 'aggregate' => 'true', 'alias' => 'count' } ] }, + 'from' => {'cbrebi' => + { 'bre' => + { 'join' => + { 'acn' => + { 'join' => + { 'acp' => + { 'join' => + { 'ccs' => {} + } + } + } + } + } + } + } + }, + 'where' => { + '+cbrebi' => { 'bucket' => $bookbag->id }, + '+acn' => { 'deleted' => 'f' }, + '+ccs' => { 'opac_visible' => 't' }, + '+acp' => { + 'deleted' => 'f', + 'opac_visible' => 't' + } + } + }; + my $ir = $e->json_query($iq); + $ctx->{bb_item_count} = $ir->[0]->{'count'}; + #now add ebooks + my $ebook_q = { + 'select' => { 'cbrebi' => [ { 'column' => 'target_biblio_record_entry', 'distinct' => 'true', 'transform' => 'count', 'aggregate' => 'true', 'alias' => 'count' } ] }, + 'from' => {'cbrebi' => + { 'bre' => + { 'join' => + { } + } + } + }, + 'where' => { + '+cbrebi' => { 'bucket' => $bookbag->id }, + '+bre' => { + 'deleted' => 'f', + 'source' => 101, + 'active' => 't' + } + } + }; + my $ebook_r = $e->json_query($ebook_q); + $ctx->{bb_item_count} = $ctx->{bb_item_count} + $ebook_r->[0]->{'count'}; + + #calculate page count + $ctx->{bb_page_count} = int ((($ctx->{bb_item_count} - 1) / $itemLimit) + 1); + if ( ($self->cgi->param("action") || '') eq "editmeta") { if (!$self->_update_bookbag_metadata($bookbag)) { $e->rollback; @@ -1760,11 +1822,10 @@ sub load_myopac_bookbags { $bookbag->id, $sorter, $modifier ); - # XXX Limiting to 1000 for now. This way you should be able to see entire - # list contents. Need to add paging here instead. + # For list items pagination my $args = { - "limit" => 1000, - "offset" => 0 + "limit" => $itemLimit, + "offset" => $itemOffset }; my $items = $U->bib_container_items_via_search($bookbag->id, $query, $args) diff --git a/Open-ILS/src/templates/opac/myopac/lists.tt2 b/Open-ILS/src/templates/opac/myopac/lists.tt2 index 0b2977dc93..bbb0f66c51 100644 --- a/Open-ILS/src/templates/opac/myopac/lists.tt2 +++ b/Open-ILS/src/templates/opac/myopac/lists.tt2 @@ -4,6 +4,7 @@ myopac_page = "lists" limit = ctx.bookbags_limit; offset = ctx.bookbags_offset; + itemPage = ctx.bookbags_itemPage; %]
@@ -86,7 +87,7 @@
[% baseurl = ctx.opac_root _ '/myopac/lists'; IF bbag.id != CGI.param("bbid"); - url = mkurl(baseurl,{bbid => bbag.id},['edit_notes','sort']); + url = mkurl(baseurl,{bbid => bbag.id, itemPage => 1},['edit_notes','sort']); ltitle = l("Show items in list"); ELSE; url = mkurl(baseurl, {}, ['bbid', 'edit_notes', 'sort']); @@ -338,6 +339,60 @@ [% END %] + + [% IF ctx.bb_page_count > 1; %] +
+ [% l('Navigate Selected List ') %] + + [%- IF itemPage > 1 -%] + itemPage - 1 + }) %]'>[% l('Previous') %] + [%- END; -%] + + [%- IF (itemPage - 3) >= 1 -%] + itemPage - 3 + }) %]'>[% itemPage - 3 %] + [%- END; -%] + [%- IF (itemPage - 2) >= 1 -%] + itemPage - 2 + }) %]'>[% itemPage - 2 %] + [%- END; -%] + [%- IF (itemPage - 1) >= 1 -%] + itemPage - 1 + }) %]'>[% itemPage - 1%] + [%- END; -%] + [% itemPage %] + [%- IF (itemPage + 1) <= ctx.bb_page_count -%] + itemPage + 1 + }) %]'>[% itemPage + 1 %] + [%- END; -%] + [%- IF (itemPage + 2) <= ctx.bb_page_count -%] + itemPage + 2 + }) %]'>[% itemPage + 2 %] + [%- END; -%] + [%- IF (itemPage + 3) <= ctx.bb_page_count -%] + itemPage + 3 + }) %]'>[% itemPage + 3 %] + [%- END; -%] + + [%- IF (itemPage + 1) <= ctx.bb_page_count; -%] + itemPage + 1 + }) %]'>[% l('Next') %] + [%- END; -%] + +
+
+ [% END %] +
+ [% END %] [% END %] -- 2.11.0