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 sort: SortMeta = { field: 'createdAt', order: -1 }
21 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
22 listBlacklistTypeFilter: VideoBlacklistType = undefined
24 videoBlacklistActions: DropdownAction<VideoBlacklist>[] = []
27 private notifier: Notifier,
28 private serverService: ServerService,
29 private confirmService: ConfirmService,
30 private videoBlacklistService: VideoBlacklistService,
31 private markdownRenderer: MarkdownService,
38 this.serverService.getConfig()
39 .subscribe(config => {
40 // don't filter if auto-blacklist is not enabled as this will be the only list
41 if (config.autoBlacklist.videos.ofUsers.enabled) {
42 this.listBlacklistTypeFilter = VideoBlacklistType.MANUAL
48 this.videoBlacklistActions = [
50 label: this.i18n('Unblacklist'),
51 handler: videoBlacklist => this.removeVideoFromBlacklist(videoBlacklist)
57 return 'VideoBlacklistListComponent'
60 getVideoUrl (videoBlacklist: VideoBlacklist) {
61 return Video.buildClientUrl(videoBlacklist.video.uuid)
64 booleanToText (value: boolean) {
65 if (value === true) return this.i18n('yes')
67 return this.i18n('no')
70 toHtml (text: string) {
71 return this.markdownRenderer.textMarkdownToHTML(text)
74 async removeVideoFromBlacklist (entry: VideoBlacklist) {
75 const confirmMessage = this.i18n(
76 'Do you really want to remove this video from the blacklist? It will be available again in the videos list.'
79 const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist'))
80 if (res === false) return
82 this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe(
84 this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name }))
88 err => this.notifier.error(err.message)
92 protected loadData () {
93 this.videoBlacklistService.listBlacklist({
94 pagination: this.pagination,
97 type: this.listBlacklistTypeFilter
100 async resultList => {
101 this.totalRecords = resultList.total
103 this.blacklist = resultList.data
105 for (const element of this.blacklist) {
106 Object.assign(element, { reasonHtml: await this.toHtml(element.reason) })
110 err => this.notifier.error(err.message)