]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+videos/+video-edit/video-add-components/video-send.ts
add ng-select for templatable select options
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add-components / video-send.ts
1 import { catchError, switchMap, tap } from 'rxjs/operators'
2 import { Directive, EventEmitter, OnInit } from '@angular/core'
3 import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core'
4 import { populateAsyncUserVideoChannels } from '@app/helpers'
5 import { FormReactive } from '@app/shared/shared-forms'
6 import { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
7 import { LoadingBarService } from '@ngx-loading-bar/core'
8 import { ServerConfig, VideoConstant, VideoPrivacy } from '@shared/models'
9
10 @Directive()
11 // tslint:disable-next-line: directive-class-suffix
12 export abstract class VideoSend extends FormReactive implements OnInit {
13 userVideoChannels: { id: number, label: string, support: string, avatarPath?: string }[] = []
14 videoPrivacies: VideoConstant<VideoPrivacy>[] = []
15 videoCaptions: VideoCaptionEdit[] = []
16
17 firstStepPrivacyId = 0
18 firstStepChannelId = 0
19
20 abstract firstStepDone: EventEmitter<string>
21 abstract firstStepError: EventEmitter<void>
22 protected abstract readonly DEFAULT_VIDEO_PRIVACY: VideoPrivacy
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: ServerConfig
31
32 abstract canDeactivate (): CanComponentDeactivateResult
33
34 ngOnInit () {
35 this.buildForm({})
36
37 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
38 .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id)
39
40 this.serverConfig = this.serverService.getTmpConfig()
41 this.serverService.getConfig()
42 .subscribe(config => this.serverConfig = config)
43
44 this.serverService.getVideoPrivacies()
45 .subscribe(
46 privacies => {
47 this.videoPrivacies = this.videoService.explainedPrivacyLabels(privacies)
48
49 this.firstStepPrivacyId = this.DEFAULT_VIDEO_PRIVACY
50 })
51 }
52
53 checkForm () {
54 this.forceCheck()
55
56 return this.form.valid
57 }
58
59 protected updateVideoAndCaptions (video: VideoEdit) {
60 this.loadingBar.useRef().start()
61
62 return this.videoService.updateVideo(video)
63 .pipe(
64 // Then update captions
65 switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)),
66 tap(() => this.loadingBar.useRef().complete()),
67 catchError(err => {
68 this.loadingBar.useRef().complete()
69 throw err
70 })
71 )
72 }
73 }