From: Bill Erickson Date: Wed, 3 Apr 2019 16:14:52 +0000 (-0400) Subject: LP1823041 Angular dialogs resolve on dismiss/cancel X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=120626a26b49e8965c60caec4b59600f7a33b96b;p=working%2FEvergreen.git LP1823041 Angular dialogs resolve on dismiss/cancel Angular dialogs now only result in a promise rejection when an unexpected error occurs. Dismissing a dialog via Esc, Cancel button, cross-click, body-click, etc. no longer result in a rejection. In these situations, the response value will be set to 'null' and a new boolean field 'dismissed' on the dialog object will be set to true. For the current code, this primarily affects confirm dialogs, which previously rejected the dialog promise when the user selected the "do not confirm" option. Additionally, this commits add typescript support for "es2018.promise" which allows us to start using Promise.finally() handlers. Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/share/dialog/dialog.component.ts b/Open-ILS/src/eg2/src/app/share/dialog/dialog.component.ts index b7531a2a20..08ee743607 100644 --- a/Open-ILS/src/eg2/src/app/share/dialog/dialog.component.ts +++ b/Open-ILS/src/eg2/src/app/share/dialog/dialog.component.ts @@ -7,13 +7,6 @@ import {NgbModal, NgbModalRef, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap * at the root of the template (see ConfirmDialogComponent). */ -export interface DialogRejectionResponse { - // Did the user simply close the dialog without performing an action. - dismissed?: boolean; - // Relays error, etc. messages from the dialog handler to the caller. - message?: string; -} - @Component({ selector: 'eg-dialog', template: '' @@ -32,6 +25,11 @@ export class DialogComponent implements OnInit { // called in the overridding method. onOpen$ = new EventEmitter(); + // null if the dialog has never been opened. + // true if the most recent instance was dismissed by the user, + // false otherwise. + dismissed: boolean = null; + // The modalRef allows direct control of the modal instance. private modalRef: NgbModalRef = null; @@ -44,10 +42,10 @@ export class DialogComponent implements OnInit { open(options?: NgbModalOptions): Promise { if (this.modalRef !== null) { - console.warn('Dismissing existing dialog'); - this.dismiss(); + this.dismiss(new Error('Dialog was replaced')); } + this.dismissed = null; this.modalRef = this.modalService.open(this.dialogContent, options); if (this.onOpen$) { @@ -58,7 +56,9 @@ export class DialogComponent implements OnInit { return new Promise( (resolve, reject) => { this.modalRef.result.then( + (result) => { + this.dismissed = false; resolve(result); this.modalRef = null; }, @@ -67,21 +67,20 @@ export class DialogComponent implements OnInit { // NgbModal creates some result values for us, which // are outside of our control. Other dismissal // reasons are agreed upon by implementing subclasses. - console.debug('dialog closed with ' + result); - - const dismissed = ( + this.dismissed = ( result === 0 // body click || result === 1 // Esc key || result === 'canceled' // Cancel button || result === 'cross_click' // modal top-right X ); - const rejection: DialogRejectionResponse = { - dismissed: dismissed, - message: result - }; + if (this.dismissed) { + resolve(null); + } else { + console.error('Dialog rejection occurred', result); + reject(result); + } - reject(rejection); this.modalRef = null; } ); diff --git a/Open-ILS/src/eg2/src/app/staff/admin/workstation/workstations/workstations.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/workstation/workstations/workstations.component.ts index a5c72e2dff..f1627237bd 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/workstation/workstations/workstations.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/workstation/workstations/workstations.component.ts @@ -121,16 +121,14 @@ export class WorkstationsComponent implements OnInit { private handleCollision(): Promise { return new Promise((resolve, reject) => { - this.wsExistsDialog.open() - .then( - confirmed => { + this.wsExistsDialog.open().then(override => { + if (override) { this.registerWorkstationApi(true).then( wsId => resolve(wsId), notOk => reject(notOk) ); - }, - dismissed => reject(dismissed) - ); + } + }); }); } diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-list.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-list.component.ts index 0afc01d6fb..208d8aaab1 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-list.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-list.component.ts @@ -41,10 +41,8 @@ export class MatchSetListComponent implements AfterViewInit { this.createNew = () => { this.editDialog.mode = 'create'; - this.editDialog.open({size: 'lg'}).then( - ok => this.grid.reload(), - err => {} - ); + this.editDialog.open({size: 'lg'}) + .then(ok => this.grid.reload()); }; this.deleteSelected = (matchSets: IdlObject[]) => { @@ -62,10 +60,8 @@ export class MatchSetListComponent implements AfterViewInit { (matchSet: IdlObject) => { this.editDialog.mode = 'update'; this.editDialog.recId = matchSet.id(); - this.editDialog.open({size: 'lg'}).then( - ok => this.grid.reload(), - err => {} - ); + this.editDialog.open({size: 'lg'}) + .then(ok => this.grid.reload()); } ); } diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.ts index fbc62ba783..89ab6c4705 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.ts @@ -218,35 +218,26 @@ export class QueueComponent implements OnInit, AfterViewInit { } deleteQueue() { - this.confirmDelDlg.open().then( - yes => { - this.progressDlg.open(); - return this.net.request( - 'open-ils.vandelay', - `open-ils.vandelay.${this.qtypeShort()}_queue.delete`, - this.auth.token(), this.queueId - ).toPromise(); - }, - no => { - this.progressDlg.close(); - return Promise.reject('delete failed'); - } - ).then( - resp => { - this.progressDlg.close(); - const e = this.evt.parse(resp); - if (e) { - console.error(e); - alert(e); - } else { + + this.confirmDelDlg.open().then(confirmed => { + if (!confirmed) { return; } + + this.progressDlg.open(); + this.net.request( + 'open-ils.vandelay', + `open-ils.vandelay.${this.qtypeShort()}_queue.delete`, + this.auth.token(), this.queueId + ).toPromise().then( + resp => { + const e = this.evt.parse(resp); + if (e) { return new Error(e.toString()); } + // Jump back to the main queue page. this.router.navigate(['/staff/cat/vandelay/queue']); - } - }, - err => { - this.progressDlg.close(); - } - ); + }, + err => console.error('queue deletion failed!', err) + ).finally(() => this.progressDlg.close()); + }); } exportNonImported() { diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/parts.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/record/parts.component.ts index 3ab8e8f8e9..2264f24e4d 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/record/parts.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/parts.component.ts @@ -81,10 +81,7 @@ export class PartsComponent implements OnInit { (part: IdlObject) => { this.editDialog.mode = 'update'; this.editDialog.recId = part.id(); - this.editDialog.open().then( - ok => this.partsGrid.reload(), - err => {} - ); + this.editDialog.open().then(ok => this.partsGrid.reload()); } ); @@ -95,10 +92,7 @@ export class PartsComponent implements OnInit { this.editDialog.record = part; this.editDialog.mode = 'create'; - this.editDialog.open().then( - ok => this.partsGrid.reload(), - err => {} - ); + this.editDialog.open().then(ok => this.partsGrid.reload()); }; this.deleteSelected = (parts: IdlObject[]) => { @@ -113,10 +107,7 @@ export class PartsComponent implements OnInit { this.mergeSelected = (parts: IdlObject[]) => { if (parts.length < 2) { return; } this.mergeDialog.parts = parts; - this.mergeDialog.open().then( - ok => this.partsGrid.reload(), - err => console.debug('Dialog dismissed') - ); + this.mergeDialog.open().then(ok => this.partsGrid.reload()); }; } } diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts index 9b058cd5b1..e109d97a2b 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts @@ -137,16 +137,13 @@ export class SandboxComponent implements OnInit { } openEditor() { - this.fmRecordEditor.open({size: 'lg'}).then( - ok => { console.debug(ok); }, - err => { - if (err && err.dismissed) { - console.debug('dialog was dismissed'); - } else { - console.error(err); - } + this.fmRecordEditor.open({size: 'lg'}).then(ok => { + if (this.fmRecordEditor.dismissed) { + console.debug('fm editor dialog dismissed'); + } else { + console.debug(ok); } - ); + }); } btGridRowClassCallback(row: any): string { diff --git a/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts b/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts index 125d3a0fd2..c934df39d0 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts @@ -180,15 +180,17 @@ export class AdminPageComponent implements OnInit { this.editDialog.record = null; this.editDialog.open({size: this.dialogSize}).then( ok => { - this.createString.current() - .then(str => this.toast.success(str)); - this.grid.reload(); + if (this.editDialog.dismissed) { + console.debug('create action was dismissed'); + } else { + this.createString.current() + .then(str => this.toast.success(str)); + this.grid.reload(); + } }, rejection => { - if (!rejection.dismissed) { - this.createErrString.current() - .then(str => this.toast.danger(str)); - } + this.createErrString.current() + .then(str => this.toast.danger(str)); } ); }; @@ -330,15 +332,17 @@ export class AdminPageComponent implements OnInit { this.editDialog.recId = idlThing[this.pkeyField](); return this.editDialog.open({size: this.dialogSize}).then( ok => { - this.successString.current() - .then(str => this.toast.success(str)); - this.grid.reload(); + if (this.editDialog.dismissed) { + console.debug('Edit dialog dismissed'); + } else { + this.successString.current() + .then(str => this.toast.success(str)); + this.grid.reload(); + } }, rejection => { - if (!rejection.dismissed) { - this.updateFailedString.current() - .then(str => this.toast.danger(str)); - } + this.updateFailedString.current() + .then(str => this.toast.danger(str)); } ); } diff --git a/Open-ILS/src/eg2/tsconfig.json b/Open-ILS/src/eg2/tsconfig.json index 14a504dc91..157d6e6722 100644 --- a/Open-ILS/src/eg2/tsconfig.json +++ b/Open-ILS/src/eg2/tsconfig.json @@ -18,7 +18,8 @@ ], "lib": [ "es2017", - "dom" + "dom", + "es2018.promise" ] } }