From 713a0f1b91e5bc5fc8366b03cda07376b805e00a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 29 Mar 2022 17:17:23 -0400 Subject: [PATCH] LP1952931 Blocking receiving before container fully loads Signed-off-by: Bill Erickson --- .../src/app/staff/acq/asn/receive.component.html | 11 +++- .../eg2/src/app/staff/acq/asn/receive.component.ts | 71 +++++++++++----------- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/acq/asn/receive.component.html b/Open-ILS/src/eg2/src/app/staff/acq/asn/receive.component.html index 21433a581e..ccff5c51bd 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/asn/receive.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/asn/receive.component.html @@ -170,11 +170,18 @@ across different vendors to match a container code. +
+
+ +
+
+ + [disablePaging]="true" (onRowActivate)="openLi($event)"> + [disabled]="loadingContainer" (onClick)="receiveAllItems()"> + diff --git a/Open-ILS/src/eg2/src/app/staff/acq/asn/receive.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/asn/receive.component.ts index 07ceddeacf..ad4f2e3713 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/asn/receive.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/asn/receive.component.ts @@ -30,6 +30,8 @@ export class AsnReceiveComponent implements OnInit { dryRun = true; receiveOnScan = false; notFound = false; + findingContainer = false; + loadingContainer = false; liCache: {[id: number]: any} = {}; // Technically possible for one container code to match across providers. @@ -86,6 +88,8 @@ export class AsnReceiveComponent implements OnInit { } findContainer() { + this.findingContainer = true; + this.loadingContainer = true; this.notFound = false; this.receiving = false; this.container = null; @@ -100,14 +104,16 @@ export class AsnReceiveComponent implements OnInit { sn => this.containers.push(sn), _ => {}, () => { + this.findingContainer = false; // TODO handle multiple containers w/ same code if (this.containers.length === 1) { this.container = this.containers[0]; - this.loadContainer(); - if (this.receiveOnScan) { - this.receiveAllItems(); - } + this.loadContainer().then(_ => { + if (this.receiveOnScan) { + this.receiveAllItems(); + } + }); } else if (this.containers.length === 0) { this.notFound = true; } @@ -118,30 +124,26 @@ export class AsnReceiveComponent implements OnInit { ); } - loadContainer() { - if (!this.container) { return; } + loadContainer(): Promise { + if (!this.container) { return Promise.resolve(); } const entries = this.container.entries(); - if (entries.length === 0) { return; } - - this.li.getFleshedLineitems(entries.map(e => e.lineitem()), {}) - .subscribe( - li_struct => { - // Flesh the lineitems directly in the shipment entry - const entry = entries.filter(e => e.lineitem() === li_struct.id)[0]; - entry.lineitem(li_struct.lineitem); - }, - _ => {}, - () => { - this.entries = entries; - - if (this.grid) { - // Hidden of receiveOnScan - this.grid.reload(); - } + if (entries.length === 0) { return Promise.resolve(); } + + return this.li.getFleshedLineitems(entries.map(e => e.lineitem()), {}) + .pipe(tap(li_struct => { + // Flesh the lineitems directly in the shipment entry + const entry = entries.filter(e => e.lineitem() === li_struct.id)[0]; + entry.lineitem(li_struct.lineitem); + })).toPromise() + .then(_ => { + this.entries = entries; + this.loadingContainer = false; + if (this.grid) { // Hidden during receiveOnScan + this.grid.reload(); } - ); + }); } openLi(row: any) { @@ -168,7 +170,7 @@ export class AsnReceiveComponent implements OnInit { .reduce((pv, cv) => pv + (cv || 0)); } - receiveAllItems() { + receiveAllItems(): Promise { this.receiving = true; this.receiveResponse = { @@ -184,18 +186,13 @@ export class AsnReceiveComponent implements OnInit { let method = 'open-ils.acq.shipment_notification.receive_items'; if (this.dryRun) { method += '.dry_run'; } - this.net.request('open-ils.acq', - method, this.auth.token(), this.container.id()) - .subscribe( - resp => { - this.progress.update({value: resp.progress}); - console.debug('ASN Receive returned', resp); - this.receiveResponse = resp; - }, - err => {}, - () => { - } - ); + return this.net.request('open-ils.acq', + method, this.auth.token(), this.container.id() + ).pipe(tap(resp => { + this.progress.update({value: resp.progress}); + console.debug('ASN Receive returned', resp); + this.receiveResponse = resp; + })).toPromise(); } clearReceiving() { -- 2.11.0