+import { map, switchMap } from 'rxjs/operators'
import { Component, OnInit } from '@angular/core'
import { FormBuilder, FormGroup } from '@angular/forms'
import { ActivatedRoute, Router } from '@angular/router'
import { LoadingBarService } from '@ngx-loading-bar/core'
import { NotificationsService } from 'angular2-notifications'
-import 'rxjs/add/observable/forkJoin'
import { VideoPrivacy } from '../../../../../shared/models/videos'
import { ServerService } from '../../core'
import { AuthService } from '../../core/auth'
import { ValidatorMessage } from '../../shared/forms/form-validators/validator-message'
import { VideoEdit } from '../../shared/video/video-edit.model'
import { VideoService } from '../../shared/video/video.service'
-import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils'
+import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
@Component({
selector: 'my-videos-update',
styleUrls: [ './shared/video-edit.component.scss' ],
templateUrl: './video-update.component.html'
})
-
export class VideoUpdateComponent extends FormReactive implements OnInit {
video: VideoEdit
private serverService: ServerService,
private videoService: VideoService,
private authService: AuthService,
- private loadingBar: LoadingBarService
+ private loadingBar: LoadingBarService,
+ private videoChannelService: VideoChannelService
) {
super()
}
this.serverService.videoPrivaciesLoaded
.subscribe(() => this.videoPrivacies = this.serverService.getVideoPrivacies())
- const uuid: string = this.route.snapshot.params['uuid']
+ const uuid: string = this.route.snapshot.params[ 'uuid' ]
this.videoService.getVideo(uuid)
- .switchMap(video => {
- return this.videoService
- .loadCompleteDescription(video.descriptionPath)
- .map(description => Object.assign(video, { description }))
- })
- .subscribe(
- video => {
- this.video = new VideoEdit(video)
-
- populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
- .catch(err => console.error(err))
-
- // We cannot set private a video that was not private
- if (video.privacy.id !== VideoPrivacy.PRIVATE) {
- const newVideoPrivacies = []
- for (const p of this.videoPrivacies) {
- if (p.id !== VideoPrivacy.PRIVATE) newVideoPrivacies.push(p)
+ .pipe(
+ switchMap(video => {
+ return this.videoService
+ .loadCompleteDescription(video.descriptionPath)
+ .pipe(map(description => Object.assign(video, { description })))
+ }),
+ switchMap(video => {
+ return this.videoChannelService
+ .listAccountVideoChannels(video.account.id)
+ .pipe(
+ map(result => result.data),
+ map(videoChannels => videoChannels.map(c => ({ id: c.id, label: c.displayName }))),
+ map(videoChannels => ({ video, videoChannels }))
+ )
+ })
+ )
+ .subscribe(
+ ({ video, videoChannels }) => {
+ this.video = new VideoEdit(video)
+ this.userVideoChannels = videoChannels
+
+ // We cannot set private a video that was not private
+ if (video.privacy.id !== VideoPrivacy.PRIVATE) {
+ const newVideoPrivacies = []
+ for (const p of this.videoPrivacies) {
+ if (p.id !== VideoPrivacy.PRIVATE) newVideoPrivacies.push(p)
+ }
+
+ this.videoPrivacies = newVideoPrivacies
}
- this.videoPrivacies = newVideoPrivacies
- }
+ this.hydrateFormFromVideo()
+ },
- this.hydrateFormFromVideo()
- },
-
- err => {
- console.error(err)
- this.notificationsService.error('Error', err.message)
- }
- )
+ err => {
+ console.error(err)
+ this.notificationsService.error('Error', err.message)
+ }
+ )
}
checkForm () {