From 3ccdf7e6e266578b98063e898b4acca0f1d15eda Mon Sep 17 00:00:00 2001 From: ShaabanEltanany Date: Sun, 13 Sep 2020 14:16:23 +0200 Subject: keeping package changes safe give user chance to discard changes or save changes Issue-ID: CCSDK-2336 Signed-off-by: ShaabanEltanany Change-Id: If1e1c94ef65822428f25cca071103c9022add144 --- .../core/canDactivate/ComponentCanDeactivate.ts | 14 +++ .../canDactivate/ComponentCanDeactivateGuard.ts | 19 ++++ .../configuration-dashboard.component.html | 104 ++++++++++----------- .../configuration-dashboard.component.ts | 9 +- .../package-creation/package-creation.component.ts | 10 +- .../feature-modules/packages/packages.module.ts | 68 +++++++------- .../packages/packages.routing.module.ts | 9 +- 7 files changed, 142 insertions(+), 91 deletions(-) create mode 100644 cds-ui/designer-client/src/app/common/core/canDactivate/ComponentCanDeactivate.ts create mode 100644 cds-ui/designer-client/src/app/common/core/canDactivate/ComponentCanDeactivateGuard.ts (limited to 'cds-ui/designer-client/src') diff --git a/cds-ui/designer-client/src/app/common/core/canDactivate/ComponentCanDeactivate.ts b/cds-ui/designer-client/src/app/common/core/canDactivate/ComponentCanDeactivate.ts new file mode 100644 index 000000000..e0dac0dc3 --- /dev/null +++ b/cds-ui/designer-client/src/app/common/core/canDactivate/ComponentCanDeactivate.ts @@ -0,0 +1,14 @@ +import {HostListener} from '@angular/core'; + +export abstract class ComponentCanDeactivate { + + abstract canDeactivate(): boolean; + + + @HostListener('window:beforeunload', ['$event']) + unloadNotification($event: any) { + if (!this.canDeactivate()) { + $event.returnValue = true; + } + } +} diff --git a/cds-ui/designer-client/src/app/common/core/canDactivate/ComponentCanDeactivateGuard.ts b/cds-ui/designer-client/src/app/common/core/canDactivate/ComponentCanDeactivateGuard.ts new file mode 100644 index 000000000..b24784262 --- /dev/null +++ b/cds-ui/designer-client/src/app/common/core/canDactivate/ComponentCanDeactivateGuard.ts @@ -0,0 +1,19 @@ +import {Injectable} from '@angular/core'; + +import {CanDeactivate} from '@angular/router'; +import {ComponentCanDeactivate} from './ComponentCanDeactivate'; + +@Injectable() +export class ComponentCanDeactivateGuard implements CanDeactivate { + canDeactivate(component: ComponentCanDeactivate): boolean { + + if (component.canDeactivate()) { + if (confirm('You have unsaved changes! If you leave, your changes will be lost.')) { + return true; + } else { + return false; + } + } + return true; + } +} diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.html b/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.html index 0ffd9cb5e..2b6ba4c63 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.html +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.html @@ -13,60 +13,60 @@
-
+ @@ -757,7 +757,7 @@