1 import { Component, OnDestroy, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { AuthService, Notifier, ServerService } from '@app/core'
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 { I18n } from '@ngx-translate/i18n-polyfill'
10 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
11 import { VideoChannelValidatorsService } from '@app/shared/forms/form-validators/video-channel-validators.service'
14 selector: 'my-account-video-channel-update',
15 templateUrl: './my-account-video-channel-edit.component.html',
16 styleUrls: [ './my-account-video-channel-edit.component.scss' ]
18 export class MyAccountVideoChannelUpdateComponent extends MyAccountVideoChannelEdit implements OnInit, OnDestroy {
20 videoChannelToUpdate: VideoChannel
22 private paramsSub: Subscription
25 protected formValidatorService: FormValidatorService,
26 private authService: AuthService,
27 private videoChannelValidatorsService: VideoChannelValidatorsService,
28 private notifier: Notifier,
29 private router: Router,
30 private route: ActivatedRoute,
31 private videoChannelService: VideoChannelService,
33 private serverService: ServerService
40 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME,
41 description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION,
42 support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT
45 this.paramsSub = this.route.params.subscribe(routeParams => {
46 const videoChannelId = routeParams['videoChannelId']
48 this.videoChannelService.getVideoChannel(videoChannelId).subscribe(
49 videoChannelToUpdate => {
50 this.videoChannelToUpdate = videoChannelToUpdate
52 this.form.patchValue({
53 'display-name': videoChannelToUpdate.displayName,
54 description: videoChannelToUpdate.description,
55 support: videoChannelToUpdate.support
59 err => this.error = err.message
65 if (this.paramsSub) this.paramsSub.unsubscribe()
69 this.error = undefined
71 const body = this.form.value
72 const videoChannelUpdate: VideoChannelUpdate = {
73 displayName: body['display-name'],
74 description: body.description || null,
75 support: body.support || null
78 this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.name, videoChannelUpdate).subscribe(
80 this.authService.refreshUserInformation()
82 this.notifier.success(
83 this.i18n('Video channel {{videoChannelName}} updated.', { videoChannelName: videoChannelUpdate.displayName })
86 this.router.navigate([ '/my-account', 'video-channels' ])
89 err => this.error = err.message
93 onAvatarChange (formData: FormData) {
94 this.videoChannelService.changeVideoChannelAvatar(this.videoChannelToUpdate.name, formData)
97 this.notifier.success(this.i18n('Avatar changed.'))
99 this.videoChannelToUpdate.updateAvatar(data.avatar)
102 err => this.notifier.error(err.message)
106 get maxAvatarSize () {
107 return this.serverService.getConfig().avatar.file.size.max
110 get avatarExtensions () {
111 return this.serverService.getConfig().avatar.file.extensions.join(',')
118 getFormButtonTitle () {
119 return this.i18n('Update')