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 { VideoConstant, VideoPrivacy } from '../../../../../../shared'
7 import { AuthService, ServerService } from '@app/core'
8 import { VideoService } from '@app/shared/video/video.service'
9 import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
10 import { VideoCaptionService } from '@app/shared/video-caption'
11 import { VideoEdit } from '@app/shared/video/video-edit.model'
12 import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils'
13 import { CanComponentDeactivateResult } from '@app/shared/guards/can-deactivate-guard.service'
15 export abstract class VideoSend extends FormReactive implements OnInit {
16 userVideoChannels: { id: number, label: string, support: string }[] = []
17 videoPrivacies: VideoConstant<VideoPrivacy>[] = []
18 videoCaptions: VideoCaptionEdit[] = []
20 firstStepPrivacyId = 0
21 firstStepChannelId = 0
23 abstract firstStepDone: EventEmitter<string>
24 protected abstract readonly DEFAULT_VIDEO_PRIVACY: VideoPrivacy
26 protected loadingBar: LoadingBarService
27 protected notificationsService: NotificationsService
28 protected authService: AuthService
29 protected serverService: ServerService
30 protected videoService: VideoService
31 protected videoCaptionService: VideoCaptionService
33 abstract canDeactivate (): CanComponentDeactivateResult
38 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
39 .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id)
41 this.serverService.videoPrivaciesLoaded
44 this.videoPrivacies = this.serverService.getVideoPrivacies()
46 this.firstStepPrivacyId = this.DEFAULT_VIDEO_PRIVACY
53 return this.form.valid
56 protected updateVideoAndCaptions (video: VideoEdit) {
57 this.loadingBar.start()
59 return this.videoService.updateVideo(video)
61 // Then update captions
62 switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)),
63 tap(() => this.loadingBar.complete()),
65 this.loadingBar.complete()