1 import { Component, OnInit } from '@angular/core'
2 import { SortMeta } from 'primeng/components/common/sortmeta'
3 import { Notifier } from '@app/core'
4 import { ConfirmService } from '../../../core'
5 import { RestPagination, RestTable, VideoBlacklistService } from '../../../shared'
6 import { VideoBlacklist } 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[] = []
21 sort: SortMeta = { field: 'createdAt', order: 1 }
22 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
24 videoBlacklistActions: DropdownAction<VideoBlacklist>[] = []
27 private notifier: Notifier,
28 private confirmService: ConfirmService,
29 private videoBlacklistService: VideoBlacklistService,
30 private markdownRenderer: MarkdownService,
35 this.videoBlacklistActions = [
37 label: this.i18n('Unblacklist'),
38 handler: videoBlacklist => this.removeVideoFromBlacklist(videoBlacklist)
47 getVideoUrl (videoBlacklist: VideoBlacklist) {
48 return Video.buildClientUrl(videoBlacklist.video.uuid)
51 booleanToText (value: boolean) {
52 if (value === true) return this.i18n('yes')
54 return this.i18n('no')
57 toHtml (text: string) {
58 return this.markdownRenderer.textMarkdownToHTML(text)
61 async removeVideoFromBlacklist (entry: VideoBlacklist) {
62 const confirmMessage = this.i18n(
63 'Do you really want to remove this video from the blacklist? It will be available again in the videos list.'
66 const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist'))
67 if (res === false) return
69 this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe(
71 this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name }))
75 err => this.notifier.error(err.message)
79 protected loadData () {
80 this.videoBlacklistService.listBlacklist(this.pagination, this.sort)
83 this.blacklist = resultList.data
84 this.totalRecords = resultList.total
87 err => this.notifier.error(err.message)