LP1904036 Patron UI; canceled holds
authorBill Erickson <berickxx@gmail.com>
Wed, 26 Aug 2020 14:40:48 +0000 (10:40 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:22 +0000 (20:13 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/circ/patron/holds.component.html
Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm

index 17a3671..8ada06b 100644 (file)
@@ -1,12 +1,11 @@
 
 
-<ul ngbNav #holdsNav="ngbNav" class="nav-tabs" (navChange)="beforeTabChange($event)">
+<ul ngbNav #holdsNav="ngbNav" class="nav-tabs">
 
-  <li ngbNavItem="active">
+  <li ngbNavItem>
     <a ngbNavLink i18n>Open Hold Requests</a>
     <ng-template ngbNavContent>
       <eg-holds-grid 
-        preFetchSetting="eg.circ.patron.holds.prefetch"
         printTemplate="holds_for_patron"
         persistKey="circ.patron.holds"
         [hidePickupLibFilter]="true"
     </ng-template>
   </li>
 
+  <li ngbNavItem>
+    <a ngbNavLink i18n>Recently Canceled Holds</a>
+    <ng-template ngbNavContent>
+      <eg-holds-grid 
+        printTemplate="holds_for_patron"
+        persistKey="circ.patron.holds.canceled"
+        [hidePickupLibFilter]="true"
+        [showRecentlyCanceled]="true"
+        [defaultSort]="[{name:'cancel_time',dir:'desc'}]"
+        [patronId]="context.patron.id()"></eg-holds-grid>
+    </ng-template>
+  </li>
 </ul>
 
 <ng-container *ngIf="context.patron">
index 6d70c32..3a8dee7 100644 (file)
@@ -118,18 +118,8 @@ export class HoldsGridComponent implements OnInit {
         return this._patronId;
     }
 
-    // Include holds canceled on or after the provided date.
-    // If no value is passed, canceled holds are not displayed.
-    _showCanceledSince: Date;
-    @Input() set showCanceledSince(show: Date) {
-        this._showCanceledSince = show;
-        if (this.initDone) { // reload on update
-            this.holdsGrid.reload();
-        }
-    }
-    get showCanceledSince(): Date {
-        return this._showCanceledSince;
-    }
+    // If true, show recently canceled holds only.
+    @Input() showRecentlyCanceled: boolean = false;
 
     // Include holds fulfilled on or after hte provided date.
     // If no value is passed, fulfilled holds are not displayed.
@@ -186,6 +176,8 @@ export class HoldsGridComponent implements OnInit {
             this.store.getItem(this.preFetchSetting).then(
                 applied => this.enablePreFetch = Boolean(applied)
             );
+        } else {
+            this.enablePreFetch = false;
         }
 
         if (!this.defaultSort) {
@@ -347,6 +339,7 @@ export class HoldsGridComponent implements OnInit {
 
         const limit = this.enablePreFetch ? null : pager.limit;
         const offset = this.enablePreFetch ? 0 : pager.offset;
+        const options = this.showRecentlyCanceled ? {recently_canceled: true} : {};
 
         let observer: Observer<any>;
         const observable = new Observable(obs => observer = obs);
@@ -358,7 +351,7 @@ export class HoldsGridComponent implements OnInit {
         this.net.request(
             'open-ils.circ',
             'open-ils.circ.hold.wide_hash.stream',
-            this.auth.token(), filters, orderBy, limit, offset
+            this.auth.token(), filters, orderBy, limit, offset, options
         ).subscribe(
             holdData => {
 
index a11d0ab..178278d 100644 (file)
@@ -837,35 +837,10 @@ sub retrieve_holds {
 
     if($self->api_name =~ /canceled/) {
 
-        # Fetch the canceled holds
-        # order cancelled holds by cancel time, most recent first
+        $holds_query->{order_by} = 
+            [{class => 'ahr', field => 'cancel_time', direction => 'desc'}];
 
-        $holds_query->{order_by} = [{class => 'ahr', field => 'cancel_time', direction => 'desc'}];
-
-        my $cancel_age;
-        my $cancel_count = $U->ou_ancestor_setting_value(
-                $e->requestor->ws_ou, 'circ.holds.canceled.display_count', $e);
-
-        unless($cancel_count) {
-            $cancel_age = $U->ou_ancestor_setting_value(
-                $e->requestor->ws_ou, 'circ.holds.canceled.display_age', $e);
-
-            # if no settings are defined, default to last 10 cancelled holds
-            $cancel_count = 10 unless $cancel_age;
-        }
-
-        if($cancel_count) { # limit by count
-
-            $holds_query->{where}->{cancel_time} = {'!=' => undef};
-            $holds_query->{limit} = $cancel_count;
-
-        } elsif($cancel_age) { # limit by age
-
-            # find all of the canceled holds that were canceled within the configured time frame
-            my $date = DateTime->now->subtract(seconds => OpenILS::Utils::DateTime->interval_to_seconds($cancel_age));
-            $date = $U->epoch2ISO8601($date->epoch);
-            $holds_query->{where}->{cancel_time} = {'>=' => $date};
-        }
+        recently_canceled_holds_filter($e, $holds_query);
 
     } else {
 
@@ -913,6 +888,45 @@ sub retrieve_holds {
 }
 
 
+# Creates / augments a set of query filters to search for canceled holds
+# based on circ.holds.canceled.* org settings.
+sub recently_canceled_holds_filter {
+    my ($e, $filters) = @_;
+    $filters ||= {};
+    $filters->{where} ||= {};
+
+    my $cancel_age;
+    my $cancel_count = $U->ou_ancestor_setting_value(
+            $e->requestor->ws_ou, 'circ.holds.canceled.display_count', $e);
+
+    unless($cancel_count) {
+        $cancel_age = $U->ou_ancestor_setting_value(
+            $e->requestor->ws_ou, 'circ.holds.canceled.display_age', $e);
+
+        # if no settings are defined, default to last 10 cancelled holds
+        $cancel_count = 10 unless $cancel_age;
+    }
+
+    if($cancel_count) { # limit by count
+
+        $filters->{where}->{cancel_time} = {'!=' => undef};
+        $filters->{limit} = $cancel_count;
+
+    } elsif($cancel_age) { # limit by age
+
+        # find all of the canceled holds that were canceled within the configured time frame
+        my $date = DateTime->now->subtract(seconds => 
+            OpenILS::Utils::DateTime->interval_to_seconds($cancel_age));
+
+        $date = $U->epoch2ISO8601($date->epoch);
+        $filters->{where}->{cancel_time} = {'>=' => $date};
+    }
+
+    return $filters;
+}
+
+
+
 __PACKAGE__->register_method(
     method   => 'user_hold_count',
     api_name => 'open-ils.circ.hold.user.count'
@@ -3636,12 +3650,26 @@ __PACKAGE__->register_method(
 );
 
 sub stream_wide_holds {
-    my($self, $client, $auth, $restrictions, $order_by, $limit, $offset) = @_;
+    my($self, $client, $auth, $restrictions, $order_by, $limit, $offset, $options) = @_;
+    $options ||= {};
 
     my $e = new_editor(authtoken=>$auth);
     $e->checkauth or return $e->event;
     $e->allowed('VIEW_HOLD') or return $e->event;
 
+    if ($options->{recently_canceled}) {
+        # Map the the recently canceled holds filter into values 
+        # wide-stream understands.
+        my $filter = recently_canceled_holds_filter($e);
+        $restrictions->{$_} =
+            $filter->{where}->{$_} for keys %{$filter->{where}};
+
+        $limit = $filter->{limit} if $filter->{limit};
+    }
+
+    my $filters = OpenSRF::Utils::JSON->perl2JSON($restrictions);
+    $logger->info("WIDE HOLD FILTERS: $filters");
+
     my $st = OpenSRF::AppSession->create('open-ils.storage');
     my $req = $st->request(
         'open-ils.storage.action.live_holds.wide_hash',