]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.ts
Rich reporter field and video embed in moderation abuse list
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / moderation / video-blacklist-list / video-blacklist-list.component.ts
CommitLineData
792dbaf0 1import { Component, OnInit } from '@angular/core'
f77eb73b 2import { SortMeta } from 'primeng/api'
7ccddd7b 3import { Notifier, ServerService } from '@app/core'
792dbaf0 4import { ConfirmService } from '../../../core'
b1d40cff 5import { RestPagination, RestTable, VideoBlacklistService } from '../../../shared'
7ccddd7b 6import { VideoBlacklist, VideoBlacklistType } from '../../../../../../shared'
b1d40cff 7import { I18n } from '@ngx-translate/i18n-polyfill'
614d1ae9
C
8import { DropdownAction } from '../../../shared/buttons/action-dropdown.component'
9import { Video } from '../../../shared/video/video.model'
1506307f 10import { MarkdownService } from '@app/shared/renderer'
792dbaf0
GS
11
12@Component({
35bf0c83
C
13 selector: 'my-video-blacklist-list',
14 templateUrl: './video-blacklist-list.component.html',
83b5fe9c 15 styleUrls: [ '../moderation.component.scss' ]
792dbaf0 16})
35bf0c83 17export class VideoBlacklistListComponent extends RestTable implements OnInit {
41d71344 18 blacklist: (VideoBlacklist & { reasonHtml?: string })[] = []
792dbaf0
GS
19 totalRecords = 0
20 rowsPerPage = 10
ab998f7b 21 sort: SortMeta = { field: 'createdAt', order: 1 }
792dbaf0 22 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
7ccddd7b 23 listBlacklistTypeFilter: VideoBlacklistType = undefined
792dbaf0 24
191764f3 25 videoBlacklistActions: DropdownAction<VideoBlacklist>[] = []
26b7305a 26
792dbaf0 27 constructor (
f8b2c1b4 28 private notifier: Notifier,
7ccddd7b 29 private serverService: ServerService,
792dbaf0 30 private confirmService: ConfirmService,
b1d40cff 31 private videoBlacklistService: VideoBlacklistService,
1506307f 32 private markdownRenderer: MarkdownService,
b1d40cff 33 private i18n: I18n
792dbaf0
GS
34 ) {
35 super()
ba430d75
C
36 }
37
38 ngOnInit () {
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
44 }
45 })
26b7305a 46
ba430d75 47 this.initialize()
7ccddd7b 48
26b7305a
C
49 this.videoBlacklistActions = [
50 {
51 label: this.i18n('Unblacklist'),
52 handler: videoBlacklist => this.removeVideoFromBlacklist(videoBlacklist)
53 }
54 ]
792dbaf0
GS
55 }
56
8e11a1b3
C
57 getIdentifier () {
58 return 'VideoBlacklistListComponent'
59 }
60
191764f3
C
61 getVideoUrl (videoBlacklist: VideoBlacklist) {
62 return Video.buildClientUrl(videoBlacklist.video.uuid)
63 }
64
5abb9fbb
C
65 booleanToText (value: boolean) {
66 if (value === true) return this.i18n('yes')
67
68 return this.i18n('no')
69 }
70
1506307f
C
71 toHtml (text: string) {
72 return this.markdownRenderer.textMarkdownToHTML(text)
73 }
74
191764f3 75 async removeVideoFromBlacklist (entry: VideoBlacklist) {
b1d40cff 76 const confirmMessage = this.i18n(
26b7305a 77 'Do you really want to remove this video from the blacklist? It will be available again in the videos list.'
b1d40cff 78 )
792dbaf0 79
b1d40cff 80 const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist'))
1f30a185 81 if (res === false) return
792dbaf0 82
26b7305a 83 this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe(
1f30a185 84 () => {
f8b2c1b4 85 this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name }))
1f30a185
C
86 this.loadData()
87 },
792dbaf0 88
f8b2c1b4 89 err => this.notifier.error(err.message)
792dbaf0
GS
90 )
91 }
92
93 protected loadData () {
7ccddd7b 94 this.videoBlacklistService.listBlacklist(this.pagination, this.sort, this.listBlacklistTypeFilter)
792dbaf0 95 .subscribe(
41d71344 96 async resultList => {
792dbaf0 97 this.totalRecords = resultList.total
41d71344
C
98
99 this.blacklist = resultList.data
100
101 for (const element of this.blacklist) {
102 Object.assign(element, { reasonHtml: await this.toHtml(element.reason) })
103 }
792dbaf0
GS
104 },
105
f8b2c1b4 106 err => this.notifier.error(err.message)
792dbaf0
GS
107 )
108 }
109}