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 })[] = []
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,
39 this.serverService.getConfig()
40 .subscribe(config => {
41 // don't filter if auto-blacklist not enabled as this will be only list
42 if (config.autoBlacklist.videos.ofUsers.enabled) {
43 this.listBlacklistTypeFilter = VideoBlacklistType.MANUAL
49 this.videoBlacklistActions = [
51 label: this.i18n('Unblacklist'),
52 handler: videoBlacklist => this.removeVideoFromBlacklist(videoBlacklist)
58 return 'VideoBlacklistListComponent'
61 getVideoUrl (videoBlacklist: VideoBlacklist) {
62 return Video.buildClientUrl(videoBlacklist.video.uuid)
65 booleanToText (value: boolean) {
66 if (value === true) return this.i18n('yes')
68 return this.i18n('no')
71 toHtml (text: string) {
72 return this.markdownRenderer.textMarkdownToHTML(text)
75 async removeVideoFromBlacklist (entry: VideoBlacklist) {
76 const confirmMessage = this.i18n(
77 'Do you really want to remove this video from the blacklist? It will be available again in the videos list.'
80 const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist'))
81 if (res === false) return
83 this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe(
85 this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name }))
89 err => this.notifier.error(err.message)
93 protected loadData () {
94 this.videoBlacklistService.listBlacklist(this.pagination, this.sort, this.listBlacklistTypeFilter)
97 this.totalRecords = resultList.total
99 this.blacklist = resultList.data
101 for (const element of this.blacklist) {
102 Object.assign(element, { reasonHtml: await this.toHtml(element.reason) })
106 err => this.notifier.error(err.message)