1 import { Subscription } from 'rxjs'
2 import { Component, OnDestroy, OnInit } from '@angular/core'
3 import { ActivatedRoute, Router } from '@angular/router'
4 import { AuthService, Notifier, ServerService } from '@app/core'
5 import { FormValidatorService, VideoChannelValidatorsService } from '@app/shared/shared-forms'
6 import { VideoChannel, VideoChannelService } from '@app/shared/shared-main'
7 import { ServerConfig, VideoChannelUpdate } from '@shared/models'
8 import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit'
11 selector: 'my-account-video-channel-update',
12 templateUrl: './my-account-video-channel-edit.component.html',
13 styleUrls: [ './my-account-video-channel-edit.component.scss' ]
15 export class MyAccountVideoChannelUpdateComponent extends MyAccountVideoChannelEdit implements OnInit, OnDestroy {
17 videoChannelToUpdate: VideoChannel
19 private paramsSub: Subscription
20 private oldSupportField: string
21 private serverConfig: ServerConfig
24 protected formValidatorService: FormValidatorService,
25 private authService: AuthService,
26 private videoChannelValidatorsService: VideoChannelValidatorsService,
27 private notifier: Notifier,
28 private router: Router,
29 private route: ActivatedRoute,
30 private videoChannelService: VideoChannelService,
31 private serverService: ServerService
37 this.serverConfig = this.serverService.getTmpConfig()
38 this.serverService.getConfig()
39 .subscribe(config => this.serverConfig = config)
42 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME,
43 description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION,
44 support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT,
45 bulkVideosSupportUpdate: null
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.oldSupportField = videoChannelToUpdate.support
57 this.form.patchValue({
58 'display-name': videoChannelToUpdate.displayName,
59 description: videoChannelToUpdate.description,
60 support: videoChannelToUpdate.support
64 err => this.error = err.message
70 if (this.paramsSub) this.paramsSub.unsubscribe()
74 this.error = undefined
76 const body = this.form.value
77 const videoChannelUpdate: VideoChannelUpdate = {
78 displayName: body['display-name'],
79 description: body.description || null,
80 support: body.support || null,
81 bulkVideosSupportUpdate: body.bulkVideosSupportUpdate || false
84 this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.name, videoChannelUpdate).subscribe(
86 this.authService.refreshUserInformation()
88 this.notifier.success($localize`Video channel ${videoChannelUpdate.displayName} updated.`)
90 this.router.navigate([ '/my-account', 'video-channels' ])
93 err => this.error = err.message
97 onAvatarChange (formData: FormData) {
98 this.videoChannelService.changeVideoChannelAvatar(this.videoChannelToUpdate.name, formData)
101 this.notifier.success($localize`Avatar changed.`)
103 this.videoChannelToUpdate.updateAvatar(data.avatar)
106 err => this.notifier.error(err.message)
110 get maxAvatarSize () {
111 return this.serverConfig.avatar.file.size.max
114 get avatarExtensions () {
115 return this.serverConfig.avatar.file.extensions.join(',')
122 getFormButtonTitle () {
123 return $localize`Update`
126 isBulkUpdateVideosDisplayed () {
127 if (this.oldSupportField === undefined) return false
129 return this.oldSupportField !== this.form.value['support']