1 import { EventEmitter, OnInit } from '@angular/core'
2 import { LoadingBarService } from '@ngx-loading-bar/core'
3 import { AuthService, Notifier, ServerService } from '@app/core'
4 import { catchError, switchMap, tap } from 'rxjs/operators'
5 import { FormReactive } from '@app/shared'
6 import { ServerConfig, VideoConstant, VideoPrivacy } from '../../../../../../shared'
7 import { VideoService } from '@app/shared/video/video.service'
8 import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
9 import { VideoCaptionService } from '@app/shared/video-caption'
10 import { VideoEdit } from '@app/shared/video/video-edit.model'
11 import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils'
12 import { CanComponentDeactivateResult } from '@app/shared/guards/can-deactivate-guard.service'
14 export abstract class VideoSend extends FormReactive implements OnInit {
15 userVideoChannels: { id: number, label: string, support: string }[] = []
16 videoPrivacies: VideoConstant<VideoPrivacy>[] = []
17 videoCaptions: VideoCaptionEdit[] = []
19 firstStepPrivacyId = 0
20 firstStepChannelId = 0
22 abstract firstStepDone: EventEmitter<string>
23 abstract firstStepError: EventEmitter<void>
24 protected abstract readonly DEFAULT_VIDEO_PRIVACY: VideoPrivacy
26 protected loadingBar: LoadingBarService
27 protected notifier: Notifier
28 protected authService: AuthService
29 protected serverService: ServerService
30 protected videoService: VideoService
31 protected videoCaptionService: VideoCaptionService
32 protected serverConfig: ServerConfig
34 abstract canDeactivate (): CanComponentDeactivateResult
39 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
40 .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id)
42 this.serverConfig = this.serverService.getTmpConfig()
43 this.serverService.getConfig()
44 .subscribe(config => this.serverConfig = config)
46 this.serverService.getVideoPrivacies()
49 this.videoPrivacies = privacies
51 this.firstStepPrivacyId = this.DEFAULT_VIDEO_PRIVACY
58 return this.form.valid
61 protected updateVideoAndCaptions (video: VideoEdit) {
62 this.loadingBar.start()
64 return this.videoService.updateVideo(video)
66 // Then update captions
67 switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)),
68 tap(() => this.loadingBar.complete()),
70 this.loadingBar.complete()