]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-library/+my-video-channels/my-video-channel-update.component.ts
Merge branch 'release/3.3.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / +my-video-channels / my-video-channel-update.component.ts
CommitLineData
67ed6552 1import { Subscription } from 'rxjs'
cdeddff1 2import { HttpErrorResponse } from '@angular/common/http'
c199c427 3import { Component, OnDestroy, OnInit } from '@angular/core'
08c1efbe 4import { ActivatedRoute, Router } from '@angular/router'
f8b2c1b4 5import { AuthService, Notifier, ServerService } from '@app/core'
f6d6e7f8 6import { genericUploadErrorHandler } from '@app/helpers'
7ed1edbb
C
7import {
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'
12import { FormValidatorService } from '@app/shared/shared-forms'
67ed6552 13import { VideoChannel, VideoChannelService } from '@app/shared/shared-main'
2989628b 14import { HTMLServerConfig, VideoChannelUpdate } from '@shared/models'
17119e4a 15import { MyVideoChannelEdit } from './my-video-channel-edit'
08c1efbe
C
16
17@Component({
17119e4a
C
18 selector: 'my-video-channel-update',
19 templateUrl: './my-video-channel-edit.component.html',
20 styleUrls: [ './my-video-channel-edit.component.scss' ]
08c1efbe 21})
17119e4a 22export class MyVideoChannelUpdateComponent extends MyVideoChannelEdit implements OnInit, OnDestroy {
08c1efbe 23 error: string
27ec473f 24 videoChannel: VideoChannel
c199c427 25
08c1efbe 26 private paramsSub: Subscription
1e66b987 27 private oldSupportField: string
2989628b 28 private serverConfig: HTMLServerConfig
08c1efbe
C
29
30 constructor (
d18d6478 31 protected formValidatorService: FormValidatorService,
95166f9a 32 private authService: AuthService,
f8b2c1b4 33 private notifier: Notifier,
08c1efbe
C
34 private router: Router,
35 private route: ActivatedRoute,
b1d40cff 36 private videoChannelService: VideoChannelService,
52d9f792 37 private serverService: ServerService
08c1efbe
C
38 ) {
39 super()
40 }
41
08c1efbe 42 ngOnInit () {
2989628b 43 this.serverConfig = this.serverService.getHTMLConfig()
ba430d75 44
d18d6478 45 this.buildForm({
7ed1edbb
C
46 'display-name': VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
47 description: VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
48 support: VIDEO_CHANNEL_SUPPORT_VALIDATOR,
1e66b987 49 bulkVideosSupportUpdate: null
d18d6478 50 })
08c1efbe
C
51
52 this.paramsSub = this.route.params.subscribe(routeParams => {
53 const videoChannelId = routeParams['videoChannelId']
54
55 this.videoChannelService.getVideoChannel(videoChannelId).subscribe(
56 videoChannelToUpdate => {
27ec473f 57 this.videoChannel = videoChannelToUpdate
08c1efbe 58
1e66b987
C
59 this.oldSupportField = videoChannelToUpdate.support
60
08c1efbe
C
61 this.form.patchValue({
62 'display-name': videoChannelToUpdate.displayName,
63 description: videoChannelToUpdate.description,
64 support: videoChannelToUpdate.support
65 })
66 },
67
68 err => this.error = err.message
69 )
70 })
71 }
72
73 ngOnDestroy () {
74 if (this.paramsSub) this.paramsSub.unsubscribe()
75 }
76
77 formValidated () {
78 this.error = undefined
79
80 const body = this.form.value
81 const videoChannelUpdate: VideoChannelUpdate = {
82 displayName: body['display-name'],
360329cc 83 description: body.description || null,
1e66b987
C
84 support: body.support || null,
85 bulkVideosSupportUpdate: body.bulkVideosSupportUpdate || false
08c1efbe
C
86 }
87
27ec473f 88 this.videoChannelService.updateVideoChannel(this.videoChannel.name, videoChannelUpdate).subscribe(
08c1efbe 89 () => {
95166f9a 90 this.authService.refreshUserInformation()
f8b2c1b4 91
66357162 92 this.notifier.success($localize`Video channel ${videoChannelUpdate.displayName} updated.`)
f8b2c1b4 93
17119e4a 94 this.router.navigate([ '/my-library', 'video-channels' ])
08c1efbe
C
95 },
96
97 err => this.error = err.message
98 )
99 }
100
52d9f792 101 onAvatarChange (formData: FormData) {
27ec473f 102 this.videoChannelService.changeVideoChannelImage(this.videoChannel.name, formData, 'avatar')
52d9f792
C
103 .subscribe(
104 data => {
66357162 105 this.notifier.success($localize`Avatar changed.`)
52d9f792 106
27ec473f 107 this.videoChannel.updateAvatar(data.avatar)
52d9f792
C
108 },
109
f6d6e7f8 110 (err: HttpErrorResponse) => genericUploadErrorHandler({
1ea7da81
RK
111 err,
112 name: $localize`avatar`,
113 notifier: this.notifier
114 })
52d9f792
C
115 )
116 }
117
1ea7da81 118 onAvatarDelete () {
27ec473f 119 this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'avatar')
1ea7da81
RK
120 .subscribe(
121 data => {
122 this.notifier.success($localize`Avatar deleted.`)
123
27ec473f 124 this.videoChannel.resetAvatar()
1ea7da81
RK
125 },
126
127 err => this.notifier.error(err.message)
128 )
129 }
130
cdeddff1 131 onBannerChange (formData: FormData) {
27ec473f 132 this.videoChannelService.changeVideoChannelImage(this.videoChannel.name, formData, 'banner')
cdeddff1
C
133 .subscribe(
134 data => {
135 this.notifier.success($localize`Banner changed.`)
136
27ec473f 137 this.videoChannel.updateBanner(data.banner)
cdeddff1
C
138 },
139
f6d6e7f8 140 (err: HttpErrorResponse) => genericUploadErrorHandler({
cdeddff1
C
141 err,
142 name: $localize`banner`,
143 notifier: this.notifier
144 })
145 )
146 }
147
148 onBannerDelete () {
27ec473f 149 this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'banner')
cdeddff1
C
150 .subscribe(
151 data => {
152 this.notifier.success($localize`Banner deleted.`)
153
27ec473f 154 this.videoChannel.resetBanner()
cdeddff1
C
155 },
156
157 err => this.notifier.error(err.message)
158 )
159 }
160
52d9f792 161 get maxAvatarSize () {
ba430d75 162 return this.serverConfig.avatar.file.size.max
52d9f792
C
163 }
164
165 get avatarExtensions () {
ba430d75 166 return this.serverConfig.avatar.file.extensions.join(',')
52d9f792
C
167 }
168
08c1efbe
C
169 isCreation () {
170 return false
171 }
172
173 getFormButtonTitle () {
66357162 174 return $localize`Update`
08c1efbe 175 }
1e66b987
C
176
177 isBulkUpdateVideosDisplayed () {
178 if (this.oldSupportField === undefined) return false
179
180 return this.oldSupportField !== this.form.value['support']
181 }
08c1efbe 182}