]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/+video-edit/video-add-components/video-send.ts
Fix player progress bar when changing resolution
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-edit / video-add-components / video-send.ts
CommitLineData
78848714 1import { EventEmitter, OnInit } from '@angular/core'
43620009
C
2import { LoadingBarService } from '@ngx-loading-bar/core'
3import { NotificationsService } from 'angular2-notifications'
78848714
C
4import { catchError, switchMap, tap } from 'rxjs/operators'
5import { FormReactive } from '@app/shared'
78848714 6import { VideoConstant, VideoPrivacy } from '../../../../../../shared'
43620009
C
7import { AuthService, ServerService } from '@app/core'
8import { VideoService } from '@app/shared/video/video.service'
78848714 9import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
43620009 10import { VideoCaptionService } from '@app/shared/video-caption'
43620009 11import { VideoEdit } from '@app/shared/video/video-edit.model'
78848714 12import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils'
c199c427 13import { CanComponentDeactivateResult } from '@app/shared/guards/can-deactivate-guard.service'
43620009 14
c199c427 15export abstract class VideoSend extends FormReactive implements OnInit {
43620009 16 userVideoChannels: { id: number, label: string, support: string }[] = []
8cd7faaa 17 videoPrivacies: VideoConstant<VideoPrivacy>[] = []
43620009
C
18 videoCaptions: VideoCaptionEdit[] = []
19
20 firstStepPrivacyId = 0
21 firstStepChannelId = 0
22
78848714 23 abstract firstStepDone: EventEmitter<string>
43620009
C
24 protected abstract readonly DEFAULT_VIDEO_PRIVACY: VideoPrivacy
25
26 protected loadingBar: LoadingBarService
27 protected notificationsService: NotificationsService
28 protected authService: AuthService
29 protected serverService: ServerService
30 protected videoService: VideoService
31 protected videoCaptionService: VideoCaptionService
32
c199c427 33 abstract canDeactivate (): CanComponentDeactivateResult
43620009
C
34
35 ngOnInit () {
36 this.buildForm({})
37
38 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
39 .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id)
40
41 this.serverService.videoPrivaciesLoaded
42 .subscribe(
43 () => {
44 this.videoPrivacies = this.serverService.getVideoPrivacies()
45
46 this.firstStepPrivacyId = this.DEFAULT_VIDEO_PRIVACY
47 })
48 }
49
50 checkForm () {
51 this.forceCheck()
52
53 return this.form.valid
54 }
55
56 protected updateVideoAndCaptions (video: VideoEdit) {
57 this.loadingBar.start()
58
59 return this.videoService.updateVideo(video)
60 .pipe(
61 // Then update captions
62 switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)),
63 tap(() => this.loadingBar.complete()),
64 catchError(err => {
65 this.loadingBar.complete()
66 throw err
67 })
68 )
69 }
70}