From 3ca0579b405503cf953d31415dda4aefb6a5d0a1 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 30 Sep 2020 11:18:00 -0400 Subject: [PATCH] LP1889128 Reset hold recipient info after success * When all holds for a given recipient have been successfully placed, directly or via override, clear the recipient data so new recipient data can easily be added. * When placing duplicate Part holds, ensure the same part is applied to each hold context so the selected part is targeted for all of the multi-holds. * Fxes a regression in the display of multiple hold targets where only the first target would display. Signed-off-by: Bill Erickson Signed-off-by: Michele Morgan Signed-off-by: Jane Sandberg --- .../staff/catalog/hold/hold.component.html | 3 +- .../app/staff/catalog/hold/hold.component.ts | 67 +++++++++++++++---- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html index aeb1a7c166..3c47fbb9a1 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html @@ -282,7 +282,8 @@
{{ctx.holdMeta.bibSummary.display.author}}
- diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts index c079a1678c..89bb3da1e4 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts @@ -26,6 +26,7 @@ class HoldContext { canOverride?: boolean; processing: boolean; selectedFormats: any; + success = false; constructor(target: number) { this.holdTarget = target; @@ -203,13 +204,20 @@ export class HoldComponent implements OnInit { // Load the bib, call number, copy, etc. data associated with each target. getTargetMeta(): Promise { - return this.holds.getHoldTargetMeta(this.holdType, this.holdTargets) - .toPromise().then(meta => { - this.holdContexts.filter(ctx => ctx.holdTarget === meta.target) - .forEach(ctx => { - ctx.holdMeta = meta; - this.mrFiltersToSelectors(ctx); - }); + + return new Promise(resolve => { + this.holds.getHoldTargetMeta(this.holdType, this.holdTargets) + .subscribe( + meta => { + this.holdContexts.filter(ctx => ctx.holdTarget === meta.target) + .forEach(ctx => { + ctx.holdMeta = meta; + this.mrFiltersToSelectors(ctx); + }); + }, + err => {}, + () => resolve() + ); }); } @@ -303,7 +311,7 @@ export class HoldComponent implements OnInit { userBarcodeChanged() { const newBc = this.userBarcode; - if (!newBc) { this.user = null; return; } + if (!newBc) { this.resetRecipient(); return; } // Avoid simultaneous or duplicate lookups if (newBc === this.currentUserBarcode) { return; } @@ -314,13 +322,13 @@ export class HoldComponent implements OnInit { this.staffCat.clearHoldPatron(); } - this.currentUserBarcode = this.userBarcode; this.getUser(); } getUser(id?: number): Promise { let promise = this.resetForm(true); + this.currentUserBarcode = this.userBarcode; const flesh = {flesh: 1, flesh_fields: {au: ['settings']}}; @@ -346,17 +354,23 @@ export class HoldComponent implements OnInit { }); } - resetForm(keepBarcode?: boolean): Promise { + resetRecipient(keepBarcode?: boolean) { this.user = null; this.notifyEmail = true; this.notifyPhone = true; this.phoneValue = ''; this.pickupLib = this.requestor.ws_ou(); - this.placeHoldsClicked = false; + this.currentUserBarcode = null; + this.multiHoldCount = 1; // Avoid clearing the barcode in cases where the form is // reset as the result of a barcode change. if (!keepBarcode) { this.userBarcode = null; } + } + + resetForm(keepBarcode?: boolean): Promise { + this.placeHoldsClicked = false; + this.resetRecipient(keepBarcode); this.holdContexts = this.holdTargets.map(target => { const ctx = new HoldContext(target); @@ -423,8 +437,7 @@ export class HoldComponent implements OnInit { } if (!this.holdContexts[idx]) { - this.placeHoldsClicked = false; - return; + return this.afterPlaceHolds(idx > 0); } this.placeHoldsClicked = true; @@ -433,6 +446,21 @@ export class HoldComponent implements OnInit { this.placeOneHold(ctx).then(() => this.placeHolds(idx + 1)); } + afterPlaceHolds(somePlaced: boolean) { + this.placeHoldsClicked = false; + + if (!somePlaced) { return; } + + // At least one hold attempted. Confirm all succeeded + // before resetting the recipient info in the form. + let reset = true; + this.holdContexts.forEach(ctx => { + if (!ctx.success) { reset = false; } + }); + + if (reset) { this.resetRecipient(); } + } + // When placing holds on multiple copies per target, add a hold // context for each instance of the request. addMultHoldContexts() { @@ -490,7 +518,18 @@ export class HoldComponent implements OnInit { ctx.lastRequest = request; ctx.processing = false; - if (!request.result.success) { + if (request.result.success) { + ctx.success = true; + + // 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); // If this request failed and was not already an override, -- 2.43.2