]>
Commit | Line | Data |
---|---|---|
792dbaf0 | 1 | import { Component, OnInit } from '@angular/core' |
f77eb73b | 2 | import { SortMeta } from 'primeng/api' |
7ccddd7b | 3 | import { Notifier, ServerService } from '@app/core' |
792dbaf0 | 4 | import { ConfirmService } from '../../../core' |
b1d40cff | 5 | import { RestPagination, RestTable, VideoBlacklistService } from '../../../shared' |
7ccddd7b | 6 | import { VideoBlacklist, VideoBlacklistType } from '../../../../../../shared' |
b1d40cff | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
614d1ae9 C |
8 | import { DropdownAction } from '../../../shared/buttons/action-dropdown.component' |
9 | import { Video } from '../../../shared/video/video.model' | |
1506307f | 10 | import { MarkdownService } from '@app/shared/renderer' |
792dbaf0 GS |
11 | |
12 | @Component({ | |
35bf0c83 C |
13 | selector: 'my-video-blacklist-list', |
14 | templateUrl: './video-blacklist-list.component.html', | |
83b5fe9c | 15 | styleUrls: [ '../moderation.component.scss' ] |
792dbaf0 | 16 | }) |
35bf0c83 | 17 | export class VideoBlacklistListComponent extends RestTable implements OnInit { |
41d71344 | 18 | blacklist: (VideoBlacklist & { reasonHtml?: string })[] = [] |
792dbaf0 | 19 | totalRecords = 0 |
e0a92917 RK |
20 | rowsPerPageOptions = [ 20, 50, 100 ] |
21 | rowsPerPage = this.rowsPerPageOptions[0] | |
bb152476 | 22 | sort: SortMeta = { field: 'createdAt', order: -1 } |
792dbaf0 | 23 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
7ccddd7b | 24 | listBlacklistTypeFilter: VideoBlacklistType = undefined |
792dbaf0 | 25 | |
191764f3 | 26 | videoBlacklistActions: DropdownAction<VideoBlacklist>[] = [] |
26b7305a | 27 | |
792dbaf0 | 28 | constructor ( |
f8b2c1b4 | 29 | private notifier: Notifier, |
7ccddd7b | 30 | private serverService: ServerService, |
792dbaf0 | 31 | private confirmService: ConfirmService, |
b1d40cff | 32 | private videoBlacklistService: VideoBlacklistService, |
1506307f | 33 | private markdownRenderer: MarkdownService, |
b1d40cff | 34 | private i18n: I18n |
792dbaf0 GS |
35 | ) { |
36 | super() | |
ba430d75 C |
37 | } |
38 | ||
39 | ngOnInit () { | |
40 | this.serverService.getConfig() | |
41 | .subscribe(config => { | |
e0a92917 | 42 | // don't filter if auto-blacklist is not enabled as this will be the only list |
ba430d75 C |
43 | if (config.autoBlacklist.videos.ofUsers.enabled) { |
44 | this.listBlacklistTypeFilter = VideoBlacklistType.MANUAL | |
45 | } | |
46 | }) | |
26b7305a | 47 | |
ba430d75 | 48 | this.initialize() |
7ccddd7b | 49 | |
26b7305a C |
50 | this.videoBlacklistActions = [ |
51 | { | |
52 | label: this.i18n('Unblacklist'), | |
53 | handler: videoBlacklist => this.removeVideoFromBlacklist(videoBlacklist) | |
54 | } | |
55 | ] | |
792dbaf0 GS |
56 | } |
57 | ||
8e11a1b3 C |
58 | getIdentifier () { |
59 | return 'VideoBlacklistListComponent' | |
60 | } | |
61 | ||
191764f3 C |
62 | getVideoUrl (videoBlacklist: VideoBlacklist) { |
63 | return Video.buildClientUrl(videoBlacklist.video.uuid) | |
64 | } | |
65 | ||
5abb9fbb C |
66 | booleanToText (value: boolean) { |
67 | if (value === true) return this.i18n('yes') | |
68 | ||
69 | return this.i18n('no') | |
70 | } | |
71 | ||
1506307f C |
72 | toHtml (text: string) { |
73 | return this.markdownRenderer.textMarkdownToHTML(text) | |
74 | } | |
75 | ||
191764f3 | 76 | async removeVideoFromBlacklist (entry: VideoBlacklist) { |
b1d40cff | 77 | const confirmMessage = this.i18n( |
26b7305a | 78 | 'Do you really want to remove this video from the blacklist? It will be available again in the videos list.' |
b1d40cff | 79 | ) |
792dbaf0 | 80 | |
b1d40cff | 81 | const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist')) |
1f30a185 | 82 | if (res === false) return |
792dbaf0 | 83 | |
26b7305a | 84 | this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe( |
1f30a185 | 85 | () => { |
f8b2c1b4 | 86 | this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name })) |
1f30a185 C |
87 | this.loadData() |
88 | }, | |
792dbaf0 | 89 | |
f8b2c1b4 | 90 | err => this.notifier.error(err.message) |
792dbaf0 GS |
91 | ) |
92 | } | |
93 | ||
94 | protected loadData () { | |
e0a92917 RK |
95 | this.videoBlacklistService.listBlacklist({ |
96 | pagination: this.pagination, | |
97 | sort: this.sort, | |
98 | search: this.search, | |
99 | type: this.listBlacklistTypeFilter | |
100 | }) | |
792dbaf0 | 101 | .subscribe( |
41d71344 | 102 | async resultList => { |
792dbaf0 | 103 | this.totalRecords = resultList.total |
41d71344 C |
104 | |
105 | this.blacklist = resultList.data | |
106 | ||
107 | for (const element of this.blacklist) { | |
108 | Object.assign(element, { reasonHtml: await this.toHtml(element.reason) }) | |
109 | } | |
792dbaf0 GS |
110 | }, |
111 | ||
f8b2c1b4 | 112 | err => this.notifier.error(err.message) |
792dbaf0 GS |
113 | ) |
114 | } | |
115 | } |