]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/+videos/+video-edit/video-add-components/video-send.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add-components / video-send.ts
... / ...
CommitLineData
1import { catchError, switchMap, tap } from 'rxjs/operators'
2import { SelectChannelItem } from 'src/types/select-options-item.model'
3import { Directive, EventEmitter, OnInit } from '@angular/core'
4import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core'
5import { listUserChannelsForSelect } from '@app/helpers'
6import { FormReactive } from '@app/shared/shared-forms'
7import { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
8import { LoadingBarService } from '@ngx-loading-bar/core'
9import { HTMLServerConfig, VideoConstant, VideoPrivacy } from '@shared/models'
10
11@Directive()
12// eslint-disable-next-line @angular-eslint/directive-class-suffix
13export abstract class VideoSend extends FormReactive implements OnInit {
14 userVideoChannels: SelectChannelItem[] = []
15 videoPrivacies: VideoConstant<VideoPrivacy>[] = []
16 videoCaptions: VideoCaptionEdit[] = []
17
18 firstStepPrivacyId: VideoPrivacy
19 firstStepChannelId: number
20
21 abstract firstStepDone: EventEmitter<string>
22 abstract firstStepError: EventEmitter<void>
23
24 protected loadingBar: LoadingBarService
25 protected notifier: Notifier
26 protected authService: AuthService
27
28 protected serverService: ServerService
29 protected videoService: VideoService
30 protected videoCaptionService: VideoCaptionService
31
32 protected serverConfig: HTMLServerConfig
33
34 protected highestPrivacy: VideoPrivacy
35
36 abstract canDeactivate (): CanComponentDeactivateResult
37
38 ngOnInit () {
39 this.buildForm({})
40
41 listUserChannelsForSelect(this.authService)
42 .subscribe(channels => {
43 this.userVideoChannels = channels
44 this.firstStepChannelId = this.userVideoChannels[0].id
45 })
46
47 this.serverConfig = this.serverService.getHTMLConfig()
48
49 this.serverService.getVideoPrivacies()
50 .subscribe(
51 privacies => {
52 const defaultPrivacy = this.serverConfig.defaults.publish.privacy
53
54 const { videoPrivacies, defaultPrivacyId } = this.videoService.explainedPrivacyLabels(privacies, defaultPrivacy)
55
56 this.videoPrivacies = videoPrivacies
57 this.firstStepPrivacyId = defaultPrivacyId
58
59 this.highestPrivacy = this.videoService.getHighestAvailablePrivacy(privacies)
60 })
61 }
62
63 protected updateVideoAndCaptions (video: VideoEdit) {
64 this.loadingBar.useRef().start()
65
66 return this.videoService.updateVideo(video)
67 .pipe(
68 // Then update captions
69 switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)),
70 tap(() => this.loadingBar.useRef().complete()),
71 catchError(err => {
72 this.loadingBar.useRef().complete()
73 throw err
74 })
75 )
76 }
77
78 protected async isFormValid () {
79 await this.waitPendingCheck()
80 this.forceCheck()
81
82 return this.form.valid
83 }
84}