]>
Commit | Line | Data |
---|---|---|
67ed6552 | 1 | import { Subscription } from 'rxjs' |
cdeddff1 | 2 | import { HttpErrorResponse } from '@angular/common/http' |
c199c427 | 3 | import { Component, OnDestroy, OnInit } from '@angular/core' |
08c1efbe | 4 | import { ActivatedRoute, Router } from '@angular/router' |
a37e9e74 | 5 | import { AuthService, 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' | |
12 | import { FormValidatorService } 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 | }) |
a37e9e74 | 22 | export class VideoChannelUpdateComponent extends VideoChannelEdit 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, |
a37e9e74 | 37 | private serverService: ServerService, |
38 | private redirectService: RedirectService | |
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 | ||
61 | this.oldSupportField = videoChannelToUpdate.support | |
62 | ||
63 | this.form.patchValue({ | |
64 | 'display-name': videoChannelToUpdate.displayName, | |
65 | description: videoChannelToUpdate.description, | |
66 | support: videoChannelToUpdate.support | |
67 | }) | |
68 | }, | |
08c1efbe | 69 | |
9df52d66 C |
70 | error: err => { |
71 | this.error = err.message | |
72 | } | |
1378c0d3 | 73 | }) |
08c1efbe C |
74 | }) |
75 | } | |
76 | ||
77 | ngOnDestroy () { | |
78 | if (this.paramsSub) this.paramsSub.unsubscribe() | |
79 | } | |
80 | ||
81 | formValidated () { | |
82 | this.error = undefined | |
83 | ||
84 | const body = this.form.value | |
85 | const videoChannelUpdate: VideoChannelUpdate = { | |
86 | displayName: body['display-name'], | |
360329cc | 87 | description: body.description || null, |
1e66b987 C |
88 | support: body.support || null, |
89 | bulkVideosSupportUpdate: body.bulkVideosSupportUpdate || false | |
08c1efbe C |
90 | } |
91 | ||
1378c0d3 C |
92 | this.videoChannelService.updateVideoChannel(this.videoChannel.name, videoChannelUpdate) |
93 | .subscribe({ | |
94 | next: () => { | |
95 | this.authService.refreshUserInformation() | |
f8b2c1b4 | 96 | |
1378c0d3 | 97 | this.notifier.success($localize`Video channel ${videoChannelUpdate.displayName} updated.`) |
f8b2c1b4 | 98 | |
a37e9e74 | 99 | this.redirectService.redirectToPreviousRoute([ '/c', this.videoChannel.name ]) |
1378c0d3 | 100 | }, |
08c1efbe | 101 | |
9df52d66 C |
102 | error: err => { |
103 | this.error = err.message | |
104 | } | |
1378c0d3 | 105 | }) |
08c1efbe C |
106 | } |
107 | ||
52d9f792 | 108 | onAvatarChange (formData: FormData) { |
27ec473f | 109 | this.videoChannelService.changeVideoChannelImage(this.videoChannel.name, formData, 'avatar') |
1378c0d3 C |
110 | .subscribe({ |
111 | next: data => { | |
66357162 | 112 | this.notifier.success($localize`Avatar changed.`) |
52d9f792 | 113 | |
d0800f76 | 114 | this.videoChannel.updateAvatar(data.avatars) |
52d9f792 C |
115 | }, |
116 | ||
1378c0d3 | 117 | error: (err: HttpErrorResponse) => genericUploadErrorHandler({ |
1ea7da81 RK |
118 | err, |
119 | name: $localize`avatar`, | |
120 | notifier: this.notifier | |
121 | }) | |
1378c0d3 | 122 | }) |
52d9f792 C |
123 | } |
124 | ||
1ea7da81 | 125 | onAvatarDelete () { |
27ec473f | 126 | this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'avatar') |
1378c0d3 C |
127 | .subscribe({ |
128 | next: () => { | |
1ea7da81 RK |
129 | this.notifier.success($localize`Avatar deleted.`) |
130 | ||
27ec473f | 131 | this.videoChannel.resetAvatar() |
1ea7da81 RK |
132 | }, |
133 | ||
1378c0d3 C |
134 | error: err => this.notifier.error(err.message) |
135 | }) | |
1ea7da81 RK |
136 | } |
137 | ||
cdeddff1 | 138 | onBannerChange (formData: FormData) { |
27ec473f | 139 | this.videoChannelService.changeVideoChannelImage(this.videoChannel.name, formData, 'banner') |
1378c0d3 C |
140 | .subscribe({ |
141 | next: data => { | |
cdeddff1 C |
142 | this.notifier.success($localize`Banner changed.`) |
143 | ||
d0800f76 | 144 | this.videoChannel.updateBanner(data.banners) |
cdeddff1 C |
145 | }, |
146 | ||
1378c0d3 | 147 | error: (err: HttpErrorResponse) => genericUploadErrorHandler({ |
cdeddff1 C |
148 | err, |
149 | name: $localize`banner`, | |
150 | notifier: this.notifier | |
151 | }) | |
1378c0d3 | 152 | }) |
cdeddff1 C |
153 | } |
154 | ||
155 | onBannerDelete () { | |
27ec473f | 156 | this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'banner') |
1378c0d3 C |
157 | .subscribe({ |
158 | next: () => { | |
cdeddff1 C |
159 | this.notifier.success($localize`Banner deleted.`) |
160 | ||
27ec473f | 161 | this.videoChannel.resetBanner() |
cdeddff1 C |
162 | }, |
163 | ||
1378c0d3 C |
164 | error: err => this.notifier.error(err.message) |
165 | }) | |
cdeddff1 C |
166 | } |
167 | ||
52d9f792 | 168 | get maxAvatarSize () { |
ba430d75 | 169 | return this.serverConfig.avatar.file.size.max |
52d9f792 C |
170 | } |
171 | ||
172 | get avatarExtensions () { | |
ba430d75 | 173 | return this.serverConfig.avatar.file.extensions.join(',') |
52d9f792 C |
174 | } |
175 | ||
08c1efbe C |
176 | isCreation () { |
177 | return false | |
178 | } | |
179 | ||
180 | getFormButtonTitle () { | |
66357162 | 181 | return $localize`Update` |
08c1efbe | 182 | } |
1e66b987 C |
183 | |
184 | isBulkUpdateVideosDisplayed () { | |
185 | if (this.oldSupportField === undefined) return false | |
186 | ||
187 | return this.oldSupportField !== this.form.value['support'] | |
188 | } | |
08c1efbe | 189 | } |