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 --- cds-ui/designer-client/package.json | 2 +- .../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 +- 8 files changed, 143 insertions(+), 92 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') diff --git a/cds-ui/designer-client/package.json b/cds-ui/designer-client/package.json index 517b2dab1..df6b02b4a 100644 --- a/cds-ui/designer-client/package.json +++ b/cds-ui/designer-client/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "scripts": { "ng": "ng", - "start": "npm run lint && ng build --prod --aot && ng serve --proxy-config proxy.conf.json", + "start": "npm run lint && ng serve --proxy-config proxy.conf.json && ng build --prod --aot ", "build": "npm run lint && ng build --prod --aot ", "test": "ng test", "lint": "ng lint", 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 @@