import { FormBuilder, FormGroup } from '@angular/forms'
import { Router } from '@angular/router'
import { NotificationsService } from 'angular2-notifications'
-import { VideoService } from 'app/shared/video/video.service'
-import { VideoCreate } from '../../../../../shared'
import { VideoPrivacy } from '../../../../../shared/models/videos'
import { AuthService, ServerService } from '../../core'
import { FormReactive } from '../../shared'
-import { ValidatorMessage } from '../../shared/forms/form-validators'
+import { ValidatorMessage } from '../../shared/forms/form-validators/validator-message'
+import { populateAsyncUserVideoChannels } from '../../shared/misc/utils'
import { VideoEdit } from '../../shared/video/video-edit.model'
+import { VideoService } from '../../shared/video/video.service'
@Component({
selector: 'my-videos-add',
isUploadingVideo = false
videoUploaded = false
videoUploadPercents = 0
- videoUploadedId = 0
+ videoUploadedIds = {
+ id: 0,
+ uuid: ''
+ }
error: string = null
form: FormGroup
ngOnInit () {
this.buildForm()
+ populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
+ .then(() => this.firstStepChannelId = this.userVideoChannels[0].id)
+
this.serverService.videoPrivaciesLoaded
.subscribe(
() => {
// Public by default
this.firstStepPrivacyId = VideoPrivacy.PUBLIC
})
-
- this.authService.userInformationLoaded
- .subscribe(
- () => {
- const user = this.authService.getUser()
- if (!user) return
-
- const videoChannels = user.videoChannels
- if (Array.isArray(videoChannels) === false) return
-
- this.userVideoChannels = videoChannels.map(v => ({ id: v.id, label: v.name }))
- this.firstStepChannelId = this.userVideoChannels[0].id
- }
- )
}
fileChange () {
this.videoUploaded = true
- this.videoUploadedId = event.body.video.id
+ this.videoUploadedIds = event.body.video
}
},
const video = new VideoEdit()
video.patch(this.form.value)
video.channel = this.firstStepChannelId
- video.id = this.videoUploadedId
+ video.id = this.videoUploadedIds.id
+ video.uuid = this.videoUploadedIds.uuid
this.videoService.updateVideo(video)
.subscribe(
() => {
this.notificationsService.success('Success', 'Video published.')
- this.router.navigate([ '/videos/watch', video.id ])
+ this.router.navigate([ '/videos/watch', video.uuid ])
},
err => {