LP1952931 Blocking receiving before container fully loads
authorBill Erickson <berickxx@gmail.com>
Tue, 29 Mar 2022 21:17:23 +0000 (17:17 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 8 Apr 2022 15:31:40 +0000 (11:31 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/acq/asn/receive.component.html
Open-ILS/src/eg2/src/app/staff/acq/asn/receive.component.ts

index 21433a5..ccff5c5 100644 (file)
@@ -170,11 +170,18 @@ across different vendors to match a container code.
   </div>
 </div>
 
+<div *ngIf="findingContainer" class="row">
+  <div class="col-lg-6 offset-lg-3">
+    <eg-progress-inline></eg-progress-inline>
+  </div>
+</div>
+
 <eg-grid *ngIf="container && !receiving" #grid [dataSource]="gridDataSource" 
-  pageSize="50" (onRowActivate)="openLi($event)">
+  [disablePaging]="true" (onRowActivate)="openLi($event)">
 
   <eg-grid-toolbar-button i18n-label label="Receive All Items"
-    (onClick)="receiveAllItems()"></eg-grid-toolbar-button> 
+    [disabled]="loadingContainer" (onClick)="receiveAllItems()">
+  </eg-grid-toolbar-button> 
     
   <eg-grid-toolbar-checkbox i18n-label label="Dry Run" [initialValue]="true" 
     (onChange)="dryRun = !dryRun"></eg-grid-toolbar-checkbox> 
index 07cedde..ad4f2e3 100644 (file)
@@ -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<any> {
+        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<any> {
         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() {