]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.ts
Add filter inputs for blacklisted videos and muted accounts/servers
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / moderation / video-blacklist-list / video-blacklist-list.component.ts
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'
11
12 @Component({
13 selector: 'my-video-blacklist-list',
14 templateUrl: './video-blacklist-list.component.html',
15 styleUrls: [ '../moderation.component.scss' ]
16 })
17 export class VideoBlacklistListComponent extends RestTable implements OnInit {
18 blacklist: (VideoBlacklist & { reasonHtml?: string })[] = []
19 totalRecords = 0
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
25
26 videoBlacklistActions: DropdownAction<VideoBlacklist>[] = []
27
28 constructor (
29 private notifier: Notifier,
30 private serverService: ServerService,
31 private confirmService: ConfirmService,
32 private videoBlacklistService: VideoBlacklistService,
33 private markdownRenderer: MarkdownService,
34 private i18n: I18n
35 ) {
36 super()
37 }
38
39 ngOnInit () {
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
45 }
46 })
47
48 this.initialize()
49
50 this.videoBlacklistActions = [
51 {
52 label: this.i18n('Unblacklist'),
53 handler: videoBlacklist => this.removeVideoFromBlacklist(videoBlacklist)
54 }
55 ]
56 }
57
58 getIdentifier () {
59 return 'VideoBlacklistListComponent'
60 }
61
62 getVideoUrl (videoBlacklist: VideoBlacklist) {
63 return Video.buildClientUrl(videoBlacklist.video.uuid)
64 }
65
66 booleanToText (value: boolean) {
67 if (value === true) return this.i18n('yes')
68
69 return this.i18n('no')
70 }
71
72 toHtml (text: string) {
73 return this.markdownRenderer.textMarkdownToHTML(text)
74 }
75
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.'
79 )
80
81 const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist'))
82 if (res === false) return
83
84 this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe(
85 () => {
86 this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name }))
87 this.loadData()
88 },
89
90 err => this.notifier.error(err.message)
91 )
92 }
93
94 protected loadData () {
95 this.videoBlacklistService.listBlacklist({
96 pagination: this.pagination,
97 sort: this.sort,
98 search: this.search,
99 type: this.listBlacklistTypeFilter
100 })
101 .subscribe(
102 async resultList => {
103 this.totalRecords = resultList.total
104
105 this.blacklist = resultList.data
106
107 for (const element of this.blacklist) {
108 Object.assign(element, { reasonHtml: await this.toHtml(element.reason) })
109 }
110 },
111
112 err => this.notifier.error(err.message)
113 )
114 }
115 }