]>
Commit | Line | Data |
---|---|---|
54e78847 | 1 | import { Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core' |
c729caf6 | 2 | import { AuthService, ConfirmService, Notifier, ScreenService, ServerService } from '@app/core' |
66357162 | 3 | import { BlocklistService, VideoBlockComponent, VideoBlockService, VideoReportComponent } from '@app/shared/shared-moderation' |
3a0fb65c | 4 | import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap' |
c729caf6 | 5 | import { VideoCaption, VideoState } from '@shared/models' |
66357162 C |
6 | import { |
7 | Actor, | |
8 | DropdownAction, | |
9 | DropdownButtonSize, | |
10 | DropdownDirection, | |
11 | RedundancyService, | |
12 | Video, | |
13 | VideoDetails, | |
14 | VideoService | |
15 | } from '../shared-main' | |
f8c00564 | 16 | import { LiveStreamInformationComponent } from '../shared-video-live' |
67ed6552 C |
17 | import { VideoAddToPlaylistComponent } from '../shared-video-playlist' |
18 | import { VideoDownloadComponent } from './video-download.component' | |
3a0fb65c C |
19 | |
20 | export type VideoActionsDisplayType = { | |
21 | playlist?: boolean | |
22 | download?: boolean | |
23 | update?: boolean | |
24 | blacklist?: boolean | |
25 | delete?: boolean | |
26 | report?: boolean | |
b764380a | 27 | duplicate?: boolean |
d473fd94 | 28 | mute?: boolean |
f8c00564 | 29 | liveInfo?: boolean |
b46cf4b9 | 30 | removeFiles?: boolean |
ad5db104 | 31 | transcoding?: boolean |
c729caf6 | 32 | editor?: boolean |
3a0fb65c C |
33 | } |
34 | ||
35 | @Component({ | |
36 | selector: 'my-video-actions-dropdown', | |
37 | templateUrl: './video-actions-dropdown.component.html', | |
38 | styleUrls: [ './video-actions-dropdown.component.scss' ] | |
39 | }) | |
4da22f64 | 40 | export class VideoActionsDropdownComponent implements OnChanges { |
2f5d2ec5 C |
41 | @ViewChild('playlistDropdown') playlistDropdown: NgbDropdown |
42 | @ViewChild('playlistAdd') playlistAdd: VideoAddToPlaylistComponent | |
3a0fb65c | 43 | |
2f5d2ec5 C |
44 | @ViewChild('videoDownloadModal') videoDownloadModal: VideoDownloadComponent |
45 | @ViewChild('videoReportModal') videoReportModal: VideoReportComponent | |
5baee5fc | 46 | @ViewChild('videoBlockModal') videoBlockModal: VideoBlockComponent |
f8c00564 | 47 | @ViewChild('liveStreamInformationModal') liveStreamInformationModal: LiveStreamInformationComponent |
3a0fb65c C |
48 | |
49 | @Input() video: Video | VideoDetails | |
8ba9c205 | 50 | @Input() videoCaptions: VideoCaption[] = [] |
3a0fb65c C |
51 | |
52 | @Input() displayOptions: VideoActionsDisplayType = { | |
53 | playlist: false, | |
54 | download: true, | |
55 | update: true, | |
56 | blacklist: true, | |
57 | delete: true, | |
b764380a | 58 | report: true, |
d473fd94 | 59 | duplicate: true, |
f8c00564 | 60 | mute: true, |
ad5db104 C |
61 | liveInfo: false, |
62 | removeFiles: false, | |
c729caf6 C |
63 | transcoding: false, |
64 | editor: true | |
3a0fb65c | 65 | } |
8dfceec4 | 66 | @Input() placement = 'left' |
3a0fb65c C |
67 | |
68 | @Input() label: string | |
69 | ||
70 | @Input() buttonStyled = false | |
71 | @Input() buttonSize: DropdownButtonSize = 'normal' | |
72 | @Input() buttonDirection: DropdownDirection = 'vertical' | |
73 | ||
b46cf4b9 | 74 | @Output() videoFilesRemoved = new EventEmitter() |
3a0fb65c | 75 | @Output() videoRemoved = new EventEmitter() |
5baee5fc RK |
76 | @Output() videoUnblocked = new EventEmitter() |
77 | @Output() videoBlocked = new EventEmitter() | |
d473fd94 | 78 | @Output() videoAccountMuted = new EventEmitter() |
ad5db104 | 79 | @Output() transcodingCreated = new EventEmitter() |
689a4f69 | 80 | @Output() modalOpened = new EventEmitter() |
3a0fb65c C |
81 | |
82 | videoActions: DropdownAction<{ video: Video }>[][] = [] | |
83 | ||
84 | private loaded = false | |
85 | ||
86 | constructor ( | |
87 | private authService: AuthService, | |
88 | private notifier: Notifier, | |
89 | private confirmService: ConfirmService, | |
d473fd94 | 90 | private blocklistService: BlocklistService, |
5baee5fc | 91 | private videoBlocklistService: VideoBlockService, |
3a0fb65c C |
92 | private screenService: ScreenService, |
93 | private videoService: VideoService, | |
c729caf6 C |
94 | private redundancyService: RedundancyService, |
95 | private serverService: ServerService | |
3a0fb65c C |
96 | ) { } |
97 | ||
98 | get user () { | |
99 | return this.authService.getUser() | |
100 | } | |
101 | ||
102 | ngOnChanges () { | |
1c8ddbfa C |
103 | if (this.loaded) { |
104 | this.loaded = false | |
3bc68dfd | 105 | if (this.playlistAdd) this.playlistAdd.reload() |
1c8ddbfa C |
106 | } |
107 | ||
3a0fb65c C |
108 | this.buildActions() |
109 | } | |
110 | ||
111 | isUserLoggedIn () { | |
112 | return this.authService.isLoggedIn() | |
113 | } | |
114 | ||
115 | loadDropdownInformation () { | |
116 | if (!this.isUserLoggedIn() || this.loaded === true) return | |
117 | ||
118 | this.loaded = true | |
119 | ||
120 | if (this.displayOptions.playlist) this.playlistAdd.load() | |
121 | } | |
122 | ||
123 | /* Show modals */ | |
124 | ||
125 | showDownloadModal () { | |
689a4f69 C |
126 | this.modalOpened.emit() |
127 | ||
8ba9c205 | 128 | this.videoDownloadModal.show(this.video as VideoDetails, this.videoCaptions) |
3a0fb65c C |
129 | } |
130 | ||
131 | showReportModal () { | |
689a4f69 C |
132 | this.modalOpened.emit() |
133 | ||
3a0fb65c C |
134 | this.videoReportModal.show() |
135 | } | |
136 | ||
5baee5fc | 137 | showBlockModal () { |
689a4f69 C |
138 | this.modalOpened.emit() |
139 | ||
3cfa8176 | 140 | this.videoBlockModal.show([ this.video ]) |
3a0fb65c C |
141 | } |
142 | ||
f8c00564 C |
143 | showLiveInfoModal (video: Video) { |
144 | this.modalOpened.emit() | |
145 | ||
146 | this.liveStreamInformationModal.show(video) | |
147 | } | |
148 | ||
3a0fb65c C |
149 | /* Actions checker */ |
150 | ||
151 | isVideoUpdatable () { | |
152 | return this.video.isUpdatableBy(this.user) | |
153 | } | |
154 | ||
c729caf6 C |
155 | isVideoEditable () { |
156 | return this.serverService.getHTMLConfig().videoEditor.enabled && | |
157 | this.video.state?.id === VideoState.PUBLISHED && | |
158 | this.video.isUpdatableBy(this.user) | |
159 | } | |
160 | ||
3a0fb65c C |
161 | isVideoRemovable () { |
162 | return this.video.isRemovableBy(this.user) | |
163 | } | |
164 | ||
5baee5fc RK |
165 | isVideoBlockable () { |
166 | return this.video.isBlockableBy(this.user) | |
3a0fb65c C |
167 | } |
168 | ||
5baee5fc RK |
169 | isVideoUnblockable () { |
170 | return this.video.isUnblockableBy(this.user) | |
3a0fb65c C |
171 | } |
172 | ||
f8c00564 C |
173 | isVideoLiveInfoAvailable () { |
174 | return this.video.isLiveInfoAvailableBy(this.user) | |
175 | } | |
176 | ||
72675ebe | 177 | isVideoDownloadable () { |
a5cf76af C |
178 | return this.video && |
179 | this.video.isLive !== true && | |
180 | this.video instanceof VideoDetails && | |
181 | this.video.downloadEnabled | |
72675ebe C |
182 | } |
183 | ||
b764380a | 184 | canVideoBeDuplicated () { |
17b7d4b3 | 185 | return !this.video.isLive && this.video.canBeDuplicatedBy(this.user) |
b764380a C |
186 | } |
187 | ||
d473fd94 RK |
188 | isVideoAccountMutable () { |
189 | return this.video.account.id !== this.user.account.id | |
190 | } | |
191 | ||
b46cf4b9 | 192 | canRemoveVideoFiles () { |
ad5db104 C |
193 | return this.video.canRemoveFiles(this.user) |
194 | } | |
195 | ||
196 | canRunTranscoding () { | |
197 | return this.video.canRunTranscoding(this.user) | |
b46cf4b9 C |
198 | } |
199 | ||
3a0fb65c C |
200 | /* Action handlers */ |
201 | ||
5baee5fc | 202 | async unblockVideo () { |
bc844338 | 203 | const confirmMessage = $localize`Do you really want to unblock ${this.video.name}? It will be available again in the videos list.` |
3a0fb65c | 204 | |
bc844338 | 205 | const res = await this.confirmService.confirm(confirmMessage, $localize`Unblock ${this.video.name}`) |
3a0fb65c C |
206 | if (res === false) return |
207 | ||
d473fd94 | 208 | this.videoBlocklistService.unblockVideo(this.video.id) |
1378c0d3 C |
209 | .subscribe({ |
210 | next: () => { | |
66357162 | 211 | this.notifier.success($localize`Video ${this.video.name} unblocked.`) |
3a0fb65c | 212 | |
d473fd94 | 213 | this.video.blacklisted = false |
2760b454 | 214 | this.video.blacklistedReason = null |
3a0fb65c | 215 | |
d473fd94 RK |
216 | this.videoUnblocked.emit() |
217 | }, | |
3a0fb65c | 218 | |
1378c0d3 C |
219 | error: err => this.notifier.error(err.message) |
220 | }) | |
3a0fb65c C |
221 | } |
222 | ||
223 | async removeVideo () { | |
689a4f69 C |
224 | this.modalOpened.emit() |
225 | ||
bc844338 | 226 | let message = $localize`Do you really want to delete ${this.video.name}?` |
d846d99c C |
227 | if (this.video.isLive) { |
228 | message += ' ' + $localize`The live stream will be automatically terminated.` | |
229 | } | |
230 | ||
bc844338 | 231 | const res = await this.confirmService.confirm(message, $localize`Delete ${this.video.name}`) |
3a0fb65c C |
232 | if (res === false) return |
233 | ||
234 | this.videoService.removeVideo(this.video.id) | |
1378c0d3 C |
235 | .subscribe({ |
236 | next: () => { | |
66357162 | 237 | this.notifier.success($localize`Video ${this.video.name} deleted.`) |
3a0fb65c C |
238 | this.videoRemoved.emit() |
239 | }, | |
240 | ||
1378c0d3 C |
241 | error: err => this.notifier.error(err.message) |
242 | }) | |
3a0fb65c C |
243 | } |
244 | ||
b764380a C |
245 | duplicateVideo () { |
246 | this.redundancyService.addVideoRedundancy(this.video) | |
1378c0d3 C |
247 | .subscribe({ |
248 | next: () => { | |
bc844338 | 249 | const message = $localize`${this.video.name} will be duplicated by your instance.` |
d473fd94 RK |
250 | this.notifier.success(message) |
251 | }, | |
b764380a | 252 | |
1378c0d3 C |
253 | error: err => this.notifier.error(err.message) |
254 | }) | |
d473fd94 RK |
255 | } |
256 | ||
257 | muteVideoAccount () { | |
258 | const params = { nameWithHost: Actor.CREATE_BY_STRING(this.video.account.name, this.video.account.host) } | |
259 | ||
260 | this.blocklistService.blockAccountByUser(params) | |
1378c0d3 C |
261 | .subscribe({ |
262 | next: () => { | |
66357162 | 263 | this.notifier.success($localize`Account ${params.nameWithHost} muted.`) |
d473fd94 RK |
264 | this.videoAccountMuted.emit() |
265 | }, | |
266 | ||
1378c0d3 C |
267 | error: err => this.notifier.error(err.message) |
268 | }) | |
b764380a C |
269 | } |
270 | ||
b46cf4b9 C |
271 | async removeVideoFiles (video: Video, type: 'hls' | 'webtorrent') { |
272 | const confirmMessage = $localize`Do you really want to remove "${this.video.name}" files?` | |
273 | ||
274 | const res = await this.confirmService.confirm(confirmMessage, $localize`Remove "${this.video.name}" files`) | |
275 | if (res === false) return | |
276 | ||
277 | this.videoService.removeVideoFiles([ video.id ], type) | |
278 | .subscribe({ | |
279 | next: () => { | |
280 | this.notifier.success($localize`Removed files of ${video.name}.`) | |
281 | this.videoFilesRemoved.emit() | |
282 | }, | |
283 | ||
284 | error: err => this.notifier.error(err.message) | |
285 | }) | |
286 | } | |
287 | ||
ad5db104 C |
288 | runTranscoding (video: Video, type: 'hls' | 'webtorrent') { |
289 | this.videoService.runTranscoding([ video.id ], type) | |
290 | .subscribe({ | |
291 | next: () => { | |
292 | this.notifier.success($localize`Transcoding jobs created for ${video.name}.`) | |
293 | this.transcodingCreated.emit() | |
294 | }, | |
295 | ||
296 | error: err => this.notifier.error(err.message) | |
297 | }) | |
298 | } | |
299 | ||
5baee5fc RK |
300 | onVideoBlocked () { |
301 | this.videoBlocked.emit() | |
3a0fb65c C |
302 | } |
303 | ||
304 | getPlaylistDropdownPlacement () { | |
305 | if (this.screenService.isInSmallView()) { | |
306 | return 'bottom-right' | |
307 | } | |
308 | ||
309 | return 'bottom-left bottom-right' | |
310 | } | |
311 | ||
312 | private buildActions () { | |
f238aec5 C |
313 | this.videoActions = [ |
314 | [ | |
3a0fb65c | 315 | { |
66357162 | 316 | label: $localize`Save to playlist`, |
3a0fb65c | 317 | handler: () => this.playlistDropdown.toggle(), |
f238aec5 | 318 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.playlist, |
3a0fb65c C |
319 | iconName: 'playlist-add' |
320 | } | |
f238aec5 | 321 | ], |
d473fd94 | 322 | [ // actions regarding the video |
3a0fb65c | 323 | { |
66357162 | 324 | label: $localize`Download`, |
3a0fb65c | 325 | handler: () => this.showDownloadModal(), |
72675ebe | 326 | isDisplayed: () => this.displayOptions.download && this.isVideoDownloadable(), |
3a0fb65c C |
327 | iconName: 'download' |
328 | }, | |
f8c00564 C |
329 | { |
330 | label: $localize`Display live information`, | |
331 | handler: ({ video }) => this.showLiveInfoModal(video), | |
3bc68dfd | 332 | isDisplayed: () => this.displayOptions.liveInfo && this.isVideoLiveInfoAvailable(), |
f8c00564 C |
333 | iconName: 'live' |
334 | }, | |
3a0fb65c | 335 | { |
66357162 | 336 | label: $localize`Update`, |
3a0fb65c C |
337 | linkBuilder: ({ video }) => [ '/videos/update', video.uuid ], |
338 | iconName: 'edit', | |
f238aec5 | 339 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.update && this.isVideoUpdatable() |
3a0fb65c | 340 | }, |
c729caf6 C |
341 | { |
342 | label: $localize`Editor`, | |
343 | linkBuilder: ({ video }) => [ '/video-editor/edit', video.uuid ], | |
344 | iconName: 'film', | |
345 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.editor && this.isVideoEditable() | |
346 | }, | |
3a0fb65c | 347 | { |
66357162 | 348 | label: $localize`Block`, |
5baee5fc | 349 | handler: () => this.showBlockModal(), |
3a0fb65c | 350 | iconName: 'no', |
5baee5fc | 351 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoBlockable() |
3a0fb65c C |
352 | }, |
353 | { | |
66357162 | 354 | label: $localize`Unblock`, |
5baee5fc | 355 | handler: () => this.unblockVideo(), |
3a0fb65c | 356 | iconName: 'undo', |
5baee5fc | 357 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoUnblockable() |
3a0fb65c | 358 | }, |
b764380a | 359 | { |
66357162 | 360 | label: $localize`Mirror`, |
b764380a C |
361 | handler: () => this.duplicateVideo(), |
362 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.duplicate && this.canVideoBeDuplicated(), | |
363 | iconName: 'cloud-download' | |
364 | }, | |
3a0fb65c | 365 | { |
66357162 | 366 | label: $localize`Delete`, |
3a0fb65c | 367 | handler: () => this.removeVideo(), |
f238aec5 | 368 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.delete && this.isVideoRemovable(), |
3a0fb65c | 369 | iconName: 'delete' |
d473fd94 | 370 | }, |
3a0fb65c | 371 | { |
66357162 | 372 | label: $localize`Report`, |
3a0fb65c | 373 | handler: () => this.showReportModal(), |
f238aec5 | 374 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.report, |
c41c0e28 | 375 | iconName: 'flag' |
3a0fb65c | 376 | } |
d473fd94 | 377 | ], |
b46cf4b9 | 378 | [ |
ad5db104 C |
379 | { |
380 | label: $localize`Run HLS transcoding`, | |
381 | handler: ({ video }) => this.runTranscoding(video, 'hls'), | |
382 | isDisplayed: () => this.displayOptions.transcoding && this.canRunTranscoding(), | |
383 | iconName: 'cog' | |
384 | }, | |
385 | { | |
386 | label: $localize`Run WebTorrent transcoding`, | |
387 | handler: ({ video }) => this.runTranscoding(video, 'webtorrent'), | |
388 | isDisplayed: () => this.displayOptions.transcoding && this.canRunTranscoding(), | |
389 | iconName: 'cog' | |
390 | }, | |
b46cf4b9 C |
391 | { |
392 | label: $localize`Delete HLS files`, | |
393 | handler: ({ video }) => this.removeVideoFiles(video, 'hls'), | |
394 | isDisplayed: () => this.displayOptions.removeFiles && this.canRemoveVideoFiles(), | |
395 | iconName: 'delete' | |
396 | }, | |
397 | { | |
398 | label: $localize`Delete WebTorrent files`, | |
399 | handler: ({ video }) => this.removeVideoFiles(video, 'webtorrent'), | |
400 | isDisplayed: () => this.displayOptions.removeFiles && this.canRemoveVideoFiles(), | |
401 | iconName: 'delete' | |
402 | } | |
403 | ], | |
d473fd94 RK |
404 | [ // actions regarding the account/its server |
405 | { | |
66357162 | 406 | label: $localize`Mute account`, |
d473fd94 RK |
407 | handler: () => this.muteVideoAccount(), |
408 | isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.mute && this.isVideoAccountMutable(), | |
409 | iconName: 'no' | |
410 | } | |
f238aec5 C |
411 | ] |
412 | ] | |
3a0fb65c C |
413 | } |
414 | } |