]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/+video-edit/video-add-components/video-send.ts
Update video-import-url.component.html
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add-components / video-send.ts
CommitLineData
67ed6552 1import { catchError, switchMap, tap } from 'rxjs/operators'
a02b93ce 2import { Directive, EventEmitter, OnInit } from '@angular/core'
67ed6552
C
3import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core'
4import { populateAsyncUserVideoChannels } from '@app/helpers'
52c4976f 5import { FormReactive, SelectChannelItem } from '@app/shared/shared-forms'
67ed6552 6import { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
43620009 7import { LoadingBarService } from '@ngx-loading-bar/core'
67ed6552 8import { ServerConfig, VideoConstant, VideoPrivacy } from '@shared/models'
43620009 9
583eb04b 10@Directive()
a02b93ce 11// tslint:disable-next-line: directive-class-suffix
c199c427 12export abstract class VideoSend extends FormReactive implements OnInit {
9abd170d 13 userVideoChannels: SelectChannelItem[] = []
8cd7faaa 14 videoPrivacies: VideoConstant<VideoPrivacy>[] = []
43620009
C
15 videoCaptions: VideoCaptionEdit[] = []
16
17 firstStepPrivacyId = 0
18 firstStepChannelId = 0
19
78848714 20 abstract firstStepDone: EventEmitter<string>
7373507f 21 abstract firstStepError: EventEmitter<void>
43620009
C
22 protected abstract readonly DEFAULT_VIDEO_PRIVACY: VideoPrivacy
23
24 protected loadingBar: LoadingBarService
f8b2c1b4 25 protected notifier: Notifier
43620009
C
26 protected authService: AuthService
27 protected serverService: ServerService
28 protected videoService: VideoService
29 protected videoCaptionService: VideoCaptionService
ba430d75 30 protected serverConfig: ServerConfig
43620009 31
c199c427 32 abstract canDeactivate (): CanComponentDeactivateResult
43620009
C
33
34 ngOnInit () {
35 this.buildForm({})
36
37 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
38 .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id)
39
ba430d75
C
40 this.serverConfig = this.serverService.getTmpConfig()
41 this.serverService.getConfig()
42 .subscribe(config => this.serverConfig = config)
43
44 this.serverService.getVideoPrivacies()
43620009 45 .subscribe(
ba430d75 46 privacies => {
02c01341 47 this.videoPrivacies = this.videoService.explainedPrivacyLabels(privacies)
43620009
C
48
49 this.firstStepPrivacyId = this.DEFAULT_VIDEO_PRIVACY
50 })
51 }
52
53 checkForm () {
54 this.forceCheck()
55
56 return this.form.valid
57 }
58
59 protected updateVideoAndCaptions (video: VideoEdit) {
a02b93ce 60 this.loadingBar.useRef().start()
43620009
C
61
62 return this.videoService.updateVideo(video)
63 .pipe(
64 // Then update captions
65 switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)),
a02b93ce 66 tap(() => this.loadingBar.useRef().complete()),
43620009 67 catchError(err => {
a02b93ce 68 this.loadingBar.useRef().complete()
43620009
C
69 throw err
70 })
71 )
72 }
73}