1 import { Component, OnInit } from '@angular/core'
2 import { SortMeta } from 'primeng/api'
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 })[] = []
20 rowsPerPageOptions = [ 20, 50, 100 ]
21 rowsPerPage = this.rowsPerPageOptions[0]
22 sort: SortMeta = { field: 'createdAt', order: -1 }
23 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
24 listBlacklistTypeFilter: VideoBlacklistType = undefined
26 videoBlacklistActions: DropdownAction<VideoBlacklist>[] = []
29 private notifier: Notifier,
30 private serverService: ServerService,
31 private confirmService: ConfirmService,
32 private videoBlacklistService: VideoBlacklistService,
33 private markdownRenderer: MarkdownService,
40 this.serverService.getConfig()
41 .subscribe(config => {
42 // don't filter if auto-blacklist is not enabled as this will be the only list
43 if (config.autoBlacklist.videos.ofUsers.enabled) {
44 this.listBlacklistTypeFilter = VideoBlacklistType.MANUAL
50 this.videoBlacklistActions = [
52 label: this.i18n('Unblacklist'),
53 handler: videoBlacklist => this.removeVideoFromBlacklist(videoBlacklist)
59 return 'VideoBlacklistListComponent'
62 getVideoUrl (videoBlacklist: VideoBlacklist) {
63 return Video.buildClientUrl(videoBlacklist.video.uuid)
66 booleanToText (value: boolean) {
67 if (value === true) return this.i18n('yes')
69 return this.i18n('no')
72 toHtml (text: string) {
73 return this.markdownRenderer.textMarkdownToHTML(text)
76 async removeVideoFromBlacklist (entry: VideoBlacklist) {
77 const confirmMessage = this.i18n(
78 'Do you really want to remove this video from the blacklist? It will be available again in the videos list.'
81 const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist'))
82 if (res === false) return
84 this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe(
86 this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name }))
90 err => this.notifier.error(err.message)
94 protected loadData () {
95 this.videoBlacklistService.listBlacklist({
96 pagination: this.pagination,
99 type: this.listBlacklistTypeFilter
102 async resultList => {
103 this.totalRecords = resultList.total
105 this.blacklist = resultList.data
107 for (const element of this.blacklist) {
108 Object.assign(element, { reasonHtml: await this.toHtml(element.reason) })
112 err => this.notifier.error(err.message)