1 import { Component, OnDestroy, OnInit, ViewChild } 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 { VideoChannelUpdate } from '../../../../../shared/models/videos'
6 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
7 import { Subscription } from 'rxjs'
8 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
9 import { AuthService, ServerService } from '@app/core'
10 import { I18n } from '@ngx-translate/i18n-polyfill'
11 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
12 import { VideoChannelValidatorsService } from '@app/shared/forms/form-validators/video-channel-validators.service'
15 selector: 'my-account-video-channel-update',
16 templateUrl: './my-account-video-channel-edit.component.html',
17 styleUrls: [ './my-account-video-channel-edit.component.scss' ]
19 export class MyAccountVideoChannelUpdateComponent extends MyAccountVideoChannelEdit implements OnInit, OnDestroy {
20 @ViewChild('avatarfileInput') avatarfileInput
24 videoChannelToUpdate: VideoChannel
25 private paramsSub: Subscription
28 protected formValidatorService: FormValidatorService,
29 private authService: AuthService,
30 private videoChannelValidatorsService: VideoChannelValidatorsService,
31 private notificationsService: NotificationsService,
32 private router: Router,
33 private route: ActivatedRoute,
34 private videoChannelService: VideoChannelService,
36 private serverService: ServerService
43 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME,
44 description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION,
45 support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT
48 this.paramsSub = this.route.params.subscribe(routeParams => {
49 const videoChannelId = routeParams['videoChannelId']
51 this.videoChannelService.getVideoChannel(videoChannelId).subscribe(
52 videoChannelToUpdate => {
53 this.videoChannelToUpdate = videoChannelToUpdate
55 this.form.patchValue({
56 'display-name': videoChannelToUpdate.displayName,
57 description: videoChannelToUpdate.description,
58 support: videoChannelToUpdate.support
62 err => this.error = err.message
68 if (this.paramsSub) this.paramsSub.unsubscribe()
72 this.error = undefined
74 const body = this.form.value
75 const videoChannelUpdate: VideoChannelUpdate = {
76 displayName: body['display-name'],
77 description: body.description || null,
78 support: body.support || null
81 this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.uuid, videoChannelUpdate).subscribe(
83 this.authService.refreshUserInformation()
84 this.notificationsService.success(
86 this.i18n('Video channel {{videoChannelName}} updated.', { videoChannelName: videoChannelUpdate.displayName })
88 this.router.navigate([ '/my-account', 'video-channels' ])
91 err => this.error = err.message
95 onAvatarChange (formData: FormData) {
96 this.videoChannelService.changeVideoChannelAvatar(this.videoChannelToUpdate.uuid, formData)
99 this.notificationsService.success(this.i18n('Success'), this.i18n('Avatar changed.'))
101 this.videoChannelToUpdate.updateAvatar(data.avatar)
104 err => this.notificationsService.error(this.i18n('Error'), err.message)
108 get maxAvatarSize () {
109 return this.serverService.getConfig().avatar.file.size.max
112 get avatarExtensions () {
113 return this.serverService.getConfig().avatar.file.extensions.join(',')
120 getFormButtonTitle () {
121 return this.i18n('Update')