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