aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/can-deactivate-guard.service.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/client/src/app/shared/can-deactivate-guard.service.ts b/client/src/app/shared/can-deactivate-guard.service.ts
new file mode 100644
index 000000000..4239df737
--- /dev/null
+++ b/client/src/app/shared/can-deactivate-guard.service.ts
@@ -0,0 +1,25 @@
1import { Injectable } from '@angular/core'
2import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'
3import { Observable } from 'rxjs/Observable'
4import { ConfirmService } from '../core'
5
6export interface CanComponentDeactivate {
7 canDeactivate: () => Observable<boolean> | boolean
8}
9
10@Injectable()
11export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
12 constructor (private confirmService: ConfirmService) { }
13
14 canDeactivate (component: CanComponentDeactivate,
15 currentRoute: ActivatedRouteSnapshot,
16 currentState: RouterStateSnapshot,
17 nextState: RouterStateSnapshot
18 ): Observable<boolean> | boolean {
19 return component.canDeactivate() || this.confirmService.confirm(
20 'All unsaved data will be lost, are you sure you want to leave ?',
21 'Unsaved Data'
22 )
23 }
24
25}