1 import { Component, OnInit } from '@angular/core'
2 import { SortMeta } from 'primeng/components/common/sortmeta'
3 import { Notifier, ServerService } from '@app/core'
4 import { ConfirmService } from '../../../core'
5 import { RestPagination, RestTable, VideoBlacklistService } from '../../../shared'
6 import { VideoBlacklist, VideoBlacklistType } from '../../../../../../shared'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
8 import { DropdownAction } from '../../../shared/buttons/action-dropdown.component'
9 import { Video } from '../../../shared/video/video.model'
10 import { MarkdownService } from '@app/shared/renderer'
13 selector: 'my-video-blacklist-list',
14 templateUrl: './video-blacklist-list.component.html',
15 styleUrls: [ '../moderation.component.scss' ]
17 export class VideoBlacklistListComponent extends RestTable implements OnInit {
18 blacklist: (VideoBlacklist & { reasonHtml?: string })[] = []
21 sort: SortMeta = { field: 'createdAt', order: 1 }
22 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
23 listBlacklistTypeFilter: VideoBlacklistType = undefined
25 videoBlacklistActions: DropdownAction<VideoBlacklist>[] = []
28 private notifier: Notifier,
29 private serverService: ServerService,
30 private confirmService: ConfirmService,
31 private videoBlacklistService: VideoBlacklistService,
32 private markdownRenderer: MarkdownService,
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
42 this.videoBlacklistActions = [
44 label: this.i18n('Unblacklist'),
45 handler: videoBlacklist => this.removeVideoFromBlacklist(videoBlacklist)
54 getVideoUrl (videoBlacklist: VideoBlacklist) {
55 return Video.buildClientUrl(videoBlacklist.video.uuid)
58 booleanToText (value: boolean) {
59 if (value === true) return this.i18n('yes')
61 return this.i18n('no')
64 toHtml (text: string) {
65 return this.markdownRenderer.textMarkdownToHTML(text)
68 async removeVideoFromBlacklist (entry: VideoBlacklist) {
69 const confirmMessage = this.i18n(
70 'Do you really want to remove this video from the blacklist? It will be available again in the videos list.'
73 const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist'))
74 if (res === false) return
76 this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe(
78 this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name }))
82 err => this.notifier.error(err.message)
86 protected loadData () {
87 this.videoBlacklistService.listBlacklist(this.pagination, this.sort, this.listBlacklistTypeFilter)
90 this.totalRecords = resultList.total
92 this.blacklist = resultList.data
94 for (const element of this.blacklist) {
95 Object.assign(element, { reasonHtml: await this.toHtml(element.reason) })
99 err => this.notifier.error(err.message)