diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-25 19:01:13 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-25 19:09:47 +0100 |
commit | f6a043df74bc755de8e658ba76a4e55980b96f66 (patch) | |
tree | fb2640669f59a89bd2f2d8ab52d296425a4c55ed /client/src/app | |
parent | 94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4 (diff) | |
download | PeerTube-f6a043df74bc755de8e658ba76a4e55980b96f66.tar.gz PeerTube-f6a043df74bc755de8e658ba76a4e55980b96f66.tar.zst PeerTube-f6a043df74bc755de8e658ba76a4e55980b96f66.zip |
Improve video upload guard a little bit
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.ts | 4 | ||||
-rw-r--r-- | client/src/app/videos/+video-edit/video-add.component.ts | 29 | ||||
-rw-r--r-- | client/src/app/videos/+video-edit/video-add.module.ts | 2 |
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 @@ | |||
1 | import { Injectable } from '@angular/core' | 1 | import { Injectable } from '@angular/core' |
2 | import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router' | 2 | import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router' |
3 | import { Observable } from 'rxjs/Observable' | 3 | import { Observable } from 'rxjs/Observable' |
4 | import { ConfirmService } from '../core' | 4 | import { ConfirmService } from '../../core/index' |
5 | 5 | ||
6 | export interface CanComponentDeactivate { | 6 | export 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' | |||
4 | import { MetaGuard } from '@ngx-meta/core' | 4 | import { MetaGuard } from '@ngx-meta/core' |
5 | 5 | ||
6 | import { LoginGuard } from '../../core' | 6 | import { LoginGuard } from '../../core' |
7 | import { CanDeactivateGuard } from '../../shared/can-deactivate-guard.service' | 7 | import { CanDeactivateGuard } from '../../shared/guards/can-deactivate-guard.service' |
8 | import { VideoAddComponent } from './video-add.component' | 8 | import { VideoAddComponent } from './video-add.component' |
9 | 9 | ||
10 | const videoAddRoutes: Routes = [ | 10 | const 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 @@ | |||
1 | import { HttpEventType, HttpResponse } from '@angular/common/http' | 1 | import { HttpEventType, HttpResponse } from '@angular/common/http' |
2 | import { Component, OnInit, ViewChild } from '@angular/core' | 2 | import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core' |
3 | import { FormBuilder, FormGroup } from '@angular/forms' | 3 | import { FormBuilder, FormGroup } from '@angular/forms' |
4 | import { Router } from '@angular/router' | 4 | import { Router } from '@angular/router' |
5 | import { UserService } from '@app/shared' | 5 | import { UserService } from '@app/shared' |
6 | import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service' | ||
6 | import { NotificationsService } from 'angular2-notifications' | 7 | import { NotificationsService } from 'angular2-notifications' |
7 | import { BytesPipe } from 'ngx-pipes' | 8 | import { BytesPipe } from 'ngx-pipes' |
9 | import { Subscription } from 'rxjs/Subscription' | ||
8 | import { VideoPrivacy } from '../../../../../shared/models/videos' | 10 | import { VideoPrivacy } from '../../../../../shared/models/videos' |
9 | import { AuthService, ServerService } from '../../core' | 11 | import { AuthService, ServerService } from '../../core' |
10 | import { FormReactive } from '../../shared' | 12 | import { FormReactive } from '../../shared' |
@@ -12,7 +14,6 @@ import { ValidatorMessage } from '../../shared/forms/form-validators/validator-m | |||
12 | import { populateAsyncUserVideoChannels } from '../../shared/misc/utils' | 14 | import { populateAsyncUserVideoChannels } from '../../shared/misc/utils' |
13 | import { VideoEdit } from '../../shared/video/video-edit.model' | 15 | import { VideoEdit } from '../../shared/video/video-edit.model' |
14 | import { VideoService } from '../../shared/video/video.service' | 16 | import { VideoService } from '../../shared/video/video.service' |
15 | import { 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 | ||
26 | export class VideoAddComponent extends FormReactive implements OnInit, CanComponentDeactivate { | 27 | export 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' | |||
4 | import { VideoEditModule } from './shared/video-edit.module' | 4 | import { VideoEditModule } from './shared/video-edit.module' |
5 | import { VideoAddRoutingModule } from './video-add-routing.module' | 5 | import { VideoAddRoutingModule } from './video-add-routing.module' |
6 | import { VideoAddComponent } from './video-add.component' | 6 | import { VideoAddComponent } from './video-add.component' |
7 | import { CanDeactivateGuard } from '../../shared/can-deactivate-guard.service' | 7 | import { CanDeactivateGuard } from '../../shared/guards/can-deactivate-guard.service' |
8 | 8 | ||
9 | @NgModule({ | 9 | @NgModule({ |
10 | imports: [ | 10 | imports: [ |