From: Bill Erickson Date: Wed, 16 Dec 2020 16:03:54 +0000 (-0800) Subject: LP1888723 Detect unapplied changes; improve tab change X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e123a526ee68b78328c713e9ef6ec0a53adb6111;p=evergreen%2Fpines.git LP1888723 Detect unapplied changes; improve tab change 1. Detect when a change was initiated for one of the copy attributes, but not applied during change detection for warning alerts. 2. Improve handling of inter-tab navigation for change alerts. Signed-off-by: Bill Erickson Signed-off-by: Ruth Frasur Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts index ed49aae61d..1967a77445 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts @@ -645,6 +645,12 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit { this.canSaveChange.emit(canSave); }); } + + // True if one of our batch editors has been put into edit + // mode and left there without an Apply, Cancel, or Clear + hasActiveInput(): boolean { + return this.batchAttrs.filter(attr => attr.editing).length > 0; + } } diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.html b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.html index fc6fcd12cf..2f4ac1f002 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.html +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.html @@ -28,7 +28,7 @@
-
@@ -39,7 +39,7 @@ Item Attributes
-
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts index 0d8b797e40..6d09b11d3a 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts @@ -15,6 +15,7 @@ import {AnonCacheService} from '@eg/share/util/anon-cache.service'; import {VolCopyService} from './volcopy.service'; import {NgbNav, NgbNavChangeEvent} from '@ng-bootstrap/ng-bootstrap'; import {BroadcastService} from '@eg/share/util/broadcast.service'; +import {CopyAttrsComponent} from './copy-attrs.component'; const COPY_FLESH = { flesh: 1, @@ -62,10 +63,13 @@ export class VolCopyComponent implements OnInit { volsCanSave = true; attrsCanSave = true; changesPending = false; + routingAllowed = false; @ViewChild('pendingChangesDialog', {static: false}) pendingChangesDialog: ConfirmDialogComponent; + @ViewChild('copyAttrs', {static: false}) copyAttrs: CopyAttrsComponent; + constructor( private router: Router, private route: ActivatedRoute, @@ -174,8 +178,19 @@ export class VolCopyComponent implements OnInit { // Changing the route ultimately results in changing the tab. beforeTabChange(evt: NgbNavChangeEvent) { evt.preventDefault(); - this.tab = evt.nextId; - this.routeToTab(); + + let promise = this.canDeactivate(); + if (!(promise instanceof Promise)) { + promise = Promise.resolve(promise); + } + + promise.then(ok => { + if (ok) { + this.routingAllowed = true; + this.tab = evt.nextId; + this.routeToTab(); + } + }); } routeToTab() { @@ -515,13 +530,24 @@ export class VolCopyComponent implements OnInit { } @HostListener('window:beforeunload', ['$event']) - canDeactivate($event?: Event): Promise { + canDeactivate($event?: Event): boolean | Promise { + + if (this.routingAllowed) { + // We call canDeactive manually when routing between volcopy + // tabs. If routingAllowed, it means we'ave already confirmed + // the tag change is OK. + this.routingAllowed = false; + return true; + } + + const editing = this.copyAttrs ? this.copyAttrs.hasActiveInput() : false; - if (!this.changesPending) { return Promise.resolve(true); } + if (!editing && !this.changesPending) { return true; } // Each warning dialog clears the current "changes are pending" // flag so the user is not presented with the dialog again - // unless new changes are made. + // unless new changes are made. The 'editing' value will reset + // since the attrs component is getting destroyed. this.changesPending = false; if ($event) { // window.onbeforeunload