LP1823041 Observable dialogs repairs and cleanup
authorBill Erickson <berickxx@gmail.com>
Wed, 19 Jun 2019 20:25:51 +0000 (16:25 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 20 Jun 2019 14:17:31 +0000 (10:17 -0400)
Fixes a few instances where dialog.open() calls did not return
Observables.

Replace a number of calls to the now deprecated dialog.dismiss() with
calls to dialog.close().

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
15 files changed:
Open-ILS/src/eg2/src/app/staff/share/booking/make-bookable-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/holdings/conjoined-items-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/share/holdings/delete-volcopy-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/holdings/mark-damaged-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/holdings/mark-damaged-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/share/holdings/mark-missing-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/holdings/replace-barcode-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/holdings/replace-barcode-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/share/holds/cancel-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/holds/manage-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/holds/retarget-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/holds/transfer-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/holds/transfer-dialog.component.ts

index 25ad596..aa77935 100644 (file)
@@ -11,7 +11,7 @@
         <span i18n>Make Items Bookable</span>
       </h4>
       <button type="button" class="close" 
-        i18n-aria-label aria-label="Close" (click)="dismiss('cross_click')">
+        i18n-aria-label aria-label="Close" (click)="close()">
         <span aria-hidden="true">&times;</span>
       </button>
     </div>
@@ -36,7 +36,7 @@
     <div class="modal-footer">
       <ng-container>
         <button type="button" class="btn btn-warning" 
-          (click)="dismiss('canceled')" i18n>Cancel</button>
+          (click)="close()" i18n>Cancel</button>
         <ng-container *ngIf="!updateComplete">
           <button type="button" class="btn btn-success" 
             (click)="makeBookable()" i18n>Make Bookable</button>
index 9801c3e..33b433f 100644 (file)
@@ -11,7 +11,7 @@
         <span i18n>Attach/Modify {{copyIds.length}} Conjoined Item(s)</span>
       </h4>
       <button type="button" class="close" 
-        i18n-aria-label aria-label="Close" (click)="dismiss('cross_click')">
+        i18n-aria-label aria-label="Close" (click)="close()">
         <span aria-hidden="true">&times;</span>
       </button>
     </div>
@@ -31,7 +31,7 @@
     <div class="modal-footer">
       <ng-container>
         <button type="button" class="btn btn-warning" 
-          (click)="dismiss('canceled')" i18n>Cancel</button>
+          (click)="close()" i18n>Cancel</button>
         <button type="button" class="btn btn-success" 
           (click)="linkCopies()" [disabled]="!peerType" i18n>
           Attach/Modify
@@ -39,4 +39,4 @@
       </ng-container>
     </div>
   </ng-template>
-  
\ No newline at end of file
+  
index 4b3c1ca..039d776 100644 (file)
@@ -13,7 +13,7 @@
       <span i18n></span>
     </h4>
     <button type="button" class="close" 
-      i18n-aria-label aria-label="Close" (click)="dismiss('cross_click')">
+      i18n-aria-label aria-label="Close" (click)="close()">
       <span aria-hidden="true">&times;</span>
     </button>
   </div>
   </div>
   <div class="modal-footer">
     <button type="button" class="btn btn-secondary" 
-      (click)="dismiss('canceled')" i18n>Close</button>
+      (click)="close()" i18n>Close</button>
     <ng-container *ngIf="mode == 'manage'">
       <button class="btn btn-success mr-2" 
         (click)="applyChanges()" i18n>Apply Changes</button>
index 450fc34..6d96a91 100644 (file)
@@ -1,5 +1,6 @@
 import {Component, OnInit, Input, ViewChild} from '@angular/core';
-import {Observable, throwError} from 'rxjs';
+import {Observable, throwError, from} from 'rxjs';
+import {switchMap} from 'rxjs/operators';
 import {NetService} from '@eg/core/net.service';
 import {IdlService, IdlObject} from '@eg/core/idl.service';
 import {EventService} from '@eg/core/event.service';
@@ -94,15 +95,15 @@ export class CopyAlertsDialogComponent
             }
         }
 
-        this.getAlertTypes()
-        .then(() => this.getCopies())
-        .then(() => {
-            if (this.mode === 'manage') {
-                this.getCopyAlerts()
-                .then(() => super.open(args) );
-            }
-            return super.open(args);
-        });
+        // Observerify data loading
+        const obs = from(
+            this.getAlertTypes()
+            .then(_ => this.getCopies())
+            .then(_ => this.mode === 'manage' ? this.getCopyAlerts() : null)
+        );
+
+        // Return open() observable to caller
+        return obs.pipe(switchMap(_ => super.open(args)));
     }
 
     getAlertTypes(): Promise<any> {
index 9a07de7..30b0f2c 100644 (file)
@@ -12,7 +12,7 @@
         <span i18n>Delete Holdings</span>
       </h4>
       <button type="button" class="close" 
-        i18n-aria-label aria-label="Close" (click)="dismiss('cross_click')">
+        i18n-aria-label aria-label="Close" (click)="close()">
         <span aria-hidden="true">&times;</span>
       </button>
     </div>
@@ -22,7 +22,7 @@
     <div class="modal-footer">
       <ng-container>
         <button type="button" class="btn btn-warning" 
-          (click)="dismiss('canceled')" i18n>Cancel</button>
+          (click)="close()" i18n>Cancel</button>
         <button type="button" class="btn btn-success" 
           (click)="deleteHoldings()" i18n>
           Delete Holdings
@@ -30,4 +30,4 @@
       </ng-container>
     </div>
   </ng-template>
-  
\ No newline at end of file
+  
index ddcf6b1..0c53c9c 100644 (file)
@@ -7,7 +7,7 @@
       <span i18n>Mark Item Damaged</span>
     </h4>
     <button type="button" class="close" 
-      i18n-aria-label aria-label="Close" (click)="dismiss('cross_click')">
+      i18n-aria-label aria-label="Close" (click)="close(false)">
       <span aria-hidden="true">&times;</span>
     </button>
   </div>
   <div class="modal-footer">
     <ng-container *ngIf="!chargeResponse">
       <button type="button" class="btn btn-warning" 
-        (click)="dismiss('canceled')" i18n>Cancel</button>
+        (click)="close(false)" i18n>Cancel</button>
       <button type="button" class="btn btn-success" 
         (click)="markDamaged()" i18n>Mark Damaged</button>
     </ng-container>
     <ng-container *ngIf="chargeResponse">
       <button type="button" class="btn btn-warning" 
-        (click)="dismiss('canceled')" i18n>Cancel</button>
+        (click)="close(false)" i18n>Cancel</button>
       <button class="btn btn-info mr-2" 
         (click)="amountChangeRequested = true" i18n>Change Amount</button>
       <button class="btn btn-secondary mr-2" 
index 8a1c713..346b3f0 100644 (file)
@@ -1,5 +1,6 @@
 import {Component, OnInit, Input, ViewChild} from '@angular/core';
-import {Observable, throwError} from 'rxjs';
+import {Observable, throwError, from} from 'rxjs';
+import {switchMap} from 'rxjs/operators';
 import {NetService} from '@eg/core/net.service';
 import {IdlObject} from '@eg/core/idl.service';
 import {EventService} from '@eg/core/event.service';
@@ -70,9 +71,13 @@ export class MarkDamagedDialogComponent
             return throwError('copy ID required');
         }
 
-        this.getBillingTypes()
-        .then(() => { this.getData(); })
-        .then(() => super.open(args));
+        // Map data-loading promises to an observable
+        const obs = from(
+            this.getBillingTypes().then(_ => this.getData()));
+
+        // Fire data loading observable and replace results with
+        // dialog opener observable.
+        return obs.pipe(switchMap(_ => super.open(args)));
     }
 
     // Fetch-cache billing types
index 5e85a86..ea6b7d7 100644 (file)
@@ -11,7 +11,7 @@
         <span i18n>Mark Item Missing</span>
       </h4>
       <button type="button" class="close" 
-        i18n-aria-label aria-label="Close" (click)="dismiss('cross_click')">
+        i18n-aria-label aria-label="Close" (click)="close()">
         <span aria-hidden="true">&times;</span>
       </button>
     </div>
     <div class="modal-footer">
       <ng-container *ngIf="!chargeResponse">
         <button type="button" class="btn btn-warning" 
-          (click)="dismiss('canceled')" i18n>Cancel</button>
+          (click)="close()" i18n>Cancel</button>
         <button type="button" class="btn btn-success" 
           (click)="markItemsMissing()" i18n>Mark Missing</button>
       </ng-container>
     </div>
   </ng-template>
-  
\ No newline at end of file
+  
index 562681b..8bca301 100644 (file)
@@ -11,7 +11,7 @@
         <span i18n>Replace Item Barcode</span>
       </h4>
       <button type="button" class="close" 
-        i18n-aria-label aria-label="Close" (click)="dismiss('cross_click')">
+        i18n-aria-label aria-label="Close" (click)="close()">
         <span aria-hidden="true">&times;</span>
       </button>
     </div>
@@ -39,7 +39,7 @@
     <div class="modal-footer">
       <ng-container>
         <button type="button" class="btn btn-warning" 
-          (click)="dismiss('canceled')" i18n>Cancel</button>
+          (click)="close()" i18n>Cancel</button>
         <button type="button" class="btn btn-success" 
           (click)="replaceOneBarcode()" [disabled]="!newBarcode" i18n>
           Replace Barcode
@@ -47,4 +47,4 @@
       </ng-container>
     </div>
   </ng-template>
-  
\ No newline at end of file
+  
index 2d18eb9..2b85d38 100644 (file)
@@ -1,6 +1,6 @@
 import {Component, OnInit, Input, ViewChild, Renderer2} from '@angular/core';
 import {Observable, throwError} from 'rxjs';
-import {flatMap, map, tap} from 'rxjs/operators';
+import {switchMap, map, tap} from 'rxjs/operators';
 import {IdlObject} from '@eg/core/idl.service';
 import {NetService} from '@eg/core/net.service';
 import {EventService} from '@eg/core/event.service';
@@ -59,10 +59,10 @@ export class ReplaceBarcodeDialogComponent
         this.numFailed = 0;
 
         return this.getNextCopy()
-        .pipe(flatMap(() => {
-            return super.open(args)
-            .pipe(tap(() => {this.renderer.selectRootElement('#new-barcode-input').focus(); }));
-        }));
+        .pipe(switchMap(() => super.open(args)))
+        .pipe(tap(() =>
+            this.renderer.selectRootElement('#new-barcode-input').focus())
+        );
     }
 
     getNextCopy(): Observable<any> {
index d7417fa..a2d70cd 100644 (file)
@@ -9,7 +9,7 @@
         <span i18n>Cancel Hold</span>
       </h4>
       <button type="button" class="close"
-        i18n-aria-label aria-label="Close" (click)="dismiss('cross_click')">
+        i18n-aria-label aria-label="Close" (click)="close()">
         <span aria-hidden="true">&times;</span>
       </button>
     </div>
@@ -52,9 +52,9 @@
     <div class="modal-footer">
       <ng-container *ngIf="!chargeResponse">
         <button type="button" class="btn btn-warning"
-          (click)="dismiss('canceled')" i18n>Cancel</button>
+          (click)="close()" i18n>Cancel</button>
         <button type="button" class="btn btn-success"
           (click)="cancelBatch()" i18n>Cancel Hold</button>
       </ng-container>
     </div>
-  </ng-template>
\ No newline at end of file
+  </ng-template>
index ac07dd6..1a8cbc3 100644 (file)
@@ -7,7 +7,7 @@
         <h4 class="modal-title">Batch Modify {{holdIds.length}} Holds</h4>
       </ng-container>
       <button type="button" class="close"
-        i18n-aria-label aria-label="Close" (click)="dismiss('cross_click')">
+        i18n-aria-label aria-label="Close" (click)="close()">
         <span aria-hidden="true">&times;</span>
       </button>
     </div>
@@ -15,4 +15,4 @@
       <eg-hold-manage [holdIds]="holdIds" (onComplete)="onComplete($event)">
       </eg-hold-manage>
     </div>
-  </ng-template>
\ No newline at end of file
+  </ng-template>
index 37d349d..b24a63e 100644 (file)
@@ -9,7 +9,7 @@
         <span i18n>Retarget Hold</span>
       </h4>
       <button type="button" class="close"
-        i18n-aria-label aria-label="Close" (click)="dismiss('cross_click')">
+        i18n-aria-label aria-label="Close" (click)="close()">
         <span aria-hidden="true">&times;</span>
       </button>
     </div>
@@ -33,9 +33,9 @@
     <div class="modal-footer">
       <ng-container *ngIf="!chargeResponse">
         <button type="button" class="btn btn-warning"
-          (click)="dismiss('canceled')" i18n>Cancel</button>
+          (click)="close()" i18n>Cancel</button>
         <button type="button" class="btn btn-success"
           (click)="retargetBatch()" i18n>Retarget</button>
       </ng-container>
     </div>
-  </ng-template>
\ No newline at end of file
+  </ng-template>
index 80728ca..9046836 100644 (file)
@@ -11,7 +11,7 @@
         <span i18n>Transfer Hold(s) To Marked Target</span>
       </h4>
       <button type="button" class="close"
-        i18n-aria-label aria-label="Close" (click)="dismiss('cross_click')">
+        i18n-aria-label aria-label="Close" (click)="close()">
         <span aria-hidden="true">&times;</span>
       </button>
     </div>
@@ -35,9 +35,9 @@
     <div class="modal-footer">
       <ng-container *ngIf="!chargeResponse">
         <button type="button" class="btn btn-warning"
-          (click)="dismiss('canceled')" i18n>Cancel</button>
+          (click)="close()" i18n>Cancel</button>
         <button type="button" class="btn btn-success"
           (click)="transferBatch()" i18n>Transfer</button>
       </ng-container>
     </div>
-  </ng-template>
\ No newline at end of file
+  </ng-template>
index 58b8200..796aa10 100644 (file)
@@ -53,8 +53,9 @@ export class HoldTransferDialogComponent
 
         if (!this.transferTarget) {
             this.targetNeeded.current()
-            .then((msg) => this.toast.warning(msg))
-            .then(() => throwError('Transfer Target Required'));
+            .then((msg) => this.toast.warning(msg));
+
+            return throwError('Transfer Target Required');
         }
 
         return super.open(args);