diff options
author | ShaabanEltanany <shaaban.eltanany.ext@orange.com> | 2020-09-13 14:16:23 +0200 |
---|---|---|
committer | ShaabanEltanany <shaaban.eltanany.ext@orange.com> | 2020-09-13 14:16:23 +0200 |
commit | 3ccdf7e6e266578b98063e898b4acca0f1d15eda (patch) | |
tree | 0e0d562eea0b7d96990ca6e1c9b704dcd670a901 /cds-ui/designer-client/src/app/common | |
parent | 8de37f9d3035b4a41e696b967f2222806c250925 (diff) |
keeping package changes safe
give user chance to discard changes or save changes
Issue-ID: CCSDK-2336
Signed-off-by: ShaabanEltanany <shaaban.eltanany.ext@orange.com>
Change-Id: If1e1c94ef65822428f25cca071103c9022add144
Diffstat (limited to 'cds-ui/designer-client/src/app/common')
-rw-r--r-- | cds-ui/designer-client/src/app/common/core/canDactivate/ComponentCanDeactivate.ts | 14 | ||||
-rw-r--r-- | cds-ui/designer-client/src/app/common/core/canDactivate/ComponentCanDeactivateGuard.ts | 19 |
2 files changed, 33 insertions, 0 deletions
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<ComponentCanDeactivate> { + 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; + } +} |