]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/+video-edit/video-add-components/video-send.ts
allow public video privacy to be deleted in the web client
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add-components / video-send.ts
CommitLineData
67ed6552 1import { catchError, switchMap, tap } from 'rxjs/operators'
21e493d4 2import { SelectChannelItem } from 'src/types/select-options-item.model'
a02b93ce 3import { Directive, EventEmitter, OnInit } from '@angular/core'
67ed6552 4import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core'
9556ce48 5import { listUserChannels } from '@app/helpers'
21e493d4 6import { FormReactive } from '@app/shared/shared-forms'
67ed6552 7import { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
43620009 8import { LoadingBarService } from '@ngx-loading-bar/core'
2989628b 9import { HTMLServerConfig, VideoConstant, VideoPrivacy } from '@shared/models'
43620009 10
583eb04b 11@Directive()
a02b93ce 12// tslint:disable-next-line: directive-class-suffix
c199c427 13export abstract class VideoSend extends FormReactive implements OnInit {
9abd170d 14 userVideoChannels: SelectChannelItem[] = []
8cd7faaa 15 videoPrivacies: VideoConstant<VideoPrivacy>[] = []
43620009
C
16 videoCaptions: VideoCaptionEdit[] = []
17
18 firstStepPrivacyId = 0
19 firstStepChannelId = 0
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
C
26 protected authService: AuthService
27 protected serverService: ServerService
28 protected videoService: VideoService
29 protected videoCaptionService: VideoCaptionService
2989628b 30 protected serverConfig: HTMLServerConfig
43620009 31
c199c427 32 abstract canDeactivate (): CanComponentDeactivateResult
43620009
C
33
34 ngOnInit () {
35 this.buildForm({})
36
9556ce48
C
37 listUserChannels(this.authService)
38 .subscribe(channels => {
39 this.userVideoChannels = channels
40 this.firstStepChannelId = this.userVideoChannels[0].id
41 })
43620009 42
2989628b 43 this.serverConfig = this.serverService.getHTMLConfig()
ba430d75
C
44
45 this.serverService.getVideoPrivacies()
43620009 46 .subscribe(
ba430d75 47 privacies => {
29510651 48 const { videoPrivacies, defaultPrivacyId } = this.videoService.explainedPrivacyLabels(privacies)
43620009 49
29510651
RK
50 this.videoPrivacies = videoPrivacies
51 this.firstStepPrivacyId = defaultPrivacyId
43620009
C
52 })
53 }
54
55 checkForm () {
56 this.forceCheck()
57
58 return this.form.valid
59 }
60
61 protected updateVideoAndCaptions (video: VideoEdit) {
a02b93ce 62 this.loadingBar.useRef().start()
43620009
C
63
64 return this.videoService.updateVideo(video)
65 .pipe(
66 // Then update captions
67 switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)),
a02b93ce 68 tap(() => this.loadingBar.useRef().complete()),
43620009 69 catchError(err => {
a02b93ce 70 this.loadingBar.useRef().complete()
43620009
C
71 throw err
72 })
73 )
74 }
75}