1 import { EventEmitter, OnInit } from '@angular/core'
2 import { LoadingBarService } from '@ngx-loading-bar/core'
3 import { NotificationsService } from 'angular2-notifications'
4 import { catchError, switchMap, tap } from 'rxjs/operators'
5 import { FormReactive } from '@app/shared'
6 import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
7 import { VideoConstant, VideoPrivacy } from '../../../../../../shared'
8 import { AuthService, ServerService } from '@app/core'
9 import { VideoService } from '@app/shared/video/video.service'
10 import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
11 import { VideoCaptionService } from '@app/shared/video-caption'
12 import { VideoEdit } from '@app/shared/video/video-edit.model'
13 import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils'
15 export abstract class VideoSend extends FormReactive implements OnInit, CanComponentDeactivate {
17 userVideoChannels: { id: number, label: string, support: string }[] = []
18 videoPrivacies: VideoConstant<VideoPrivacy>[] = []
19 videoCaptions: VideoCaptionEdit[] = []
21 firstStepPrivacyId = 0
22 firstStepChannelId = 0
24 abstract firstStepDone: EventEmitter<string>
25 protected abstract readonly DEFAULT_VIDEO_PRIVACY: VideoPrivacy
27 protected loadingBar: LoadingBarService
28 protected notificationsService: NotificationsService
29 protected authService: AuthService
30 protected serverService: ServerService
31 protected videoService: VideoService
32 protected videoCaptionService: VideoCaptionService
34 abstract canDeactivate ()
39 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
40 .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id)
42 this.serverService.videoPrivaciesLoaded
45 this.videoPrivacies = this.serverService.getVideoPrivacies()
47 this.firstStepPrivacyId = this.DEFAULT_VIDEO_PRIVACY
54 return this.form.valid
57 protected updateVideoAndCaptions (video: VideoEdit) {
58 this.loadingBar.start()
60 return this.videoService.updateVideo(video)
62 // Then update captions
63 switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)),
64 tap(() => this.loadingBar.complete()),
66 this.loadingBar.complete()