aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-25 19:01:13 +0100
committerChocobozzz <me@florianbigard.com>2018-01-25 19:09:47 +0100
commitf6a043df74bc755de8e658ba76a4e55980b96f66 (patch)
treefb2640669f59a89bd2f2d8ab52d296425a4c55ed /client/src/app/videos
parent94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4 (diff)
downloadPeerTube-f6a043df74bc755de8e658ba76a4e55980b96f66.tar.gz
PeerTube-f6a043df74bc755de8e658ba76a4e55980b96f66.tar.zst
PeerTube-f6a043df74bc755de8e658ba76a4e55980b96f66.zip
Improve video upload guard a little bit
Diffstat (limited to 'client/src/app/videos')
-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
3 files changed, 27 insertions, 8 deletions
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: [