LP#1879983: Restrict top-level curbside tab display
authorMike Rylander <mrylander@gmail.com>
Mon, 29 Jun 2020 20:58:37 +0000 (16:58 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 15 Sep 2020 20:21:00 +0000 (16:21 -0400)
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 <mrylander@gmail.com>
Signed-off-by: Michele Morgan <mmorgan@noblenet.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/templates/opac/parts/myopac/base.tt2

index 8479fab..907ae8b 100644 (file)
@@ -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;
 }
index b3e6672..4da79eb 100644 (file)
@@ -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};
index c6e38e8..e7d2006 100644 (file)
@@ -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 = "../"
 %]
     <h2 class="sr-only">[% l('My Account') %]</h2>