aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app')
-rw-r--r--client/src/app/shared/guards/can-deactivate-guard.service.ts (renamed from client/src/app/shared/can-deactivate-guard.service.ts)13
-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.ts29
-rw-r--r--client/src/app/videos/+video-edit/video-add.module.ts2
4 files changed, 35 insertions, 13 deletions
diff --git a/client/src/app/shared/can-deactivate-guard.service.ts b/client/src/app/shared/guards/can-deactivate-guard.service.ts
index 4239df737..15618f699 100644
--- a/client/src/app/shared/can-deactivate-guard.service.ts
+++ b/client/src/app/shared/guards/can-deactivate-guard.service.ts
@@ -1,10 +1,10 @@
1import { Injectable } from '@angular/core' 1import { Injectable } from '@angular/core'
2import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router' 2import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'
3import { Observable } from 'rxjs/Observable' 3import { Observable } from 'rxjs/Observable'
4import { ConfirmService } from '../core' 4import { ConfirmService } from '../../core/index'
5 5
6export interface CanComponentDeactivate { 6export interface CanComponentDeactivate {
7 canDeactivate: () => Observable<boolean> | boolean 7 canDeactivate: () => { text?: string, canDeactivate: Observable<boolean> | boolean }
8} 8}
9 9
10@Injectable() 10@Injectable()
@@ -16,9 +16,12 @@ export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate>
16 currentState: RouterStateSnapshot, 16 currentState: RouterStateSnapshot,
17 nextState: RouterStateSnapshot 17 nextState: RouterStateSnapshot
18 ): Observable<boolean> | boolean { 18 ): Observable<boolean> | boolean {
19 return component.canDeactivate() || this.confirmService.confirm( 19 const result = component.canDeactivate()
20 'All unsaved data will be lost, are you sure you want to leave ?', 20 const text = result.text || 'All unsaved data will be lost, are you sure you want to leave this page?'
21 'Unsaved Data' 21
22 return result.canDeactivate || this.confirmService.confirm(
23 text,
24 'Warning'
22 ) 25 )
23 } 26 }
24 27
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 9541a2bd1..e0fef7158 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,7 +4,7 @@ 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 { CanDeactivateGuard } from '../../shared/guards/can-deactivate-guard.service'
8import { VideoAddComponent } from './video-add.component' 8import { VideoAddComponent } from './video-add.component'
9 9
10const videoAddRoutes: Routes = [ 10const videoAddRoutes: Routes = [
@@ -12,7 +12,7 @@ const videoAddRoutes: Routes = [
12 path: '', 12 path: '',
13 component: VideoAddComponent, 13 component: VideoAddComponent,
14 canActivate: [ MetaGuard, LoginGuard ], 14 canActivate: [ MetaGuard, LoginGuard ],
15 canDeactivate: [CanDeactivateGuard] 15 canDeactivate: [ CanDeactivateGuard ]
16 } 16 }
17] 17]
18 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 58eccef48..c6f0525c3 100644
--- a/client/src/app/videos/+video-edit/video-add.component.ts
+++ b/client/src/app/videos/+video-edit/video-add.component.ts
@@ -1,10 +1,12 @@
1import { HttpEventType, HttpResponse } from '@angular/common/http' 1import { HttpEventType, HttpResponse } from '@angular/common/http'
2import { Component, OnInit, ViewChild } from '@angular/core' 2import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
3import { FormBuilder, FormGroup } from '@angular/forms' 3import { FormBuilder, FormGroup } from '@angular/forms'
4import { Router } from '@angular/router' 4import { Router } from '@angular/router'
5import { UserService } from '@app/shared' 5import { UserService } from '@app/shared'
6import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
6import { NotificationsService } from 'angular2-notifications' 7import { NotificationsService } from 'angular2-notifications'
7import { BytesPipe } from 'ngx-pipes' 8import { BytesPipe } from 'ngx-pipes'
9import { Subscription } from 'rxjs/Subscription'
8import { VideoPrivacy } from '../../../../../shared/models/videos' 10import { VideoPrivacy } from '../../../../../shared/models/videos'
9import { AuthService, ServerService } from '../../core' 11import { AuthService, ServerService } from '../../core'
10import { FormReactive } from '../../shared' 12import { FormReactive } from '../../shared'
@@ -12,7 +14,6 @@ import { ValidatorMessage } from '../../shared/forms/form-validators/validator-m
12import { populateAsyncUserVideoChannels } from '../../shared/misc/utils' 14import { populateAsyncUserVideoChannels } from '../../shared/misc/utils'
13import { VideoEdit } from '../../shared/video/video-edit.model' 15import { VideoEdit } from '../../shared/video/video-edit.model'
14import { VideoService } from '../../shared/video/video.service' 16import { VideoService } from '../../shared/video/video.service'
15import { CanComponentDeactivate } from '@app/shared/can-deactivate-guard.service'
16 17
17@Component({ 18@Component({
18 selector: 'my-videos-add', 19 selector: 'my-videos-add',
@@ -23,12 +24,12 @@ import { CanComponentDeactivate } from '@app/shared/can-deactivate-guard.service
23 ] 24 ]
24}) 25})
25 26
26export class VideoAddComponent extends FormReactive implements OnInit, CanComponentDeactivate { 27export class VideoAddComponent extends FormReactive implements OnInit, OnDestroy, CanComponentDeactivate {
27 @ViewChild('videofileInput') videofileInput 28 @ViewChild('videofileInput') videofileInput
28 29
29 isUploadingVideo = false 30 isUploadingVideo = false
30 videoUploaded = false 31 videoUploaded = false
31 videoUploadObservable = null 32 videoUploadObservable: Subscription = null
32 videoUploadPercents = 0 33 videoUploadPercents = 0
33 videoUploadedIds = { 34 videoUploadedIds = {
34 id: 0, 35 id: 0,
@@ -85,8 +86,26 @@ export class VideoAddComponent extends FormReactive implements OnInit, CanCompon
85 }) 86 })
86 } 87 }
87 88
89 ngOnDestroy () {
90 if (this.videoUploadObservable) {
91 this.videoUploadObservable.unsubscribe()
92 }
93 }
94
88 canDeactivate () { 95 canDeactivate () {
89 return !this.isUploadingVideo 96 let text = ''
97
98 if (this.videoUploaded === true) {
99 text = 'Your video was uploaded in your account and is private.' +
100 ' But associated data (tags, description...) will be lost, are you sure you want to leave this page?'
101 } else {
102 text = 'Your video is not uploaded yet, are you sure you want to leave this page?'
103 }
104
105 return {
106 canDeactivate: !this.isUploadingVideo,
107 text
108 }
90 } 109 }
91 110
92 fileChange () { 111 fileChange () {
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 af9696a03..1bfedf251 100644
--- a/client/src/app/videos/+video-edit/video-add.module.ts
+++ b/client/src/app/videos/+video-edit/video-add.module.ts
@@ -4,7 +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' 7import { CanDeactivateGuard } from '../../shared/guards/can-deactivate-guard.service'
8 8
9@NgModule({ 9@NgModule({
10 imports: [ 10 imports: [