LP1823041: Converting new dialogs to observables
authorJane Sandberg <sandbej@linnbenton.edu>
Wed, 19 Jun 2019 17:17:40 +0000 (10:17 -0700)
committerBill Erickson <berickxx@gmail.com>
Thu, 20 Jun 2019 14:17:31 +0000 (10:17 -0400)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
15 files changed:
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts
Open-ILS/src/eg2/src/app/staff/admin/server/org-unit-type.component.ts
Open-ILS/src/eg2/src/app/staff/catalog/basket-actions.component.ts
Open-ILS/src/eg2/src/app/staff/catalog/record/conjoined.component.ts
Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.ts
Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts
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.ts
Open-ILS/src/eg2/src/app/staff/share/holdings/mark-damaged-dialog.component.ts
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.ts
Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts
Open-ILS/src/eg2/src/app/staff/share/holds/manage-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/share/holds/retarget-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/share/holds/transfer-dialog.component.ts

index e283cc2..f25839b 100644 (file)
@@ -520,14 +520,12 @@ export class FmRecordEditorComponent
         this.translator.fieldName = field;
         this.translator.idlObject = this.record;
 
-        // TODO: will need to change once LP1823041 is merged
-        this.translator.open().then(
+        this.translator.open().subscribe(
             newValue => {
                 if (newValue) {
                     this.record[field](newValue);
                 }
-            },
-            () => {} // avoid console error
+            }
         );
     }
 }
index 77d007b..0366d73 100644 (file)
@@ -91,7 +91,7 @@ export class OrgUnitTypeComponent implements OnInit {
         this.editDialog.mode = 'update';
         this.editDialog.setRecord(this.selected.callerData.aout);
 
-        this.editDialog.open().then(
+        this.editDialog.open().subscribe(
             success => {
                 this.postUpdate(this.editString);
                 this.loadAoutTree(); // since the tree is never going to
@@ -109,7 +109,7 @@ export class OrgUnitTypeComponent implements OnInit {
     }
 
     remove() {
-        this.delConfirm.open().then(
+        this.delConfirm.open().subscribe(
             ok => {
                 this.pcrud.remove(this.selected.callerData.aout)
                 .subscribe(
@@ -128,8 +128,7 @@ export class OrgUnitTypeComponent implements OnInit {
                         this.postUpdate(this.editString);
                     }
                 );
-            },
-            notConfirmed => {}
+            }
         );
     }
 
@@ -144,7 +143,7 @@ export class OrgUnitTypeComponent implements OnInit {
         this.editDialog.setRecord(newType);
         this.editDialog.mode = 'create';
 
-        this.editDialog.open().then(
+        this.editDialog.open().subscribe(
             result => { // aout object
 
                 // Add our new node to the tree
index da3f793..c42b7dd 100644 (file)
@@ -97,10 +97,7 @@ export class BasketActionsComponent implements OnInit {
                 this.basket.getRecordIds().then(ids => {
                     this.addToBucketDialog.bucketClass = 'biblio';
                     this.addToBucketDialog.itemIds = ids;
-                    this.addToBucketDialog.open({size: 'lg'}).then(
-                        ok => {},
-                        dismissed => {}
-                    );
+                    this.addToBucketDialog.open({size: 'lg'});
                 });
                 break;
 
index b4d6274..1ba570d 100644 (file)
@@ -97,13 +97,12 @@ export class ConjoinedComponent implements OnInit {
     }
 
     openConjoinedDialog() {
-        this.conjoinedDialog.open({size: 'sm'}).then(
+        this.conjoinedDialog.open({size: 'sm'}).subscribe(
             modified => {
                 if (modified) {
                     this.grid.reload();
                 }
-            },
-            notOk => {}
+            }
         );
     }
 }
index 7ffa692..a89444b 100644 (file)
@@ -609,7 +609,7 @@ export class HoldingsMaintenanceComponent implements OnInit {
             }
 
             this.markDamagedDialog.copyId = ids.pop();
-            return this.markDamagedDialog.open({size: 'lg'}).then(
+            return this.markDamagedDialog.open({size: 'lg'}).subscribe(
                 ok => {
                     if (ok) { rowsModified = true; }
                     return markNext(ids);
@@ -629,7 +629,7 @@ export class HoldingsMaintenanceComponent implements OnInit {
         const copyIds = this.selectedCopyIds(rows, 4 /* ignore missing */);
         if (copyIds.length > 0) {
             this.markMissingDialog.copyIds = copyIds;
-            this.markMissingDialog.open({}).then(
+            this.markMissingDialog.open({}).subscribe(
                 rowsModified => {
                     if (rowsModified) {
                         this.refreshHoldings = true;
@@ -762,13 +762,12 @@ export class HoldingsMaintenanceComponent implements OnInit {
 
         this.copyAlertsDialog.copyIds = copyIds;
         this.copyAlertsDialog.mode = mode;
-        this.copyAlertsDialog.open({size: 'lg'}).then(
+        this.copyAlertsDialog.open({size: 'lg'}).subscribe(
             modified => {
                 if (modified) {
                     this.hardRefresh();
                 }
-            },
-            dismissed => {}
+            }
         );
     }
 
@@ -776,13 +775,12 @@ export class HoldingsMaintenanceComponent implements OnInit {
         const ids = this.selectedCopyIds(rows);
         if (ids.length === 0) { return; }
         this.replaceBarcode.copyIds = ids;
-        this.replaceBarcode.open({}).then(
+        this.replaceBarcode.open({}).subscribe(
             modified => {
                 if (modified) {
                     this.hardRefresh();
                 }
-            },
-            dismissed => {}
+            }
         );
     }
 
@@ -835,13 +833,12 @@ export class HoldingsMaintenanceComponent implements OnInit {
         // "both" mode.
         this.deleteVolcopy.forceDeleteCopies = mode === 'both';
         this.deleteVolcopy.volumes = Object.values(volHash);
-        this.deleteVolcopy.open({size: 'sm'}).then(
+        this.deleteVolcopy.open({size: 'sm'}).subscribe(
             modified => {
                 if (modified) {
                     this.hardRefresh();
                 }
-            },
-            dismissed => {}
+            }
         );
     }
 
@@ -857,11 +854,7 @@ export class HoldingsMaintenanceComponent implements OnInit {
         if (copyIds.length > 0) {
             this.bucketDialog.bucketClass = 'copy';
             this.bucketDialog.itemIds = copyIds;
-            this.bucketDialog.open({size: 'lg'}).then(
-                // No need to reload the grid after adding items to buckets.
-                ok => {},
-                dismissed => {}
-            );
+            this.bucketDialog.open({size: 'lg'});
         }
     }
 
@@ -869,10 +862,7 @@ export class HoldingsMaintenanceComponent implements OnInit {
         const copyIds = this.selectedCopyIds(rows);
         if (copyIds.length > 0) {
             this.conjoinedDialog.copyIds = copyIds;
-            this.conjoinedDialog.open({size: 'sm'}).then(
-                ok => {}, // No grid reload required
-                dismissed => {}
-            );
+            this.conjoinedDialog.open({size: 'sm'});
         }
     }
 
@@ -887,10 +877,7 @@ export class HoldingsMaintenanceComponent implements OnInit {
         const copyIds = this.selectedCopyIds(rows);
         if (copyIds.length > 0) {
             this.makeBookableDialog.copyIds = copyIds;
-            this.makeBookableDialog.open({}).then(
-                modified => {}, // No refresh needed
-                dismissed => {}
-            );
+            this.makeBookableDialog.open({});
         }
     }
 }
index 2faf8f9..0930d5c 100644 (file)
@@ -395,7 +395,7 @@ export class AdminPageComponent implements OnInit {
         // create action does not try to modify an existing record.
         this.editDialog.recId = null;
         this.editDialog.record = null;
-        this.editDialog.open({size: this.dialogSize}).then(
+        this.editDialog.open({size: this.dialogSize}).subscribe(
             ok => {
                 this.createString.current()
                     .then(str => this.toast.success(str));
index 630126b..450fc34 100644 (file)
@@ -1,4 +1,5 @@
 import {Component, OnInit, Input, ViewChild} from '@angular/core';
+import {Observable, throwError} from 'rxjs';
 import {NetService} from '@eg/core/net.service';
 import {IdlService, IdlObject} from '@eg/core/idl.service';
 import {EventService} from '@eg/core/event.service';
@@ -73,14 +74,14 @@ export class CopyAlertsDialogComponent
      * Dialog promise resolves with true/false indicating whether
      * the mark-damanged action occured or was dismissed.
      */
-    async open(args: NgbModalOptions): Promise<boolean> {
+    open(args: NgbModalOptions): Observable<boolean> {
         this.copy = null;
         this.copies = [];
         this.newAlert = this.idl.create('aca');
         this.newAlert.create_staff(this.auth.user().id());
 
         if (this.copyIds.length === 0) {
-            return Promise.reject('copy ID required');
+            return throwError('copy ID required');
         }
 
         // In manage mode, we can only manage a single copy.
@@ -93,15 +94,18 @@ export class CopyAlertsDialogComponent
             }
         }
 
-        await this.getAlertTypes();
-        await this.getCopies();
-        if (this.mode === 'manage') {
-            await this.getCopyAlerts();
-        }
-        return super.open(args);
+        this.getAlertTypes()
+        .then(() => this.getCopies())
+        .then(() => {
+            if (this.mode === 'manage') {
+                this.getCopyAlerts()
+                .then(() => super.open(args) );
+            }
+            return super.open(args);
+        });
     }
 
-    async getAlertTypes(): Promise<any> {
+    getAlertTypes(): Promise<any> {
         if (this.alertTypes) {
             return Promise.resolve();
         }
@@ -114,7 +118,7 @@ export class CopyAlertsDialogComponent
         });
     }
 
-    async getCopies(): Promise<any> {
+    getCopies(): Promise<any> {
         return this.pcrud.search('acp', {id: this.copyIds}, {}, {atomic: true})
         .toPromise().then(copies => {
             this.copies = copies;
@@ -128,7 +132,7 @@ export class CopyAlertsDialogComponent
     // Copy alerts for the selected copies which have not been
     // acknowledged by staff and are within org unit range of
     // the alert type.
-    async getCopyAlerts(): Promise<any> {
+    getCopyAlerts(): Promise<any> {
         const copyIds = this.copies.map(c => c.id());
         const typeIds = this.alertTypes.map(a => a.id);
 
index 57c613d..dc86d9b 100644 (file)
@@ -1,4 +1,5 @@
 import {Component, OnInit, Input, ViewChild, Renderer2} from '@angular/core';
+import {Observable, throwError} from 'rxjs';
 import {IdlObject} from '@eg/core/idl.service';
 import {NetService} from '@eg/core/net.service';
 import {EventService} from '@eg/core/event.service';
@@ -57,7 +58,7 @@ export class DeleteVolcopyDialogComponent
 
     ngOnInit() {}
 
-    async open(args: NgbModalOptions): Promise<boolean> {
+    open(args: NgbModalOptions): Observable<boolean> {
         this.numVols = 0;
         this.numCopies = 0;
         this.numSucceeded = 0;
@@ -82,7 +83,7 @@ export class DeleteVolcopyDialogComponent
 
         if (this.numVols === 0 && this.numCopies === 0) {
             console.debug('Volcopy delete called with no usable data');
-            return Promise.resolve(false);
+            return throwError(false);
         }
 
         return super.open(args);
index 70d7f8f..8a1c713 100644 (file)
@@ -1,4 +1,5 @@
 import {Component, OnInit, Input, ViewChild} from '@angular/core';
+import {Observable, throwError} from 'rxjs';
 import {NetService} from '@eg/core/net.service';
 import {IdlObject} from '@eg/core/idl.service';
 import {EventService} from '@eg/core/event.service';
@@ -62,20 +63,20 @@ export class MarkDamagedDialogComponent
      * Dialog promise resolves with true/false indicating whether
      * the mark-damanged action occured or was dismissed.
      */
-    async open(args: NgbModalOptions): Promise<boolean> {
+    open(args: NgbModalOptions): Observable<boolean> {
         this.reset();
 
         if (!this.copyId) {
-            return Promise.reject('copy ID required');
+            return throwError('copy ID required');
         }
 
-        await this.getBillingTypes();
-        await this.getData();
-        return super.open(args);
+        this.getBillingTypes()
+        .then(() => { this.getData(); })
+        .then(() => super.open(args));
     }
 
     // Fetch-cache billing types
-    async getBillingTypes(): Promise<any> {
+    getBillingTypes(): Promise<any> {
         if (this.billingTypes.length > 1) {
             return Promise.resolve();
         }
@@ -89,7 +90,7 @@ export class MarkDamagedDialogComponent
         });
     }
 
-    async getData(): Promise<any> {
+    getData(): Promise<any> {
         return this.pcrud.retrieve('acp', this.copyId,
             {flesh: 1, flesh_fields: {acp: ['call_number']}}).toPromise()
         .then(copy => {
index 2cd67de..2d18eb9 100644 (file)
@@ -1,4 +1,6 @@
 import {Component, OnInit, Input, ViewChild, Renderer2} from '@angular/core';
+import {Observable, throwError} from 'rxjs';
+import {flatMap, 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';
@@ -51,24 +53,23 @@ export class ReplaceBarcodeDialogComponent
 
     ngOnInit() {}
 
-    async open(args: NgbModalOptions): Promise<boolean> {
+    open(args: NgbModalOptions): Observable<boolean> {
         this.ids = [].concat(this.copyIds);
         this.numSucceeded = 0;
         this.numFailed = 0;
 
-        await this.getNextCopy();
-        setTimeout(() =>
-            // Give the dialog a chance to render
-            this.renderer.selectRootElement('#new-barcode-input').focus()
-        );
-        return super.open(args);
+        return this.getNextCopy()
+        .pipe(flatMap(() => {
+            return super.open(args)
+            .pipe(tap(() => {this.renderer.selectRootElement('#new-barcode-input').focus(); }));
+        }));
     }
 
-    async getNextCopy(): Promise<any> {
+    getNextCopy(): Observable<any> {
 
         if (this.ids.length === 0) {
             this.close(this.numSucceeded > 0);
-            return Promise.resolve();
+            return throwError(false);
         }
 
         this.newBarcode = '';
@@ -76,7 +77,7 @@ export class ReplaceBarcodeDialogComponent
         const id = this.ids.pop();
 
         return this.pcrud.retrieve('acp', id)
-        .toPromise().then(c => this.copy = c);
+        .pipe(map(c => this.copy = c));
     }
 
     async replaceOneBarcode(): Promise<any> {
index 98af514..d9c9295 100644 (file)
@@ -1,4 +1,5 @@
 import {Component, OnInit, Input, ViewChild} from '@angular/core';
+import {Observable} from 'rxjs';
 import {NetService} from '@eg/core/net.service';
 import {EventService} from '@eg/core/event.service';
 import {ToastService} from '@eg/share/toast/toast.service';
@@ -48,7 +49,7 @@ export class HoldCancelDialogComponent
         // them to load regardless of whether the dialog is ever used.
     }
 
-    open(args: NgbModalOptions): Promise<boolean> {
+    open(args: NgbModalOptions): Observable<boolean> {
 
         if (this.cancelReasons.length === 0) {
             this.pcrud.retrieveAll('ahrcc', {}, {atomic: true}).toPromise()
index a95ed85..bdecd41 100644 (file)
@@ -297,13 +297,12 @@ export class HoldsGridComponent implements OnInit {
         const holdIds = rows.map(r => r.id).filter(id => Boolean(id));
         if (holdIds.length > 0) {
             this.manageDialog.holdIds = holdIds;
-            this.manageDialog.open({size: 'lg'}).then(
+            this.manageDialog.open({size: 'lg'}).subscribe(
                 rowsModified => {
                     if (rowsModified) {
                         this.holdsGrid.reload();
                     }
-                },
-                dismissed => {}
+                }
             );
         }
     }
@@ -312,13 +311,12 @@ export class HoldsGridComponent implements OnInit {
         const holdIds = rows.map(r => r.id).filter(id => Boolean(id));
         if (holdIds.length > 0) {
             this.transferDialog.holdIds = holdIds;
-            this.transferDialog.open({}).then(
+            this.transferDialog.open({}).subscribe(
                 rowsModified => {
                     if (rowsModified) {
                         this.holdsGrid.reload();
                     }
-                },
-                dismissed => {}
+                }
             );
         }
     }
@@ -335,7 +333,7 @@ export class HoldsGridComponent implements OnInit {
             }
 
             this.markDamagedDialog.copyId = ids.pop();
-            return this.markDamagedDialog.open({size: 'lg'}).then(
+            return this.markDamagedDialog.open({size: 'lg'}).subscribe(
                 ok => {
                     if (ok) { rowsModified = true; }
                     return markNext(ids);
@@ -354,13 +352,12 @@ export class HoldsGridComponent implements OnInit {
         const copyIds = rows.map(r => r.cp_id).filter(id => Boolean(id));
         if (copyIds.length > 0) {
             this.markMissingDialog.copyIds = copyIds;
-            this.markMissingDialog.open({}).then(
+            this.markMissingDialog.open({}).subscribe(
                 rowsModified => {
                     if (rowsModified) {
                         this.holdsGrid.reload();
                     }
-                },
-                dismissed => {} // avoid console errors
+                }
             );
         }
     }
@@ -369,13 +366,12 @@ export class HoldsGridComponent implements OnInit {
         const holdIds = rows.map(r => r.id).filter(id => Boolean(id));
         if (holdIds.length > 0) {
             this.retargetDialog.holdIds = holdIds;
-            this.retargetDialog.open({}).then(
+            this.retargetDialog.open({}).subscribe(
                 rowsModified => {
                     if (rowsModified) {
                         this.holdsGrid.reload();
                     }
-                },
-                dismissed => {}
+                }
             );
         }
     }
@@ -384,13 +380,12 @@ export class HoldsGridComponent implements OnInit {
         const holdIds = rows.map(r => r.id).filter(id => Boolean(id));
         if (holdIds.length > 0) {
             this.cancelDialog.holdIds = holdIds;
-            this.cancelDialog.open({}).then(
+            this.cancelDialog.open({}).subscribe(
                 rowsModified => {
                     if (rowsModified) {
                         this.holdsGrid.reload();
                     }
-                },
-                dismissed => {}
+                }
             );
         }
     }
index 93375c0..1b539d1 100644 (file)
@@ -1,4 +1,5 @@
 import {Component, OnInit, Input} from '@angular/core';
+import {Observable} from 'rxjs';
 import {DialogComponent} from '@eg/share/dialog/dialog.component';
 import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
 
@@ -21,7 +22,7 @@ export class HoldManageDialogComponent
         super(modal); // required for subclassing
     }
 
-    open(args: NgbModalOptions): Promise<boolean> {
+    open(args: NgbModalOptions): Observable<boolean> {
         return super.open(args);
     }
 
index feca64d..bb31a48 100644 (file)
@@ -1,4 +1,5 @@
 import {Component, OnInit, Input, ViewChild} from '@angular/core';
+import {Observable} from 'rxjs';
 import {NetService} from '@eg/core/net.service';
 import {EventService} from '@eg/core/event.service';
 import {ToastService} from '@eg/share/toast/toast.service';
@@ -39,7 +40,7 @@ export class HoldRetargetDialogComponent
 
     ngOnInit() {}
 
-    open(args: NgbModalOptions): Promise<boolean> {
+    open(args: NgbModalOptions): Observable<boolean> {
         this.holdIds = [].concat(this.holdIds); // array-ify ints
         return super.open(args);
     }
index 5ce38ea..58b8200 100644 (file)
@@ -1,4 +1,5 @@
 import {Component, OnInit, Input, ViewChild} from '@angular/core';
+import {Observable, throwError} from 'rxjs';
 import {NetService} from '@eg/core/net.service';
 import {StoreService} from '@eg/core/store.service';
 import {EventService} from '@eg/core/event.service';
@@ -44,15 +45,16 @@ export class HoldTransferDialogComponent
 
     ngOnInit() {}
 
-    async open(args: NgbModalOptions): Promise<boolean> {
+    open(args: NgbModalOptions): Observable<boolean> {
         this.holdIds = [].concat(this.holdIds); // array-ify ints
 
         this.transferTarget =
             this.store.getLocalItem('eg.circ.hold.title_transfer_target');
 
         if (!this.transferTarget) {
-            this.toast.warning(await this.targetNeeded.current());
-            return Promise.reject('Transfer Target Required');
+            this.targetNeeded.current()
+            .then((msg) => this.toast.warning(msg))
+            .then(() => throwError('Transfer Target Required'));
         }
 
         return super.open(args);