aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/+video-edit/video-import.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-06 15:12:54 +0200
committerChocobozzz <me@florianbigard.com>2018-08-08 09:30:31 +0200
commit43620009d5bc0d2a8da6480276b046d1c946bdc9 (patch)
treef4bf50816c1bba4fe23682775428f57ae7040fd4 /client/src/app/videos/+video-edit/video-import.component.ts
parentaad0ec24e886a93c5f85cbb8eb4c31ff5e973e1a (diff)
downloadPeerTube-43620009d5bc0d2a8da6480276b046d1c946bdc9.tar.gz
PeerTube-43620009d5bc0d2a8da6480276b046d1c946bdc9.tar.zst
PeerTube-43620009d5bc0d2a8da6480276b046d1c946bdc9.zip
Refractor video upload/import
Diffstat (limited to 'client/src/app/videos/+video-edit/video-import.component.ts')
-rw-r--r--client/src/app/videos/+video-edit/video-import.component.ts58
1 files changed, 13 insertions, 45 deletions
diff --git a/client/src/app/videos/+video-edit/video-import.component.ts b/client/src/app/videos/+video-edit/video-import.component.ts
index 5f14efd54..5d355dc8b 100644
--- a/client/src/app/videos/+video-edit/video-import.component.ts
+++ b/client/src/app/videos/+video-edit/video-import.component.ts
@@ -2,19 +2,16 @@ import { Component, EventEmitter, OnInit, Output } from '@angular/core'
2import { Router } from '@angular/router' 2import { Router } from '@angular/router'
3import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service' 3import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
4import { NotificationsService } from 'angular2-notifications' 4import { NotificationsService } from 'angular2-notifications'
5import { VideoConstant, VideoPrivacy, VideoUpdate } from '../../../../../shared/models/videos' 5import { VideoPrivacy, VideoUpdate } from '../../../../../shared/models/videos'
6import { AuthService, ServerService } from '../../core' 6import { AuthService, ServerService } from '../../core'
7import { FormReactive } from '../../shared'
8import { populateAsyncUserVideoChannels } from '../../shared/misc/utils'
9import { VideoService } from '../../shared/video/video.service' 7import { VideoService } from '../../shared/video/video.service'
10import { I18n } from '@ngx-translate/i18n-polyfill' 8import { I18n } from '@ngx-translate/i18n-polyfill'
11import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' 9import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
12import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
13import { VideoImportService } from '@app/shared/video-import' 10import { VideoImportService } from '@app/shared/video-import'
14import { VideoEdit } from '@app/shared/video/video-edit.model' 11import { VideoEdit } from '@app/shared/video/video-edit.model'
15import { switchMap } from 'rxjs/operators'
16import { LoadingBarService } from '@ngx-loading-bar/core' 12import { LoadingBarService } from '@ngx-loading-bar/core'
17import { VideoCaptionService } from '@app/shared/video-caption' 13import { VideoCaptionService } from '@app/shared/video-caption'
14import { VideoSend } from '@app/videos/+video-edit/shared/video-send'
18 15
19@Component({ 16@Component({
20 selector: 'my-video-import', 17 selector: 'my-video-import',
@@ -24,7 +21,7 @@ import { VideoCaptionService } from '@app/shared/video-caption'
24 './video-import.component.scss' 21 './video-import.component.scss'
25 ] 22 ]
26}) 23})
27export class VideoImportComponent extends FormReactive implements OnInit, CanComponentDeactivate { 24export class VideoImportComponent extends VideoSend implements OnInit, CanComponentDeactivate {
28 @Output() firstStepDone = new EventEmitter<string>() 25 @Output() firstStepDone = new EventEmitter<string>()
29 26
30 targetUrl = '' 27 targetUrl = ''
@@ -34,55 +31,33 @@ export class VideoImportComponent extends FormReactive implements OnInit, CanCom
34 hasImportedVideo = false 31 hasImportedVideo = false
35 isUpdatingVideo = false 32 isUpdatingVideo = false
36 33
37 userVideoChannels: { id: number, label: string, support: string }[] = []
38 videoPrivacies: VideoConstant<string>[] = []
39 videoCaptions: VideoCaptionEdit[] = []
40
41 firstStepPrivacyId = 0
42 firstStepChannelId = 0
43 video: VideoEdit 34 video: VideoEdit
44 35
36 protected readonly DEFAULT_VIDEO_PRIVACY = VideoPrivacy.PRIVATE
37
45 constructor ( 38 constructor (
46 protected formValidatorService: FormValidatorService, 39 protected formValidatorService: FormValidatorService,
40 protected loadingBar: LoadingBarService,
41 protected notificationsService: NotificationsService,
42 protected authService: AuthService,
43 protected serverService: ServerService,
44 protected videoService: VideoService,
45 protected videoCaptionService: VideoCaptionService,
47 private router: Router, 46 private router: Router,
48 private loadingBar: LoadingBarService,
49 private notificationsService: NotificationsService,
50 private authService: AuthService,
51 private serverService: ServerService,
52 private videoService: VideoService,
53 private videoImportService: VideoImportService, 47 private videoImportService: VideoImportService,
54 private videoCaptionService: VideoCaptionService,
55 private i18n: I18n 48 private i18n: I18n
56 ) { 49 ) {
57 super() 50 super()
58 } 51 }
59 52
60 ngOnInit () { 53 ngOnInit () {
61 this.buildForm({}) 54 super.ngOnInit()
62
63 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
64 .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id)
65
66 this.serverService.videoPrivaciesLoaded
67 .subscribe(
68 () => {
69 this.videoPrivacies = this.serverService.getVideoPrivacies()
70
71 // Private by default
72 this.firstStepPrivacyId = VideoPrivacy.PRIVATE
73 })
74 } 55 }
75 56
76 canDeactivate () { 57 canDeactivate () {
77 return { canDeactivate: true } 58 return { canDeactivate: true }
78 } 59 }
79 60
80 checkForm () {
81 this.forceCheck()
82
83 return this.form.valid
84 }
85
86 isTargetUrlValid () { 61 isTargetUrlValid () {
87 return this.targetUrl && this.targetUrl.match(/https?:\/\//) 62 return this.targetUrl && this.targetUrl.match(/https?:\/\//)
88 } 63 }
@@ -130,26 +105,19 @@ export class VideoImportComponent extends FormReactive implements OnInit, CanCom
130 105
131 this.video.patch(this.form.value) 106 this.video.patch(this.form.value)
132 107
133 this.loadingBar.start()
134 this.isUpdatingVideo = true 108 this.isUpdatingVideo = true
135 109
136 // Update the video 110 // Update the video
137 this.videoService.updateVideo(this.video) 111 this.updateVideoAndCaptions(this.video)
138 .pipe(
139 // Then update captions
140 switchMap(() => this.videoCaptionService.updateCaptions(this.video.id, this.videoCaptions))
141 )
142 .subscribe( 112 .subscribe(
143 () => { 113 () => {
144 this.isUpdatingVideo = false 114 this.isUpdatingVideo = false
145 this.loadingBar.complete()
146 this.notificationsService.success(this.i18n('Success'), this.i18n('Video to import updated.')) 115 this.notificationsService.success(this.i18n('Success'), this.i18n('Video to import updated.'))
147 116
148 this.router.navigate([ '/my-account', 'video-imports' ]) 117 this.router.navigate([ '/my-account', 'video-imports' ])
149 }, 118 },
150 119
151 err => { 120 err => {
152 this.loadingBar.complete()
153 this.isUpdatingVideo = false 121 this.isUpdatingVideo = false
154 this.notificationsService.error(this.i18n('Error'), err.message) 122 this.notificationsService.error(this.i18n('Error'), err.message)
155 console.error(err) 123 console.error(err)