1 import { Component, OnDestroy, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { NotificationsService } from 'angular2-notifications'
4 import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit'
5 import { FormBuilder, FormGroup } from '@angular/forms'
6 import { VideoChannelUpdate } from '../../../../../shared/models/videos'
8 VIDEO_CHANNEL_DESCRIPTION,
9 VIDEO_CHANNEL_DISPLAY_NAME,
11 } from '@app/shared/forms/form-validators/video-channel'
12 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
13 import { Subscription } from 'rxjs'
14 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
15 import { AuthService } from '@app/core'
18 selector: 'my-account-video-channel-update',
19 templateUrl: './my-account-video-channel-edit.component.html',
20 styleUrls: [ './my-account-video-channel-edit.component.scss' ]
22 export class MyAccountVideoChannelUpdateComponent extends MyAccountVideoChannelEdit implements OnInit, OnDestroy {
31 validationMessages = {
32 'display-name': VIDEO_CHANNEL_DISPLAY_NAME.MESSAGES,
33 'description': VIDEO_CHANNEL_DESCRIPTION.MESSAGES,
34 'support': VIDEO_CHANNEL_SUPPORT.MESSAGES
37 private videoChannelToUpdate: VideoChannel
38 private paramsSub: Subscription
41 private authService: AuthService,
42 private notificationsService: NotificationsService,
43 private router: Router,
44 private route: ActivatedRoute,
45 private formBuilder: FormBuilder,
46 private videoChannelService: VideoChannelService
52 this.form = this.formBuilder.group({
53 'display-name': [ '', VIDEO_CHANNEL_DISPLAY_NAME.VALIDATORS ],
54 description: [ '', VIDEO_CHANNEL_DESCRIPTION.VALIDATORS ],
55 support: [ '', VIDEO_CHANNEL_SUPPORT.VALIDATORS ]
58 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
64 this.paramsSub = this.route.params.subscribe(routeParams => {
65 const videoChannelId = routeParams['videoChannelId']
67 this.videoChannelService.getVideoChannel(videoChannelId).subscribe(
68 videoChannelToUpdate => {
69 this.videoChannelToUpdate = videoChannelToUpdate
71 this.form.patchValue({
72 'display-name': videoChannelToUpdate.displayName,
73 description: videoChannelToUpdate.description,
74 support: videoChannelToUpdate.support
78 err => this.error = err.message
84 if (this.paramsSub) this.paramsSub.unsubscribe()
88 this.error = undefined
90 const body = this.form.value
91 const videoChannelUpdate: VideoChannelUpdate = {
92 displayName: body['display-name'],
93 description: body.description || null,
94 support: body.support || null
97 this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.uuid, videoChannelUpdate).subscribe(
99 this.authService.refreshUserInformation()
100 this.notificationsService.success('Success', `Video channel ${videoChannelUpdate.displayName} updated.`)
101 this.router.navigate([ '/my-account', 'video-channels' ])
104 err => this.error = err.message
112 getFormButtonTitle () {