PeerTube/client/src/app/+videos/+video-edit/video-add-components/video-send.ts

76 lines
2.5 KiB
TypeScript
Raw Normal View History

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()
2020-08-06 16:14:58 +02:00
// tslint:disable-next-line: 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[] = []
firstStepPrivacyId = 0
firstStepChannelId = 0
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
protected notifier: Notifier
2018-08-06 15:12:54 +02:00
protected authService: AuthService
protected serverService: ServerService
protected videoService: VideoService
protected videoCaptionService: VideoCaptionService
2021-06-04 13:31:41 +02:00
protected serverConfig: HTMLServerConfig
2018-08-06 15:12:54 +02:00
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 => {
const { videoPrivacies, defaultPrivacyId } = this.videoService.explainedPrivacyLabels(privacies)
2018-08-06 15:12:54 +02:00
this.videoPrivacies = videoPrivacies
this.firstStepPrivacyId = defaultPrivacyId
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
})
)
}
}