1 import { Subscription } from 'rxjs'
2 import { HttpErrorResponse } from '@angular/common/http'
3 import { Component, OnDestroy, OnInit } from '@angular/core'
4 import { ActivatedRoute, Router } from '@angular/router'
5 import { AuthService, Notifier, ServerService } from '@app/core'
6 import { genericUploadErrorHandler } from '@app/helpers'
8 VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
9 VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
10 VIDEO_CHANNEL_SUPPORT_VALIDATOR
11 } from '@app/shared/form-validators/video-channel-validators'
12 import { FormValidatorService } from '@app/shared/shared-forms'
13 import { VideoChannel, VideoChannelService } from '@app/shared/shared-main'
14 import { HTMLServerConfig, VideoChannelUpdate } from '@shared/models'
15 import { MyVideoChannelEdit } from './my-video-channel-edit'
18 selector: 'my-video-channel-update',
19 templateUrl: './my-video-channel-edit.component.html',
20 styleUrls: [ './my-video-channel-edit.component.scss' ]
22 export class MyVideoChannelUpdateComponent extends MyVideoChannelEdit implements OnInit, OnDestroy {
24 videoChannel: VideoChannel
26 private paramsSub: Subscription
27 private oldSupportField: string
28 private serverConfig: HTMLServerConfig
31 protected formValidatorService: FormValidatorService,
32 private authService: AuthService,
33 private notifier: Notifier,
34 private router: Router,
35 private route: ActivatedRoute,
36 private videoChannelService: VideoChannelService,
37 private serverService: ServerService
43 this.serverConfig = this.serverService.getHTMLConfig()
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)
57 next: videoChannelToUpdate => {
58 this.videoChannel = videoChannelToUpdate
60 this.oldSupportField = videoChannelToUpdate.support
62 this.form.patchValue({
63 'display-name': videoChannelToUpdate.displayName,
64 description: videoChannelToUpdate.description,
65 support: videoChannelToUpdate.support
70 this.error = err.message
77 if (this.paramsSub) this.paramsSub.unsubscribe()
81 this.error = undefined
83 const body = this.form.value
84 const videoChannelUpdate: VideoChannelUpdate = {
85 displayName: body['display-name'],
86 description: body.description || null,
87 support: body.support || null,
88 bulkVideosSupportUpdate: body.bulkVideosSupportUpdate || false
91 this.videoChannelService.updateVideoChannel(this.videoChannel.name, videoChannelUpdate)
94 this.authService.refreshUserInformation()
96 this.notifier.success($localize`Video channel ${videoChannelUpdate.displayName} updated.`)
98 this.router.navigate([ '/my-library', 'video-channels' ])
102 this.error = err.message
107 onAvatarChange (formData: FormData) {
108 this.videoChannelService.changeVideoChannelImage(this.videoChannel.name, formData, 'avatar')
111 this.notifier.success($localize`Avatar changed.`)
113 this.videoChannel.updateAvatar(data.avatar)
116 error: (err: HttpErrorResponse) => genericUploadErrorHandler({
118 name: $localize`avatar`,
119 notifier: this.notifier
125 this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'avatar')
128 this.notifier.success($localize`Avatar deleted.`)
130 this.videoChannel.resetAvatar()
133 error: err => this.notifier.error(err.message)
137 onBannerChange (formData: FormData) {
138 this.videoChannelService.changeVideoChannelImage(this.videoChannel.name, formData, 'banner')
141 this.notifier.success($localize`Banner changed.`)
143 this.videoChannel.updateBanner(data.banner)
146 error: (err: HttpErrorResponse) => genericUploadErrorHandler({
148 name: $localize`banner`,
149 notifier: this.notifier
155 this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'banner')
158 this.notifier.success($localize`Banner deleted.`)
160 this.videoChannel.resetBanner()
163 error: err => this.notifier.error(err.message)
167 get maxAvatarSize () {
168 return this.serverConfig.avatar.file.size.max
171 get avatarExtensions () {
172 return this.serverConfig.avatar.file.extensions.join(',')
179 getFormButtonTitle () {
180 return $localize`Update`
183 isBulkUpdateVideosDisplayed () {
184 if (this.oldSupportField === undefined) return false
186 return this.oldSupportField !== this.form.value['support']