From f6a043df74bc755de8e658ba76a4e55980b96f66 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 25 Jan 2018 19:01:13 +0100 Subject: Improve video upload guard a little bit --- .../src/app/shared/can-deactivate-guard.service.ts | 25 ------------------- .../shared/guards/can-deactivate-guard.service.ts | 28 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 25 deletions(-) delete mode 100644 client/src/app/shared/can-deactivate-guard.service.ts create mode 100644 client/src/app/shared/guards/can-deactivate-guard.service.ts (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/can-deactivate-guard.service.ts b/client/src/app/shared/can-deactivate-guard.service.ts deleted file mode 100644 index 4239df737..000000000 --- a/client/src/app/shared/can-deactivate-guard.service.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Injectable } from '@angular/core' -import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router' -import { Observable } from 'rxjs/Observable' -import { ConfirmService } from '../core' - -export interface CanComponentDeactivate { - canDeactivate: () => Observable | boolean -} - -@Injectable() -export class CanDeactivateGuard implements CanDeactivate { - constructor (private confirmService: ConfirmService) { } - - canDeactivate (component: CanComponentDeactivate, - currentRoute: ActivatedRouteSnapshot, - currentState: RouterStateSnapshot, - nextState: RouterStateSnapshot - ): Observable | boolean { - return component.canDeactivate() || this.confirmService.confirm( - 'All unsaved data will be lost, are you sure you want to leave ?', - 'Unsaved Data' - ) - } - -} diff --git a/client/src/app/shared/guards/can-deactivate-guard.service.ts b/client/src/app/shared/guards/can-deactivate-guard.service.ts new file mode 100644 index 000000000..15618f699 --- /dev/null +++ b/client/src/app/shared/guards/can-deactivate-guard.service.ts @@ -0,0 +1,28 @@ +import { Injectable } from '@angular/core' +import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router' +import { Observable } from 'rxjs/Observable' +import { ConfirmService } from '../../core/index' + +export interface CanComponentDeactivate { + canDeactivate: () => { text?: string, canDeactivate: Observable | boolean } +} + +@Injectable() +export class CanDeactivateGuard implements CanDeactivate { + constructor (private confirmService: ConfirmService) { } + + canDeactivate (component: CanComponentDeactivate, + currentRoute: ActivatedRouteSnapshot, + currentState: RouterStateSnapshot, + nextState: RouterStateSnapshot + ): Observable | boolean { + const result = component.canDeactivate() + const text = result.text || 'All unsaved data will be lost, are you sure you want to leave this page?' + + return result.canDeactivate || this.confirmService.confirm( + text, + 'Warning' + ) + } + +} -- cgit v1.2.3