]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/+video-edit/video-update.component.ts
Client: fix loading server configurations
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-edit / video-update.component.ts
CommitLineData
db7af09b 1import { Component, OnInit } from '@angular/core'
df98563e
C
2import { FormBuilder, FormGroup } from '@angular/forms'
3import { ActivatedRoute, Router } from '@angular/router'
dc8bc31b 4
df98563e 5import { NotificationsService } from 'angular2-notifications'
8140a704 6
db7af09b 7import { ServerService } from '../../core'
6e07c3de
C
8import {
9 FormReactive,
10 VIDEO_NAME,
11 VIDEO_CATEGORY,
d07137b9 12 VIDEO_LICENCE,
db216afd 13 VIDEO_LANGUAGE,
6e07c3de
C
14 VIDEO_DESCRIPTION,
15 VIDEO_TAGS
df98563e
C
16} from '../../shared'
17import { Video, VideoService } from '../shared'
1553e15d 18
dc8bc31b 19@Component({
d8e689b8
C
20 selector: 'my-videos-update',
21 styleUrls: [ './video-edit.component.scss' ],
22 templateUrl: './video-update.component.html'
dc8bc31b
C
23})
24
d8e689b8 25export class VideoUpdateComponent extends FormReactive implements OnInit {
df98563e
C
26 tags: string[] = []
27 videoCategories = []
28 videoLicences = []
29 videoLanguages = []
30 video: Video
4b2f33f3 31
df98563e
C
32 tagValidators = VIDEO_TAGS.VALIDATORS
33 tagValidatorsMessages = VIDEO_TAGS.MESSAGES
3758da94 34
df98563e
C
35 error: string = null
36 form: FormGroup
4b2f33f3 37 formErrors = {
e822fdae 38 name: '',
6e07c3de 39 category: '',
d07137b9 40 licence: '',
db216afd 41 language: '',
3758da94 42 description: ''
df98563e 43 }
4b2f33f3
C
44 validationMessages = {
45 name: VIDEO_NAME.MESSAGES,
6e07c3de 46 category: VIDEO_CATEGORY.MESSAGES,
d07137b9 47 licence: VIDEO_LICENCE.MESSAGES,
db216afd 48 language: VIDEO_LANGUAGE.MESSAGES,
3758da94 49 description: VIDEO_DESCRIPTION.MESSAGES
df98563e 50 }
dc8bc31b 51
df98563e 52 fileError = ''
bf57d5ee 53
df98563e 54 constructor (
4b2f33f3 55 private formBuilder: FormBuilder,
d8e689b8 56 private route: ActivatedRoute,
7ddd02c9 57 private router: Router,
6e07c3de 58 private notificationsService: NotificationsService,
db7af09b 59 private serverService: ServerService,
6e07c3de 60 private videoService: VideoService
4b2f33f3 61 ) {
df98563e 62 super()
4b2f33f3 63 }
dc8bc31b 64
df98563e 65 buildForm () {
4b2f33f3
C
66 this.form = this.formBuilder.group({
67 name: [ '', VIDEO_NAME.VALIDATORS ],
92fb909c 68 nsfw: [ false ],
6e07c3de 69 category: [ '', VIDEO_CATEGORY.VALIDATORS ],
d07137b9 70 licence: [ '', VIDEO_LICENCE.VALIDATORS ],
db216afd 71 language: [ '', VIDEO_LANGUAGE.VALIDATORS ],
4b2f33f3 72 description: [ '', VIDEO_DESCRIPTION.VALIDATORS ],
3758da94 73 tags: [ '' ]
df98563e 74 })
4b2f33f3 75
df98563e 76 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
e822fdae
C
77 }
78
df98563e
C
79 ngOnInit () {
80 this.buildForm()
d8e689b8 81
db7af09b
C
82 this.videoCategories = this.serverService.getVideoCategories()
83 this.videoLicences = this.serverService.getVideoLicences()
84 this.videoLanguages = this.serverService.getVideoLanguages()
6e07c3de 85
0a6658fd
C
86 const uuid: string = this.route.snapshot.params['uuid']
87 this.videoService.getVideo(uuid)
d8e689b8
C
88 .subscribe(
89 video => {
df98563e 90 this.video = video
db216afd 91
df98563e 92 this.hydrateFormFromVideo()
d8e689b8 93 },
4b2f33f3 94
df98563e
C
95 err => {
96 console.error(err)
97 this.error = 'Cannot fetch video.'
98 }
99 )
e822fdae
C
100 }
101
df98563e
C
102 checkForm () {
103 this.forceCheck()
c24ac1c1 104
df98563e 105 return this.form.valid
c24ac1c1
C
106 }
107
df98563e 108 update () {
c24ac1c1 109 if (this.checkForm() === false) {
df98563e 110 return
c24ac1c1
C
111 }
112
df98563e 113 this.video.patch(this.form.value)
d8e689b8
C
114
115 this.videoService.updateVideo(this.video)
116 .subscribe(
117 () => {
df98563e 118 this.notificationsService.success('Success', 'Video updated.')
0a6658fd 119 this.router.navigate([ '/videos/watch', this.video.uuid ])
d8e689b8
C
120 },
121
122 err => {
df98563e
C
123 this.error = 'Cannot update the video.'
124 console.error(err)
d8e689b8 125 }
df98563e 126 )
e822fdae 127
dc8bc31b 128 }
e54163c2 129
df98563e
C
130 private hydrateFormFromVideo () {
131 this.form.patchValue(this.video.toJSON())
d8e689b8 132 }
dc8bc31b 133}