1 import { Component, OnInit, OnDestroy } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { NotificationsService } from 'angular2-notifications'
4 import 'rxjs/add/observable/from'
5 import 'rxjs/add/operator/concatAll'
6 import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit'
7 import { FormBuilder, FormGroup } from '@angular/forms'
8 import { VideoChannelUpdate } from '../../../../../shared/models/videos'
10 VIDEO_CHANNEL_DESCRIPTION,
11 VIDEO_CHANNEL_DISPLAY_NAME,
13 } from '@app/shared/forms/form-validators/video-channel'
14 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
15 import { Subscription } from 'rxjs/Subscription'
16 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
17 import { AuthService } from '@app/core'
20 selector: 'my-account-video-channel-update',
21 templateUrl: './my-account-video-channel-edit.component.html',
22 styleUrls: [ './my-account-video-channel-edit.component.scss' ]
24 export class MyAccountVideoChannelUpdateComponent extends MyAccountVideoChannelEdit implements OnInit, OnDestroy {
33 validationMessages = {
34 'display-name': VIDEO_CHANNEL_DISPLAY_NAME.MESSAGES,
35 'description': VIDEO_CHANNEL_DESCRIPTION.MESSAGES,
36 'support': VIDEO_CHANNEL_SUPPORT.MESSAGES
39 private videoChannelToUpdate: VideoChannel
40 private paramsSub: Subscription
43 private authService: AuthService,
44 private notificationsService: NotificationsService,
45 private router: Router,
46 private route: ActivatedRoute,
47 private formBuilder: FormBuilder,
48 private videoChannelService: VideoChannelService
54 this.form = this.formBuilder.group({
55 'display-name': [ '', VIDEO_CHANNEL_DISPLAY_NAME.VALIDATORS ],
56 description: [ '', VIDEO_CHANNEL_DESCRIPTION.VALIDATORS ],
57 support: [ '', VIDEO_CHANNEL_SUPPORT.VALIDATORS ]
60 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
66 this.paramsSub = this.route.params.subscribe(routeParams => {
67 const videoChannelId = routeParams['videoChannelId']
69 this.videoChannelService.getVideoChannel(videoChannelId).subscribe(
70 videoChannelToUpdate => {
71 this.videoChannelToUpdate = videoChannelToUpdate
73 this.form.patchValue({
74 'display-name': videoChannelToUpdate.displayName,
75 description: videoChannelToUpdate.description,
76 support: videoChannelToUpdate.support
80 err => this.error = err.message
86 if (this.paramsSub) this.paramsSub.unsubscribe()
90 this.error = undefined
92 const body = this.form.value
93 const videoChannelUpdate: VideoChannelUpdate = {
94 displayName: body['display-name'],
95 description: body.description || null,
96 support: body.support || null
99 this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.uuid, videoChannelUpdate).subscribe(
101 this.authService.refreshUserInformation()
102 this.notificationsService.success('Success', `Video channel ${videoChannelUpdate.displayName} updated.`)
103 this.router.navigate([ '/my-account', 'video-channels' ])
106 err => this.error = err.message
114 getFormButtonTitle () {