2020-06-23 14:10:17 +02:00
|
|
|
import { catchError, switchMap, tap } from 'rxjs/operators'
|
2021-02-10 09:05:29 +01:00
|
|
|
import { SelectChannelItem } from 'src/types/select-options-item.model'
|
2020-08-06 16:14:58 +02:00
|
|
|
import { Directive, EventEmitter, OnInit } from '@angular/core'
|
2020-06-23 14:10:17 +02:00
|
|
|
import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core'
|
2021-02-25 09:09:41 +01:00
|
|
|
import { listUserChannels } from '@app/helpers'
|
2021-02-10 09:05:29 +01:00
|
|
|
import { FormReactive } from '@app/shared/shared-forms'
|
2020-06-23 14:10:17 +02:00
|
|
|
import { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
|
2018-08-06 15:12:54 +02:00
|
|
|
import { LoadingBarService } from '@ngx-loading-bar/core'
|
2021-06-04 13:31:41 +02:00
|
|
|
import { HTMLServerConfig, VideoConstant, VideoPrivacy } from '@shared/models'
|
2018-08-06 15:12:54 +02:00
|
|
|
|
2020-06-26 08:37:26 +02:00
|
|
|
@Directive()
|
2021-08-17 14:42:53 +02:00
|
|
|
// eslint-disable-next-line @angular-eslint/directive-class-suffix
|
2018-10-18 14:35:31 +02:00
|
|
|
export abstract class VideoSend extends FormReactive implements OnInit {
|
2020-08-11 09:22:42 +02:00
|
|
|
userVideoChannels: SelectChannelItem[] = []
|
2018-09-04 16:21:07 +02:00
|
|
|
videoPrivacies: VideoConstant<VideoPrivacy>[] = []
|
2018-08-06 15:12:54 +02:00
|
|
|
videoCaptions: VideoCaptionEdit[] = []
|
|
|
|
|
2021-07-13 08:46:51 +02:00
|
|
|
firstStepPrivacyId: VideoPrivacy
|
|
|
|
firstStepChannelId: number
|
2018-08-06 15:12:54 +02:00
|
|
|
|
2018-08-06 15:30:24 +02:00
|
|
|
abstract firstStepDone: EventEmitter<string>
|
2018-11-16 10:05:25 +01:00
|
|
|
abstract firstStepError: EventEmitter<void>
|
2018-08-06 15:12:54 +02:00
|
|
|
|
|
|
|
protected loadingBar: LoadingBarService
|
2018-12-19 16:04:34 +01:00
|
|
|
protected notifier: Notifier
|
2018-08-06 15:12:54 +02:00
|
|
|
protected authService: AuthService
|
2021-07-13 08:46:51 +02:00
|
|
|
|
2018-08-06 15:12:54 +02:00
|
|
|
protected serverService: ServerService
|
|
|
|
protected videoService: VideoService
|
|
|
|
protected videoCaptionService: VideoCaptionService
|
2021-07-13 08:46:51 +02:00
|
|
|
|
2021-06-04 13:31:41 +02:00
|
|
|
protected serverConfig: HTMLServerConfig
|
2018-08-06 15:12:54 +02:00
|
|
|
|
2021-07-13 08:46:51 +02:00
|
|
|
protected highestPrivacy: VideoPrivacy
|
|
|
|
|
2018-10-18 14:35:31 +02:00
|
|
|
abstract canDeactivate (): CanComponentDeactivateResult
|
2018-08-06 15:12:54 +02:00
|
|
|
|
|
|
|
ngOnInit () {
|
|
|
|
this.buildForm({})
|
|
|
|
|
2021-02-25 09:09:41 +01:00
|
|
|
listUserChannels(this.authService)
|
|
|
|
.subscribe(channels => {
|
|
|
|
this.userVideoChannels = channels
|
|
|
|
this.firstStepChannelId = this.userVideoChannels[0].id
|
|
|
|
})
|
2018-08-06 15:12:54 +02:00
|
|
|
|
2021-06-04 13:31:41 +02:00
|
|
|
this.serverConfig = this.serverService.getHTMLConfig()
|
2019-12-18 15:31:54 +01:00
|
|
|
|
|
|
|
this.serverService.getVideoPrivacies()
|
2018-08-06 15:12:54 +02:00
|
|
|
.subscribe(
|
2019-12-18 15:31:54 +01:00
|
|
|
privacies => {
|
2021-12-14 17:17:01 +01:00
|
|
|
const defaultPrivacy = this.serverConfig.defaults.publish.privacy
|
|
|
|
|
|
|
|
const { videoPrivacies, defaultPrivacyId } = this.videoService.explainedPrivacyLabels(privacies, defaultPrivacy)
|
2018-08-06 15:12:54 +02:00
|
|
|
|
2021-06-05 11:05:25 +02:00
|
|
|
this.videoPrivacies = videoPrivacies
|
|
|
|
this.firstStepPrivacyId = defaultPrivacyId
|
2021-07-13 08:46:51 +02:00
|
|
|
|
|
|
|
this.highestPrivacy = this.videoService.getHighestAvailablePrivacy(privacies)
|
2018-08-06 15:12:54 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
checkForm () {
|
|
|
|
this.forceCheck()
|
|
|
|
|
|
|
|
return this.form.valid
|
|
|
|
}
|
|
|
|
|
|
|
|
protected updateVideoAndCaptions (video: VideoEdit) {
|
2020-08-06 16:14:58 +02:00
|
|
|
this.loadingBar.useRef().start()
|
2018-08-06 15:12:54 +02:00
|
|
|
|
|
|
|
return this.videoService.updateVideo(video)
|
|
|
|
.pipe(
|
|
|
|
// Then update captions
|
|
|
|
switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)),
|
2020-08-06 16:14:58 +02:00
|
|
|
tap(() => this.loadingBar.useRef().complete()),
|
2018-08-06 15:12:54 +02:00
|
|
|
catchError(err => {
|
2020-08-06 16:14:58 +02:00
|
|
|
this.loadingBar.useRef().complete()
|
2018-08-06 15:12:54 +02:00
|
|
|
throw err
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|