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