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 { 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 {
21 videoChannelToUpdate: VideoChannel
23 private paramsSub: Subscription
26 protected formValidatorService: FormValidatorService,
27 private authService: AuthService,
28 private videoChannelValidatorsService: VideoChannelValidatorsService,
29 private notificationsService: NotificationsService,
30 private router: Router,
31 private route: ActivatedRoute,
32 private videoChannelService: VideoChannelService,
34 private serverService: ServerService
41 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME,
42 description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION,
43 support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT
46 this.paramsSub = this.route.params.subscribe(routeParams => {
47 const videoChannelId = routeParams['videoChannelId']
49 this.videoChannelService.getVideoChannel(videoChannelId).subscribe(
50 videoChannelToUpdate => {
51 this.videoChannelToUpdate = videoChannelToUpdate
53 this.form.patchValue({
54 'display-name': videoChannelToUpdate.displayName,
55 description: videoChannelToUpdate.description,
56 support: videoChannelToUpdate.support
60 err => this.error = err.message
66 if (this.paramsSub) this.paramsSub.unsubscribe()
70 this.error = undefined
72 const body = this.form.value
73 const videoChannelUpdate: VideoChannelUpdate = {
74 displayName: body['display-name'],
75 description: body.description || null,
76 support: body.support || null
79 this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.name, videoChannelUpdate).subscribe(
81 this.authService.refreshUserInformation()
82 this.notificationsService.success(
84 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.notificationsService.success(this.i18n('Success'), this.i18n('Avatar changed.'))
99 this.videoChannelToUpdate.updateAvatar(data.avatar)
102 err => this.notificationsService.error(this.i18n('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')