From 97221b394a50415d9ac52efb9304b5b96d0ae581 Mon Sep 17 00:00:00 2001 From: Thomas Berezansky Date: Thu, 17 May 2012 10:29:58 -0400 Subject: [PATCH] TPac: Holds Paging Add Paging for current holds with page numbers Update Paging for hold history to include page numbers Signed-off-by: Thomas Berezansky Signed-off-by: Lebbeous Fogle-Weekley --- .../lib/OpenILS/Application/Circ/Holds.pm | 13 +++++-- .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 38 +++++++++++-------- .../templates/opac/myopac/hold_history.tt2 | 22 ++++++++--- Open-ILS/src/templates/opac/myopac/holds.tt2 | 31 +++++++++++++-- 4 files changed, 76 insertions(+), 28 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm index 1dee0c365a..be54c6821a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm @@ -419,7 +419,8 @@ __PACKAGE__->register_method( desc => "Retrieves all the holds, with hold transits attached, for the specified user. $ses_is_req_note", params => [ { desc => 'Authentication token', type => 'string' }, - { desc => 'User ID', type => 'integer' } + { desc => 'User ID', type => 'integer' }, + { desc => 'Available Only', type => 'boolean' } ], return => { desc => 'list of holds, event on error', @@ -435,7 +436,8 @@ __PACKAGE__->register_method( desc => "Retrieves all the hold IDs, for the specified user. $ses_is_req_note", params => [ { desc => 'Authentication token', type => 'string' }, - { desc => 'User ID', type => 'integer' } + { desc => 'User ID', type => 'integer' }, + { desc => 'Available Only', type => 'boolean' } ], return => { desc => 'list of holds, event on error', @@ -477,7 +479,7 @@ __PACKAGE__->register_method( sub retrieve_holds { - my ($self, $client, $auth, $user_id) = @_; + my ($self, $client, $auth, $user_id, $available) = @_; my $e = new_editor(authtoken=>$auth); return $e->event unless $e->checkauth; @@ -551,6 +553,11 @@ sub retrieve_holds { ]; $holds_query->{where}->{cancel_time} = undef; + if($available) { + $holds_query->{where}->{shelf_time} = {'!=' => undef}; + # Maybe? + $holds_query->{where}->{pickup_lib} = {'+ahr' => 'current_shelf_lib'}; + } } my $hold_ids = $e->json_query($holds_query); 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 81edf810e7..91576d4981 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -454,15 +454,16 @@ sub fetch_user_holds { $hold_ids = $circ->request( 'open-ils.circ.holds.id_list.retrieve.authoritative', $e->authtoken, - $e->requestor->id + $e->requestor->id, + $available )->gather(1); $circ->kill_me; - - $hold_ids = [ grep { defined $_ } @$hold_ids[$offset..($offset + $limit - 1)] ] if $limit or $offset; } + my $all_ids = $hold_ids; + $hold_ids = [ grep { defined $_ } @$hold_ids[$offset..($offset + $limit - 1)] ] if $limit or $offset; - return $hold_ids if $ids_only or @$hold_ids == 0; + return { ids => $hold_ids, all_ids => $all_ids } if $ids_only or @$hold_ids == 0; my $args = { suppress_notices => 1, @@ -499,10 +500,6 @@ sub fetch_user_holds { last if $first and not @ses; if(@collected) { - # If desired by the caller, filter any holds that are not available. - if ($available) { - @collected = grep { $_->{hold}->{status} == 4 } @collected; - } while(my $blob = pop(@collected)) { my (undef, @data) = $self->get_records_and_facets( [$blob->{hold}->{bre_id}], undef, {flesh => '{mra}'} @@ -528,7 +525,7 @@ sub fetch_user_holds { push @sorted, grep { $_->{hold}->{hold}->id == $id } @holds; } - return \@sorted; + return { holds => \@sorted, ids => $hold_ids, all_ids => $all_ids }; } sub handle_hold_update { @@ -539,7 +536,7 @@ sub handle_hold_update { my $url; my @hold_ids = ($hold_ids) ? @$hold_ids : $self->cgi->param('hold_id'); # for non-_all actions - @hold_ids = @{$self->fetch_user_holds(undef, 1)} if $action =~ /_all/; + @hold_ids = @{$self->fetch_user_holds(undef, 1)->{ids}} if $action =~ /_all/; my $circ = OpenSRF::AppSession->create('open-ils.circ'); @@ -609,7 +606,7 @@ sub load_myopac_holds { my $e = $self->editor; my $ctx = $self->ctx; - my $limit = $self->cgi->param('limit') || 0; + my $limit = $self->cgi->param('limit') || 15; my $offset = $self->cgi->param('offset') || 0; my $action = $self->cgi->param('action') || ''; my $hold_id = $self->cgi->param('id'); @@ -618,7 +615,13 @@ sub load_myopac_holds { my $hold_handle_result; $hold_handle_result = $self->handle_hold_update($action) if $action; - $ctx->{holds} = $self->fetch_user_holds($hold_id ? [$hold_id] : undef, 0, 1, $available, $limit, $offset); + my $holds_object = $self->fetch_user_holds($hold_id ? [$hold_id] : undef, 0, 1, $available, $limit, $offset); + if($holds_object->{holds}) { + $ctx->{holds} = $holds_object->{holds}; + } + $ctx->{holds_ids} = $holds_object->{all_ids}; + $ctx->{holds_limit} = $limit; + $ctx->{holds_offset} = $offset; return defined($hold_handle_result) ? $hold_handle_result : Apache2::Const::OK; } @@ -1173,12 +1176,15 @@ sub load_myopac_hold_history { }] }, from => 'au', - where => {id => $e->requestor->id}, - limit => $limit, - offset => $offset + where => {id => $e->requestor->id} }); - $ctx->{holds} = $self->fetch_user_holds([map { $_->{id} } @$hold_ids], 0, 1, 0); + my $holds_object = $self->fetch_user_holds([map { $_->{id} } @$hold_ids], 0, 1, 0, $limit, $offset); + if($holds_object->{holds}) { + $ctx->{holds} = $holds_object->{holds}; + } + $ctx->{hold_history_ids} = $holds_object->{all_ids}; + return Apache2::Const::OK; } diff --git a/Open-ILS/src/templates/opac/myopac/hold_history.tt2 b/Open-ILS/src/templates/opac/myopac/hold_history.tt2 index 2c3e6112d8..7276c9dadd 100644 --- a/Open-ILS/src/templates/opac/myopac/hold_history.tt2 +++ b/Open-ILS/src/templates/opac/myopac/hold_history.tt2 @@ -5,13 +5,14 @@ myopac_page = "holds"; limit = ctx.hold_history_limit; offset = ctx.hold_history_offset; + count = ctx.hold_history_ids.size; %]
[% l("Holds History") %] @@ -21,11 +22,22 @@
[% l("Previously Held Items") %] - limit,offset => (offset - limit)}) %]' [% IF offset == 0 %] class='invisible' [% END %]>[% l('Previous') %] - [%# TODO: get total to prevent paging off then end of the list.. %] - + [% IF offset > 0 || count > limit; + curpage = 0; + WHILE curpage * limit < count; + IF curpage * limit == offset; + %] + [% curpage + 1 %] + [%- ELSE %] + limit, offset => (curpage * limit)}) %]'>[% curpage + 1 %] + [%- END; + curpage = curpage + 1; + END; + END %] + limit, offset => (offset + limit)}) %]' + [% IF count <= limit + offset %] class='invisible' [% END %] >[% l('Next') %] Export List diff --git a/Open-ILS/src/templates/opac/myopac/holds.tt2 b/Open-ILS/src/templates/opac/myopac/holds.tt2 index 1a6f20954f..8321067fc7 100644 --- a/Open-ILS/src/templates/opac/myopac/holds.tt2 +++ b/Open-ILS/src/templates/opac/myopac/holds.tt2 @@ -2,7 +2,11 @@ PROCESS "opac/parts/misc_util.tt2"; PROCESS "opac/parts/hold_status.tt2"; WRAPPER "opac/parts/myopac/base.tt2"; - myopac_page = "holds" %] + myopac_page = "holds"; + limit = ctx.holds_limit; + offset = ctx.holds_offset; + count = ctx.holds_ids.size; +%] @@ -23,6 +27,25 @@ END %] + + limit,offset => (offset - limit)}) %]' + [% IF offset <= 0 %] class='invisible' [% END %]>[% l('Previous') %] + [% IF offset > 0 || count > limit; + curpage = 0; + WHILE curpage * limit < count; + IF curpage * limit == offset; + %] + [% curpage + 1 %] + [%- ELSE %] + limit, offset => (curpage * limit)}) %]'>[% curpage + 1 %] + [%- END; + curpage = curpage + 1; + END; + END %] + limit, offset => (offset + limit)}) %]' + [% IF count <= limit + offset %] class='invisible' [% END %] >[% l('Next') %] + + Export List @@ -62,11 +85,11 @@ [% l("Show") %]     [% IF CGI.param("available") %] - [% l('all') %] | + [% l('all') %] | [% l("only available") %] [% ELSE %] [% l("all") %] | - [% l("only available") %] + [% l("only available") %] [% END %]     [% l("holds") %]