]>
Commit | Line | Data |
---|---|---|
1 | import { catchError, switchMap, tap } from 'rxjs/operators' | |
2 | import { SelectChannelItem } from 'src/types/select-options-item.model' | |
3 | import { Directive, EventEmitter, OnInit } from '@angular/core' | |
4 | import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core' | |
5 | import { listUserChannels } from '@app/helpers' | |
6 | import { FormReactive } from '@app/shared/shared-forms' | |
7 | import { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main' | |
8 | import { LoadingBarService } from '@ngx-loading-bar/core' | |
9 | import { HTMLServerConfig, VideoConstant, VideoPrivacy } from '@shared/models' | |
10 | ||
11 | @Directive() | |
12 | // tslint:disable-next-line: directive-class-suffix | |
13 | export abstract class VideoSend extends FormReactive implements OnInit { | |
14 | userVideoChannels: SelectChannelItem[] = [] | |
15 | videoPrivacies: VideoConstant<VideoPrivacy>[] = [] | |
16 | videoCaptions: VideoCaptionEdit[] = [] | |
17 | ||
18 | firstStepPrivacyId = 0 | |
19 | firstStepChannelId = 0 | |
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 | protected serverService: ServerService | |
28 | protected videoService: VideoService | |
29 | protected videoCaptionService: VideoCaptionService | |
30 | protected serverConfig: HTMLServerConfig | |
31 | ||
32 | abstract canDeactivate (): CanComponentDeactivateResult | |
33 | ||
34 | ngOnInit () { | |
35 | this.buildForm({}) | |
36 | ||
37 | listUserChannels(this.authService) | |
38 | .subscribe(channels => { | |
39 | this.userVideoChannels = channels | |
40 | this.firstStepChannelId = this.userVideoChannels[0].id | |
41 | }) | |
42 | ||
43 | this.serverConfig = this.serverService.getHTMLConfig() | |
44 | ||
45 | this.serverService.getVideoPrivacies() | |
46 | .subscribe( | |
47 | privacies => { | |
48 | const { videoPrivacies, defaultPrivacyId } = this.videoService.explainedPrivacyLabels(privacies) | |
49 | ||
50 | this.videoPrivacies = videoPrivacies | |
51 | this.firstStepPrivacyId = defaultPrivacyId | |
52 | }) | |
53 | } | |
54 | ||
55 | checkForm () { | |
56 | this.forceCheck() | |
57 | ||
58 | return this.form.valid | |
59 | } | |
60 | ||
61 | protected updateVideoAndCaptions (video: VideoEdit) { | |
62 | this.loadingBar.useRef().start() | |
63 | ||
64 | return this.videoService.updateVideo(video) | |
65 | .pipe( | |
66 | // Then update captions | |
67 | switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)), | |
68 | tap(() => this.loadingBar.useRef().complete()), | |
69 | catchError(err => { | |
70 | this.loadingBar.useRef().complete() | |
71 | throw err | |
72 | }) | |
73 | ) | |
74 | } | |
75 | } |