1 import { catchError, switchMap, tap } from 'rxjs/operators'
2 import { EventEmitter, OnInit, Directive } from '@angular/core'
3 import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core'
4 import { populateAsyncUserVideoChannels } from '@app/helpers'
5 import { FormReactive } from '@app/shared/shared-forms'
6 import { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
7 import { LoadingBarService } from '@ngx-loading-bar/core'
8 import { ServerConfig, VideoConstant, VideoPrivacy } from '@shared/models'
11 export abstract class VideoSend extends FormReactive implements OnInit {
12 userVideoChannels: { id: number, label: string, support: string }[] = []
13 videoPrivacies: VideoConstant<VideoPrivacy>[] = []
14 videoCaptions: VideoCaptionEdit[] = []
16 firstStepPrivacyId = 0
17 firstStepChannelId = 0
19 abstract firstStepDone: EventEmitter<string>
20 abstract firstStepError: EventEmitter<void>
21 protected abstract readonly DEFAULT_VIDEO_PRIVACY: VideoPrivacy
23 protected loadingBar: LoadingBarService
24 protected notifier: Notifier
25 protected authService: AuthService
26 protected serverService: ServerService
27 protected videoService: VideoService
28 protected videoCaptionService: VideoCaptionService
29 protected serverConfig: ServerConfig
31 abstract canDeactivate (): CanComponentDeactivateResult
36 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
37 .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id)
39 this.serverConfig = this.serverService.getTmpConfig()
40 this.serverService.getConfig()
41 .subscribe(config => this.serverConfig = config)
43 this.serverService.getVideoPrivacies()
46 this.videoPrivacies = privacies
48 this.firstStepPrivacyId = this.DEFAULT_VIDEO_PRIVACY
55 return this.form.valid
58 protected updateVideoAndCaptions (video: VideoEdit) {
59 this.loadingBar.start()
61 return this.videoService.updateVideo(video)
63 // Then update captions
64 switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)),
65 tap(() => this.loadingBar.complete()),
67 this.loadingBar.complete()