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