]>
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' |
f8b2c1b4 | 5 | import { AuthService, Notifier, 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' |
17119e4a | 15 | import { 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 | 22 | export 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 | ||
1378c0d3 C |
55 | this.videoChannelService.getVideoChannel(videoChannelId) |
56 | .subscribe({ | |
57 | next: videoChannelToUpdate => { | |
58 | this.videoChannel = videoChannelToUpdate | |
59 | ||
60 | this.oldSupportField = videoChannelToUpdate.support | |
61 | ||
62 | this.form.patchValue({ | |
63 | 'display-name': videoChannelToUpdate.displayName, | |
64 | description: videoChannelToUpdate.description, | |
65 | support: videoChannelToUpdate.support | |
66 | }) | |
67 | }, | |
08c1efbe | 68 | |
1378c0d3 C |
69 | error: err => this.error = err.message |
70 | }) | |
08c1efbe C |
71 | }) |
72 | } | |
73 | ||
74 | ngOnDestroy () { | |
75 | if (this.paramsSub) this.paramsSub.unsubscribe() | |
76 | } | |
77 | ||
78 | formValidated () { | |
79 | this.error = undefined | |
80 | ||
81 | const body = this.form.value | |
82 | const videoChannelUpdate: VideoChannelUpdate = { | |
83 | displayName: body['display-name'], | |
360329cc | 84 | description: body.description || null, |
1e66b987 C |
85 | support: body.support || null, |
86 | bulkVideosSupportUpdate: body.bulkVideosSupportUpdate || false | |
08c1efbe C |
87 | } |
88 | ||
1378c0d3 C |
89 | this.videoChannelService.updateVideoChannel(this.videoChannel.name, videoChannelUpdate) |
90 | .subscribe({ | |
91 | next: () => { | |
92 | this.authService.refreshUserInformation() | |
f8b2c1b4 | 93 | |
1378c0d3 | 94 | this.notifier.success($localize`Video channel ${videoChannelUpdate.displayName} updated.`) |
f8b2c1b4 | 95 | |
1378c0d3 C |
96 | this.router.navigate([ '/my-library', 'video-channels' ]) |
97 | }, | |
08c1efbe | 98 | |
1378c0d3 C |
99 | error: err => this.error = err.message |
100 | }) | |
08c1efbe C |
101 | } |
102 | ||
52d9f792 | 103 | onAvatarChange (formData: FormData) { |
27ec473f | 104 | this.videoChannelService.changeVideoChannelImage(this.videoChannel.name, formData, 'avatar') |
1378c0d3 C |
105 | .subscribe({ |
106 | next: data => { | |
66357162 | 107 | this.notifier.success($localize`Avatar changed.`) |
52d9f792 | 108 | |
27ec473f | 109 | this.videoChannel.updateAvatar(data.avatar) |
52d9f792 C |
110 | }, |
111 | ||
1378c0d3 | 112 | error: (err: HttpErrorResponse) => genericUploadErrorHandler({ |
1ea7da81 RK |
113 | err, |
114 | name: $localize`avatar`, | |
115 | notifier: this.notifier | |
116 | }) | |
1378c0d3 | 117 | }) |
52d9f792 C |
118 | } |
119 | ||
1ea7da81 | 120 | onAvatarDelete () { |
27ec473f | 121 | this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'avatar') |
1378c0d3 C |
122 | .subscribe({ |
123 | next: () => { | |
1ea7da81 RK |
124 | this.notifier.success($localize`Avatar deleted.`) |
125 | ||
27ec473f | 126 | this.videoChannel.resetAvatar() |
1ea7da81 RK |
127 | }, |
128 | ||
1378c0d3 C |
129 | error: err => this.notifier.error(err.message) |
130 | }) | |
1ea7da81 RK |
131 | } |
132 | ||
cdeddff1 | 133 | onBannerChange (formData: FormData) { |
27ec473f | 134 | this.videoChannelService.changeVideoChannelImage(this.videoChannel.name, formData, 'banner') |
1378c0d3 C |
135 | .subscribe({ |
136 | next: data => { | |
cdeddff1 C |
137 | this.notifier.success($localize`Banner changed.`) |
138 | ||
27ec473f | 139 | this.videoChannel.updateBanner(data.banner) |
cdeddff1 C |
140 | }, |
141 | ||
1378c0d3 | 142 | error: (err: HttpErrorResponse) => genericUploadErrorHandler({ |
cdeddff1 C |
143 | err, |
144 | name: $localize`banner`, | |
145 | notifier: this.notifier | |
146 | }) | |
1378c0d3 | 147 | }) |
cdeddff1 C |
148 | } |
149 | ||
150 | onBannerDelete () { | |
27ec473f | 151 | this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'banner') |
1378c0d3 C |
152 | .subscribe({ |
153 | next: () => { | |
cdeddff1 C |
154 | this.notifier.success($localize`Banner deleted.`) |
155 | ||
27ec473f | 156 | this.videoChannel.resetBanner() |
cdeddff1 C |
157 | }, |
158 | ||
1378c0d3 C |
159 | error: err => this.notifier.error(err.message) |
160 | }) | |
cdeddff1 C |
161 | } |
162 | ||
52d9f792 | 163 | get maxAvatarSize () { |
ba430d75 | 164 | return this.serverConfig.avatar.file.size.max |
52d9f792 C |
165 | } |
166 | ||
167 | get avatarExtensions () { | |
ba430d75 | 168 | return this.serverConfig.avatar.file.extensions.join(',') |
52d9f792 C |
169 | } |
170 | ||
08c1efbe C |
171 | isCreation () { |
172 | return false | |
173 | } | |
174 | ||
175 | getFormButtonTitle () { | |
66357162 | 176 | return $localize`Update` |
08c1efbe | 177 | } |
1e66b987 C |
178 | |
179 | isBulkUpdateVideosDisplayed () { | |
180 | if (this.oldSupportField === undefined) return false | |
181 | ||
182 | return this.oldSupportField !== this.form.value['support'] | |
183 | } | |
08c1efbe | 184 | } |