From 788487140c500abeb69ca44daf3a9e26efa8d36f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 6 Aug 2018 15:30:24 +0200 Subject: Move send video components inside a dedicated directory --- .../+video-edit/video-add-components/video-send.ts | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 client/src/app/videos/+video-edit/video-add-components/video-send.ts (limited to 'client/src/app/videos/+video-edit/video-add-components/video-send.ts') diff --git a/client/src/app/videos/+video-edit/video-add-components/video-send.ts b/client/src/app/videos/+video-edit/video-add-components/video-send.ts new file mode 100644 index 000000000..efd182269 --- /dev/null +++ b/client/src/app/videos/+video-edit/video-add-components/video-send.ts @@ -0,0 +1,71 @@ +import { EventEmitter, OnInit } from '@angular/core' +import { LoadingBarService } from '@ngx-loading-bar/core' +import { NotificationsService } from 'angular2-notifications' +import { catchError, switchMap, tap } from 'rxjs/operators' +import { FormReactive } from '@app/shared' +import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service' +import { VideoConstant, VideoPrivacy } from '../../../../../../shared' +import { AuthService, ServerService } from '@app/core' +import { VideoService } from '@app/shared/video/video.service' +import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model' +import { VideoCaptionService } from '@app/shared/video-caption' +import { VideoEdit } from '@app/shared/video/video-edit.model' +import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils' + +export abstract class VideoSend extends FormReactive implements OnInit, CanComponentDeactivate { + + userVideoChannels: { id: number, label: string, support: string }[] = [] + videoPrivacies: VideoConstant[] = [] + videoCaptions: VideoCaptionEdit[] = [] + + firstStepPrivacyId = 0 + firstStepChannelId = 0 + + abstract firstStepDone: EventEmitter + protected abstract readonly DEFAULT_VIDEO_PRIVACY: VideoPrivacy + + protected loadingBar: LoadingBarService + protected notificationsService: NotificationsService + protected authService: AuthService + protected serverService: ServerService + protected videoService: VideoService + protected videoCaptionService: VideoCaptionService + + abstract canDeactivate () + + ngOnInit () { + this.buildForm({}) + + populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) + .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id) + + this.serverService.videoPrivaciesLoaded + .subscribe( + () => { + this.videoPrivacies = this.serverService.getVideoPrivacies() + + this.firstStepPrivacyId = this.DEFAULT_VIDEO_PRIVACY + }) + } + + checkForm () { + this.forceCheck() + + return this.form.valid + } + + protected updateVideoAndCaptions (video: VideoEdit) { + this.loadingBar.start() + + return this.videoService.updateVideo(video) + .pipe( + // Then update captions + switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)), + tap(() => this.loadingBar.complete()), + catchError(err => { + this.loadingBar.complete() + throw err + }) + ) + } +} -- cgit v1.2.3