]>
Commit | Line | Data |
---|---|---|
792dbaf0 GS |
1 | import { Component, OnInit } from '@angular/core' |
2 | import { SortMeta } from 'primeng/components/common/sortmeta' | |
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 GS |
19 | totalRecords = 0 |
20 | rowsPerPage = 10 | |
ab998f7b | 21 | sort: SortMeta = { field: 'createdAt', order: 1 } |
792dbaf0 | 22 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
7ccddd7b | 23 | listBlacklistTypeFilter: VideoBlacklistType = undefined |
792dbaf0 | 24 | |
191764f3 | 25 | videoBlacklistActions: DropdownAction<VideoBlacklist>[] = [] |
26b7305a | 26 | |
792dbaf0 | 27 | constructor ( |
f8b2c1b4 | 28 | private notifier: Notifier, |
7ccddd7b | 29 | private serverService: ServerService, |
792dbaf0 | 30 | private confirmService: ConfirmService, |
b1d40cff | 31 | private videoBlacklistService: VideoBlacklistService, |
1506307f | 32 | private markdownRenderer: MarkdownService, |
b1d40cff | 33 | private i18n: I18n |
792dbaf0 GS |
34 | ) { |
35 | super() | |
26b7305a | 36 | |
7ccddd7b JM |
37 | // don't filter if auto-blacklist not enabled as this will be only list |
38 | if (this.serverService.getConfig().autoBlacklist.videos.ofUsers.enabled) { | |
39 | this.listBlacklistTypeFilter = VideoBlacklistType.MANUAL | |
40 | } | |
41 | ||
26b7305a C |
42 | this.videoBlacklistActions = [ |
43 | { | |
44 | label: this.i18n('Unblacklist'), | |
45 | handler: videoBlacklist => this.removeVideoFromBlacklist(videoBlacklist) | |
46 | } | |
47 | ] | |
792dbaf0 GS |
48 | } |
49 | ||
50 | ngOnInit () { | |
24b9417c | 51 | this.initialize() |
792dbaf0 GS |
52 | } |
53 | ||
191764f3 C |
54 | getVideoUrl (videoBlacklist: VideoBlacklist) { |
55 | return Video.buildClientUrl(videoBlacklist.video.uuid) | |
56 | } | |
57 | ||
5abb9fbb C |
58 | booleanToText (value: boolean) { |
59 | if (value === true) return this.i18n('yes') | |
60 | ||
61 | return this.i18n('no') | |
62 | } | |
63 | ||
1506307f C |
64 | toHtml (text: string) { |
65 | return this.markdownRenderer.textMarkdownToHTML(text) | |
66 | } | |
67 | ||
191764f3 | 68 | async removeVideoFromBlacklist (entry: VideoBlacklist) { |
b1d40cff | 69 | const confirmMessage = this.i18n( |
26b7305a | 70 | 'Do you really want to remove this video from the blacklist? It will be available again in the videos list.' |
b1d40cff | 71 | ) |
792dbaf0 | 72 | |
b1d40cff | 73 | const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist')) |
1f30a185 | 74 | if (res === false) return |
792dbaf0 | 75 | |
26b7305a | 76 | this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe( |
1f30a185 | 77 | () => { |
f8b2c1b4 | 78 | this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name })) |
1f30a185 C |
79 | this.loadData() |
80 | }, | |
792dbaf0 | 81 | |
f8b2c1b4 | 82 | err => this.notifier.error(err.message) |
792dbaf0 GS |
83 | ) |
84 | } | |
85 | ||
86 | protected loadData () { | |
7ccddd7b | 87 | this.videoBlacklistService.listBlacklist(this.pagination, this.sort, this.listBlacklistTypeFilter) |
792dbaf0 | 88 | .subscribe( |
41d71344 | 89 | async resultList => { |
792dbaf0 | 90 | this.totalRecords = resultList.total |
41d71344 C |
91 | |
92 | this.blacklist = resultList.data | |
93 | ||
94 | for (const element of this.blacklist) { | |
95 | Object.assign(element, { reasonHtml: await this.toHtml(element.reason) }) | |
96 | } | |
792dbaf0 GS |
97 | }, |
98 | ||
f8b2c1b4 | 99 | err => this.notifier.error(err.message) |
792dbaf0 GS |
100 | ) |
101 | } | |
102 | } |