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