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'
6 VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
7 VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
8 VIDEO_CHANNEL_SUPPORT_VALIDATOR
9 } from '@app/shared/form-validators/video-channel-validators'
10 import { FormValidatorService } from '@app/shared/shared-forms'
11 import { VideoChannel, VideoChannelService } from '@app/shared/shared-main'
12 import { ServerConfig, VideoChannelUpdate } from '@shared/models'
13 import { MyVideoChannelEdit } from './my-video-channel-edit'
16 selector: 'my-video-channel-update',
17 templateUrl: './my-video-channel-edit.component.html',
18 styleUrls: [ './my-video-channel-edit.component.scss' ]
20 export class MyVideoChannelUpdateComponent extends MyVideoChannelEdit implements OnInit, OnDestroy {
22 videoChannelToUpdate: VideoChannel
24 private paramsSub: Subscription
25 private oldSupportField: string
26 private serverConfig: ServerConfig
29 protected formValidatorService: FormValidatorService,
30 private authService: AuthService,
31 private notifier: Notifier,
32 private router: Router,
33 private route: ActivatedRoute,
34 private videoChannelService: VideoChannelService,
35 private serverService: ServerService
41 this.serverConfig = this.serverService.getTmpConfig()
42 this.serverService.getConfig()
43 .subscribe(config => this.serverConfig = config)
46 'display-name': VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
47 description: VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
48 support: VIDEO_CHANNEL_SUPPORT_VALIDATOR,
49 bulkVideosSupportUpdate: null
52 this.paramsSub = this.route.params.subscribe(routeParams => {
53 const videoChannelId = routeParams['videoChannelId']
55 this.videoChannelService.getVideoChannel(videoChannelId).subscribe(
56 videoChannelToUpdate => {
57 this.videoChannelToUpdate = videoChannelToUpdate
59 this.oldSupportField = videoChannelToUpdate.support
61 this.form.patchValue({
62 'display-name': videoChannelToUpdate.displayName,
63 description: videoChannelToUpdate.description,
64 support: videoChannelToUpdate.support
68 err => this.error = err.message
74 if (this.paramsSub) this.paramsSub.unsubscribe()
78 this.error = undefined
80 const body = this.form.value
81 const videoChannelUpdate: VideoChannelUpdate = {
82 displayName: body['display-name'],
83 description: body.description || null,
84 support: body.support || null,
85 bulkVideosSupportUpdate: body.bulkVideosSupportUpdate || false
88 this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.name, videoChannelUpdate).subscribe(
90 this.authService.refreshUserInformation()
92 this.notifier.success($localize`Video channel ${videoChannelUpdate.displayName} updated.`)
94 this.router.navigate([ '/my-library', 'video-channels' ])
97 err => this.error = err.message
101 onAvatarChange (formData: FormData) {
102 this.videoChannelService.changeVideoChannelAvatar(this.videoChannelToUpdate.name, formData)
105 this.notifier.success($localize`Avatar changed.`)
107 this.videoChannelToUpdate.updateAvatar(data.avatar)
110 err => this.notifier.error(err.message)
114 get maxAvatarSize () {
115 return this.serverConfig.avatar.file.size.max
118 get avatarExtensions () {
119 return this.serverConfig.avatar.file.extensions.join(',')
126 getFormButtonTitle () {
127 return $localize`Update`
130 isBulkUpdateVideosDisplayed () {
131 if (this.oldSupportField === undefined) return false
133 return this.oldSupportField !== this.form.value['support']