From 3e1590fff2f1232aef6e6a0a1f6ec75e412057b4 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Mon, 29 Jun 2020 16:58:37 -0400 Subject: [PATCH] LP#1879983: Restrict top-level curbside tab display Refactor the code checking for curbside-available current-pickup libraries so that it is checked for all of MyOPAC, allowing us to hide the Curbside Pickup top-level tab when there are no holds ready at curbside pickup enabled locations. The tab will always be at the end of the list if it is visible. Signed-off-by: Mike Rylander Signed-off-by: Michele Morgan Signed-off-by: Galen Charlton --- .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 6 ++- .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 51 ++++++++++++---------- Open-ILS/src/templates/opac/parts/myopac/base.tt2 | 4 +- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index 8479fabfc9..907ae8bec0 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -241,8 +241,13 @@ sub load { return $self->load_mylist_email if $path =~ m|opac/mylist/doemail|; return $self->load_print_or_email_preview('email') if $path =~ m|opac/record/email_preview|; return $self->load_email_record if $path =~ m|opac/record/email|; + return $self->load_sms_cn if $path =~ m|opac/sms_cn|; return $self->load_place_hold if $path =~ m|opac/place_hold|; + + # centralize check for curbside tab display + $self->load_current_curbside_libs; + return $self->load_myopac_holds if $path =~ m|opac/myopac/holds|; return $self->load_myopac_circs if $path =~ m|opac/myopac/circs|; return $self->load_myopac_messages if $path =~ m|opac/myopac/messages|; @@ -269,7 +274,6 @@ sub load { return $self->load_myopac_prefs_my_lists if $path =~ m|opac/myopac/prefs_my_lists|; return $self->load_myopac_prefs if $path =~ m|opac/myopac/prefs|; return $self->load_myopac_reservations if $path =~ m|opac/myopac/reservations|; - return $self->load_sms_cn if $path =~ m|opac/sms_cn|; return Apache2::Const::OK; } 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 b3e6672394..4da79eb67d 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -1171,16 +1171,8 @@ sub fetch_user_holds { # put the holds back into the original server sort order my @sorted; - my %pickup_libs; for my $id (@$hold_ids) { push @sorted, grep { $_->{hold}->{hold}->id == $id } @holds; - - my $h = $sorted[-1]->{hold}->{hold}; - # if available, report the pickup lib in the list - $pickup_libs{$h->pickup_lib} = 1 if ( - $h && $h->pickup_lib == $h->current_shelf_lib && - $h->shelf_time && !$h->cancel_time && !$h->fulfillment_time - ); } my $curbsides = []; @@ -1192,9 +1184,34 @@ sub fetch_user_holds { ); } catch Error with {}; - my @pickup_libs = sort { $U->find_org($U->get_org_tree,$a)->name cmp $U->find_org($U->get_org_tree,$b)->name } keys %pickup_libs; + return { holds => \@sorted, ids => $hold_ids, all_ids => $all_ids, curbsides => $curbsides }; +} + +sub load_current_curbside_libs { + my $self = shift; + my $ctx = $self->ctx; + my $e = $self->editor; + my $holds = $e->search_action_hold_request({ + usr => $e->requestor->id, + shelf_time => { '!=' => undef }, + cancel_time => undef, + fulfillment_time => undef + }); - return { holds => \@sorted, ids => $hold_ids, all_ids => $all_ids, pickup_libs => \@pickup_libs, curbsides => $curbsides }; + my %pickup_libs; + for my $h (@$holds) { + next if ($h->pickup_lib != $h->current_shelf_lib); + $pickup_libs{$h->pickup_lib} = 1; + } + + my @curbside_pickup_libs; + for my $pul (keys %pickup_libs) { + push(@curbside_pickup_libs, $pul) if $ctx->{get_org_setting}->($pul, 'circ.curbside'); + } + + $ctx->{curbside_pickup_libs} = [ + sort { $U->find_org($U->get_org_tree,$a)->name cmp $U->find_org($U->get_org_tree,$b)->name } @curbside_pickup_libs + ]; } sub handle_hold_update { @@ -1405,11 +1422,6 @@ sub load_myopac_holds { } $ctx->{curbside_appointments}{$cs->org} = $cs; } - - $ctx->{curbside_pickup_libs} = []; - for my $pul (@{$holds_object->{pickup_libs}}) { - push(@{$ctx->{curbside_pickup_libs}}, $pul) if $ctx->{get_org_setting}->($pul, 'circ.curbside'); - } } $ctx->{holds_ids} = $holds_object->{all_ids}; $ctx->{holds_limit} = $limit; @@ -2228,15 +2240,6 @@ sub load_myopac_hold_history { where => {id => $e->requestor->id} }); - # This is used to detect whether we want to show the curbside tab - my $extant_holds_object = $self->fetch_user_holds(); - if($extant_holds_object->{holds}) { - $ctx->{curbside_pickup_libs} = []; - for my $pul (@{$extant_holds_object->{pickup_libs}}) { - push(@{$ctx->{curbside_pickup_libs}}, $pul) if $ctx->{get_org_setting}->($pul, 'circ.curbside'); - } - } - 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}; diff --git a/Open-ILS/src/templates/opac/parts/myopac/base.tt2 b/Open-ILS/src/templates/opac/parts/myopac/base.tt2 index c6e38e85d5..e7d20068a1 100644 --- a/Open-ILS/src/templates/opac/parts/myopac/base.tt2 +++ b/Open-ILS/src/templates/opac/parts/myopac/base.tt2 @@ -5,13 +5,15 @@ {url => "messages", name => l("Messages")}, {url => "circs", name => l("Items Checked Out")}, {url => "holds", name => l("Holds")}, - {url => "holds_curbside", name => l("Curbside Pickup")}, {url => "prefs", name => l("Account Preferences")}, {url => "lists", name => l("My Lists")} ]; IF (ctx.show_reservations_tab == 'true'); myopac_pages.push({url => "reservations", name => l("Reservations")}); END; + IF ctx.curbside_pickup_libs.size; + myopac_pages.push({url => "holds_curbside", name => l("Curbside Pickup")}); + END; skin_root = "../" %]

[% l('My Account') %]

-- 2.11.0