aboutsummaryrefslogtreecommitdiffhomepage
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/src/app/shared/can-deactivate-guard.service.ts25
-rw-r--r--client/src/app/videos/+video-edit/video-add-routing.module.ts4
-rw-r--r--client/src/app/videos/+video-edit/video-add.component.ts7
-rw-r--r--client/src/app/videos/+video-edit/video-add.module.ts8
4 files changed, 38 insertions, 6 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}
diff --git a/client/src/app/videos/+video-edit/video-add-routing.module.ts b/client/src/app/videos/+video-edit/video-add-routing.module.ts
index e7a32627c..9541a2bd1 100644
--- a/client/src/app/videos/+video-edit/video-add-routing.module.ts
+++ b/client/src/app/videos/+video-edit/video-add-routing.module.ts
@@ -4,13 +4,15 @@ import { RouterModule, Routes } from '@angular/router'
4import { MetaGuard } from '@ngx-meta/core' 4import { MetaGuard } from '@ngx-meta/core'
5 5
6import { LoginGuard } from '../../core' 6import { LoginGuard } from '../../core'
7import { CanDeactivateGuard } from '../../shared/can-deactivate-guard.service'
7import { VideoAddComponent } from './video-add.component' 8import { VideoAddComponent } from './video-add.component'
8 9
9const videoAddRoutes: Routes = [ 10const videoAddRoutes: Routes = [
10 { 11 {
11 path: '', 12 path: '',
12 component: VideoAddComponent, 13 component: VideoAddComponent,
13 canActivate: [ MetaGuard, LoginGuard ] 14 canActivate: [ MetaGuard, LoginGuard ],
15 canDeactivate: [CanDeactivateGuard]
14 } 16 }
15] 17]
16 18
diff --git a/client/src/app/videos/+video-edit/video-add.component.ts b/client/src/app/videos/+video-edit/video-add.component.ts
index 73efd60bf..58eccef48 100644
--- a/client/src/app/videos/+video-edit/video-add.component.ts
+++ b/client/src/app/videos/+video-edit/video-add.component.ts
@@ -12,6 +12,7 @@ import { ValidatorMessage } from '../../shared/forms/form-validators/validator-m
12import { populateAsyncUserVideoChannels } from '../../shared/misc/utils' 12import { populateAsyncUserVideoChannels } from '../../shared/misc/utils'
13import { VideoEdit } from '../../shared/video/video-edit.model' 13import { VideoEdit } from '../../shared/video/video-edit.model'
14import { VideoService } from '../../shared/video/video.service' 14import { VideoService } from '../../shared/video/video.service'
15import { CanComponentDeactivate } from '@app/shared/can-deactivate-guard.service'
15 16
16@Component({ 17@Component({
17 selector: 'my-videos-add', 18 selector: 'my-videos-add',
@@ -22,7 +23,7 @@ import { VideoService } from '../../shared/video/video.service'
22 ] 23 ]
23}) 24})
24 25
25export class VideoAddComponent extends FormReactive implements OnInit { 26export class VideoAddComponent extends FormReactive implements OnInit, CanComponentDeactivate {
26 @ViewChild('videofileInput') videofileInput 27 @ViewChild('videofileInput') videofileInput
27 28
28 isUploadingVideo = false 29 isUploadingVideo = false
@@ -84,6 +85,10 @@ export class VideoAddComponent extends FormReactive implements OnInit {
84 }) 85 })
85 } 86 }
86 87
88 canDeactivate () {
89 return !this.isUploadingVideo
90 }
91
87 fileChange () { 92 fileChange () {
88 this.uploadFirstStep() 93 this.uploadFirstStep()
89 } 94 }
diff --git a/client/src/app/videos/+video-edit/video-add.module.ts b/client/src/app/videos/+video-edit/video-add.module.ts
index 1efecdf4d..af9696a03 100644
--- a/client/src/app/videos/+video-edit/video-add.module.ts
+++ b/client/src/app/videos/+video-edit/video-add.module.ts
@@ -4,6 +4,7 @@ import { SharedModule } from '../../shared'
4import { VideoEditModule } from './shared/video-edit.module' 4import { VideoEditModule } from './shared/video-edit.module'
5import { VideoAddRoutingModule } from './video-add-routing.module' 5import { VideoAddRoutingModule } from './video-add-routing.module'
6import { VideoAddComponent } from './video-add.component' 6import { VideoAddComponent } from './video-add.component'
7import { CanDeactivateGuard } from '../../shared/can-deactivate-guard.service'
7 8
8@NgModule({ 9@NgModule({
9 imports: [ 10 imports: [
@@ -12,15 +13,14 @@ import { VideoAddComponent } from './video-add.component'
12 SharedModule, 13 SharedModule,
13 ProgressBarModule 14 ProgressBarModule
14 ], 15 ],
15
16 declarations: [ 16 declarations: [
17 VideoAddComponent 17 VideoAddComponent
18 ], 18 ],
19
20 exports: [ 19 exports: [
21 VideoAddComponent 20 VideoAddComponent
22 ], 21 ],
23 22 providers: [
24 providers: [ ] 23 CanDeactivateGuard
24 ]
25}) 25})
26export class VideoAddModule { } 26export class VideoAddModule { }