diff options
Diffstat (limited to 'client/src/app/core/routing')
8 files changed, 43 insertions, 16 deletions
diff --git a/client/src/app/core/routing/can-deactivate-guard.service.ts b/client/src/app/core/routing/can-deactivate-guard.service.ts new file mode 100644 index 000000000..e0405293a --- /dev/null +++ b/client/src/app/core/routing/can-deactivate-guard.service.ts | |||
@@ -0,0 +1,30 @@ | |||
1 | import { Observable } from 'rxjs' | ||
2 | import { Injectable } from '@angular/core' | ||
3 | import { CanDeactivate } from '@angular/router' | ||
4 | import { ConfirmService } from '@app/core/confirm' | ||
5 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
6 | |||
7 | export type CanComponentDeactivateResult = { text?: string, canDeactivate: Observable<boolean> | boolean } | ||
8 | |||
9 | export interface CanComponentDeactivate { | ||
10 | canDeactivate: () => CanComponentDeactivateResult | ||
11 | } | ||
12 | |||
13 | @Injectable() | ||
14 | export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> { | ||
15 | constructor ( | ||
16 | private confirmService: ConfirmService, | ||
17 | private i18n: I18n | ||
18 | ) { } | ||
19 | |||
20 | canDeactivate (component: CanComponentDeactivate) { | ||
21 | const result = component.canDeactivate() | ||
22 | const text = result.text || this.i18n('All unsaved data will be lost, are you sure you want to leave this page?') | ||
23 | |||
24 | return result.canDeactivate || this.confirmService.confirm( | ||
25 | text, | ||
26 | this.i18n('Warning') | ||
27 | ) | ||
28 | } | ||
29 | |||
30 | } | ||
diff --git a/client/src/app/core/routing/index.ts b/client/src/app/core/routing/index.ts index 58b83bb2a..239c27caf 100644 --- a/client/src/app/core/routing/index.ts +++ b/client/src/app/core/routing/index.ts | |||
@@ -1,5 +1,10 @@ | |||
1 | export * from './can-deactivate-guard.service' | ||
2 | export * from './custom-reuse-strategy' | ||
3 | export * from './disable-for-reuse-hook' | ||
1 | export * from './login-guard.service' | 4 | export * from './login-guard.service' |
2 | export * from './user-right-guard.service' | 5 | export * from './menu-guard.service' |
3 | export * from './preload-selected-modules-list' | 6 | export * from './preload-selected-modules-list' |
4 | export * from './redirect.service' | 7 | export * from './redirect.service' |
5 | export * from './menu-guard.service' | 8 | export * from './server-config-resolver.service' |
9 | export * from './unlogged-guard.service' | ||
10 | export * from './user-right-guard.service' | ||
diff --git a/client/src/app/core/routing/login-guard.service.ts b/client/src/app/core/routing/login-guard.service.ts index 7b1c37ee8..a949be14c 100644 --- a/client/src/app/core/routing/login-guard.service.ts +++ b/client/src/app/core/routing/login-guard.service.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import { Injectable } from '@angular/core' | 1 | import { Injectable } from '@angular/core' |
2 | import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router' | 2 | import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router' |
3 | |||
4 | import { AuthService } from '../auth/auth.service' | 3 | import { AuthService } from '../auth/auth.service' |
5 | 4 | ||
6 | @Injectable() | 5 | @Injectable() |
diff --git a/client/src/app/core/routing/menu-guard.service.ts b/client/src/app/core/routing/menu-guard.service.ts index 907d145fd..9df285635 100644 --- a/client/src/app/core/routing/menu-guard.service.ts +++ b/client/src/app/core/routing/menu-guard.service.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { Injectable } from '@angular/core' | 1 | import { Injectable } from '@angular/core' |
2 | import { CanActivate, CanDeactivate } from '@angular/router' | 2 | import { CanActivate, CanDeactivate } from '@angular/router' |
3 | import { MenuService } from '@app/core/menu' | 3 | import { MenuService } from '../menu' |
4 | import { ScreenService } from '@app/shared/misc/screen.service' | 4 | import { ScreenService } from '../wrappers' |
5 | 5 | ||
6 | abstract class MenuGuard implements CanActivate, CanDeactivate<any> { | 6 | abstract class MenuGuard implements CanActivate, CanDeactivate<any> { |
7 | display = true | 7 | display = true |
diff --git a/client/src/app/core/routing/preload-selected-modules-list.ts b/client/src/app/core/routing/preload-selected-modules-list.ts index 64af68225..b494a40bc 100644 --- a/client/src/app/core/routing/preload-selected-modules-list.ts +++ b/client/src/app/core/routing/preload-selected-modules-list.ts | |||
@@ -5,6 +5,7 @@ import { Injectable } from '@angular/core' | |||
5 | 5 | ||
6 | @Injectable() | 6 | @Injectable() |
7 | export class PreloadSelectedModulesList implements PreloadingStrategy { | 7 | export class PreloadSelectedModulesList implements PreloadingStrategy { |
8 | |||
8 | preload (route: Route, load: Function): Observable<any> { | 9 | preload (route: Route, load: Function): Observable<any> { |
9 | if (!route.data || !route.data.preload) return ofObservable(null) | 10 | if (!route.data || !route.data.preload) return ofObservable(null) |
10 | 11 | ||
diff --git a/client/src/app/core/routing/server-config-resolver.service.ts b/client/src/app/core/routing/server-config-resolver.service.ts index 3b7ed99bf..0ce2023a0 100644 --- a/client/src/app/core/routing/server-config-resolver.service.ts +++ b/client/src/app/core/routing/server-config-resolver.service.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { Injectable } from '@angular/core' | 1 | import { Injectable } from '@angular/core' |
2 | import { Resolve } from '@angular/router' | 2 | import { Resolve } from '@angular/router' |
3 | import { ServerService } from '@app/core/server' | 3 | import { ServerService } from '../server' |
4 | import { ServerConfig } from '@shared/models' | 4 | import { ServerConfig } from '@shared/models' |
5 | 5 | ||
6 | @Injectable() | 6 | @Injectable() |
diff --git a/client/src/app/core/routing/unlogged-guard.service.ts b/client/src/app/core/routing/unlogged-guard.service.ts index 3132a1a77..0be7911a0 100644 --- a/client/src/app/core/routing/unlogged-guard.service.ts +++ b/client/src/app/core/routing/unlogged-guard.service.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { Injectable } from '@angular/core' | 1 | import { Injectable } from '@angular/core' |
2 | import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router' | 2 | import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, RouterStateSnapshot } from '@angular/router' |
3 | import { AuthService } from '../auth/auth.service' | 3 | import { AuthService } from '../auth/auth.service' |
4 | import { RedirectService } from './redirect.service' | 4 | import { RedirectService } from './redirect.service' |
5 | 5 | ||
@@ -7,7 +7,6 @@ import { RedirectService } from './redirect.service' | |||
7 | export class UnloggedGuard implements CanActivate, CanActivateChild { | 7 | export class UnloggedGuard implements CanActivate, CanActivateChild { |
8 | 8 | ||
9 | constructor ( | 9 | constructor ( |
10 | private router: Router, | ||
11 | private auth: AuthService, | 10 | private auth: AuthService, |
12 | private redirectService: RedirectService | 11 | private redirectService: RedirectService |
13 | ) {} | 12 | ) {} |
diff --git a/client/src/app/core/routing/user-right-guard.service.ts b/client/src/app/core/routing/user-right-guard.service.ts index 50c3d8c19..a2ce772db 100644 --- a/client/src/app/core/routing/user-right-guard.service.ts +++ b/client/src/app/core/routing/user-right-guard.service.ts | |||
@@ -1,12 +1,5 @@ | |||
1 | import { Injectable } from '@angular/core' | 1 | import { Injectable } from '@angular/core' |
2 | import { | 2 | import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router' |
3 | ActivatedRouteSnapshot, | ||
4 | CanActivateChild, | ||
5 | RouterStateSnapshot, | ||
6 | CanActivate, | ||
7 | Router | ||
8 | } from '@angular/router' | ||
9 | |||
10 | import { AuthService } from '../auth/auth.service' | 3 | import { AuthService } from '../auth/auth.service' |
11 | 4 | ||
12 | @Injectable() | 5 | @Injectable() |