LP#1954681 Individual overrides when placing multiple holds
authorDan Briem <dbriem@wlsmail.org>
Fri, 18 Feb 2022 22:25:26 +0000 (17:25 -0500)
committerMichele Morgan <mmorgan@noblenet.org>
Mon, 31 Oct 2022 17:14:58 +0000 (13:14 -0400)
This adds an override all button above the override column if
there are multiple overridable holds (Angular Staff Catalog).

To test:
1. Ensure staff has permission to CREATE_DUPLICATE_HOLDS
   and HOLD_ITEM_CHECKED_OUT.override
2. Set org setting for Maximum number of duplicate holds allowed
   to a value greater than 1
3. Check out an item to a patron
4. Try to place a hold on that item with Number of copies set
   to a value greater than 1
5. Test that the Override All button appears and works

Signed-off-by: Dan Briem <dbriem@wlsmail.org>
Signed-off-by: Terran McCanna <tmccanna@georgialibraries.org>
Signed-off-by: Michele Morgan <mmorgan@noblenet.org>

Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html
Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts

index b374fbf..c9f72da 100644 (file)
     <div class="col-lg-2" i18n>Holds Status</div>
     <div class="col-lg-1" i18n>Override</div>
   </div>
+  <div class="row mt-1 ml-1 mr-1" *ngIf="showOverrideAll()">
+    <div class="col-lg-12">
+      <div class="row">
+        <div class="col-lg-1 ml-auto">
+          <button class="btn btn-info" i18n
+            (click)="overrideAll()">
+            Override All
+          </button>
+        </div>
+      </div>
+    </div>
+  </div>
   <div class="row mt-1 ml-1 mr-1" *ngFor="let ctx of holdContexts">
     <div class="col-lg-12" *ngIf="ctx.holdMeta">
       <div class="row">
index 9c72ae6..a74bc37 100644 (file)
@@ -546,10 +546,10 @@ export class HoldComponent implements OnInit {
     }
 
     // Attempt hold placement on all targets
-    placeHolds(idx?: number) {
+    placeHolds(idx?: number, override?: boolean) {
         if (!idx) {
             idx = 0;
-            if (this.multiHoldCount > 1) {
+            if (this.multiHoldCount > 1 && !override) {
                 this.addMultHoldContexts();
             }
         }
@@ -561,7 +561,9 @@ export class HoldComponent implements OnInit {
         this.placeHoldsClicked = true;
 
         const ctx = this.holdContexts[idx];
-        this.placeOneHold(ctx).then(() => this.placeHolds(idx + 1));
+        this.placeOneHold(ctx, override).then(() =>
+            this.placeHolds(idx + 1, override)
+        );
     }
 
     afterPlaceHolds(somePlaced: boolean) {
@@ -601,6 +603,10 @@ export class HoldComponent implements OnInit {
 
     placeOneHold(ctx: HoldContext, override?: boolean): Promise<any> {
 
+        if (override && !this.canOverride(ctx)) {
+            return Promise.resolve();
+        }
+
         ctx.processing = true;
         const selectedFormats = this.mrSelectorsToFilters(ctx);
 
@@ -646,14 +652,6 @@ export class HoldComponent implements OnInit {
                         user: this.user.family_name()
                     });
 
-                    // Overrides are processed one hold at a time, so
-                    // we have to invoke the post-holds logic here
-                    // instead of the batch placeHolds() method.  If
-                    // there is ever a batch override option, this
-                    // logic will have to be adjusted avoid callling
-                    // afterPlaceHolds in batch mode.
-                    if (override) { this.afterPlaceHolds(true); }
-
                 } else {
                     console.debug('hold failed with: ', request);
 
@@ -677,7 +675,9 @@ export class HoldComponent implements OnInit {
     }
 
     override(ctx: HoldContext) {
-        this.placeOneHold(ctx, true);
+        this.placeOneHold(ctx, true).then(() => {
+            this.afterPlaceHolds(ctx.success);
+        });
     }
 
     canOverride(ctx: HoldContext): boolean {
@@ -685,6 +685,16 @@ export class HoldComponent implements OnInit {
                 !ctx.lastRequest.result.success && ctx.canOverride;
     }
 
+    showOverrideAll(): boolean {
+        return this.holdContexts.filter(ctx =>
+            this.canOverride(ctx)
+        ).length > 1;
+    }
+
+    overrideAll(): void {
+        this.placeHolds(0, true);
+    }
+
     iconFormatLabel(code: string): string {
         return this.cat.iconFormatLabel(code);
     }