]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.ts
add aria-hidden to non-descriptive icons (#2844)
[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 19 totalRecords = 0
bb152476 20 sort: SortMeta = { field: 'createdAt', order: -1 }
792dbaf0 21 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
7ccddd7b 22 listBlacklistTypeFilter: VideoBlacklistType = undefined
792dbaf0 23
191764f3 24 videoBlacklistActions: DropdownAction<VideoBlacklist>[] = []
26b7305a 25
792dbaf0 26 constructor (
f8b2c1b4 27 private notifier: Notifier,
7ccddd7b 28 private serverService: ServerService,
792dbaf0 29 private confirmService: ConfirmService,
b1d40cff 30 private videoBlacklistService: VideoBlacklistService,
1506307f 31 private markdownRenderer: MarkdownService,
b1d40cff 32 private i18n: I18n
792dbaf0
GS
33 ) {
34 super()
ba430d75
C
35 }
36
37 ngOnInit () {
38 this.serverService.getConfig()
39 .subscribe(config => {
e0a92917 40 // don't filter if auto-blacklist is not enabled as this will be the only list
ba430d75
C
41 if (config.autoBlacklist.videos.ofUsers.enabled) {
42 this.listBlacklistTypeFilter = VideoBlacklistType.MANUAL
43 }
44 })
26b7305a 45
ba430d75 46 this.initialize()
7ccddd7b 47
26b7305a
C
48 this.videoBlacklistActions = [
49 {
50 label: this.i18n('Unblacklist'),
51 handler: videoBlacklist => this.removeVideoFromBlacklist(videoBlacklist)
52 }
53 ]
792dbaf0
GS
54 }
55
8e11a1b3
C
56 getIdentifier () {
57 return 'VideoBlacklistListComponent'
58 }
59
191764f3
C
60 getVideoUrl (videoBlacklist: VideoBlacklist) {
61 return Video.buildClientUrl(videoBlacklist.video.uuid)
62 }
63
5abb9fbb
C
64 booleanToText (value: boolean) {
65 if (value === true) return this.i18n('yes')
66
67 return this.i18n('no')
68 }
69
1506307f
C
70 toHtml (text: string) {
71 return this.markdownRenderer.textMarkdownToHTML(text)
72 }
73
191764f3 74 async removeVideoFromBlacklist (entry: VideoBlacklist) {
b1d40cff 75 const confirmMessage = this.i18n(
26b7305a 76 'Do you really want to remove this video from the blacklist? It will be available again in the videos list.'
b1d40cff 77 )
792dbaf0 78
b1d40cff 79 const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist'))
1f30a185 80 if (res === false) return
792dbaf0 81
26b7305a 82 this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe(
1f30a185 83 () => {
f8b2c1b4 84 this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name }))
1f30a185
C
85 this.loadData()
86 },
792dbaf0 87
f8b2c1b4 88 err => this.notifier.error(err.message)
792dbaf0
GS
89 )
90 }
91
92 protected loadData () {
e0a92917
RK
93 this.videoBlacklistService.listBlacklist({
94 pagination: this.pagination,
95 sort: this.sort,
96 search: this.search,
97 type: this.listBlacklistTypeFilter
98 })
792dbaf0 99 .subscribe(
41d71344 100 async resultList => {
792dbaf0 101 this.totalRecords = resultList.total
41d71344
C
102
103 this.blacklist = resultList.data
104
105 for (const element of this.blacklist) {
106 Object.assign(element, { reasonHtml: await this.toHtml(element.reason) })
107 }
792dbaf0
GS
108 },
109
f8b2c1b4 110 err => this.notifier.error(err.message)
792dbaf0
GS
111 )
112 }
113}