]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.ts
Cleanup menu footer links
[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
191764f3
C
57 getVideoUrl (videoBlacklist: VideoBlacklist) {
58 return Video.buildClientUrl(videoBlacklist.video.uuid)
59 }
60
5abb9fbb
C
61 booleanToText (value: boolean) {
62 if (value === true) return this.i18n('yes')
63
64 return this.i18n('no')
65 }
66
1506307f
C
67 toHtml (text: string) {
68 return this.markdownRenderer.textMarkdownToHTML(text)
69 }
70
191764f3 71 async removeVideoFromBlacklist (entry: VideoBlacklist) {
b1d40cff 72 const confirmMessage = this.i18n(
26b7305a 73 'Do you really want to remove this video from the blacklist? It will be available again in the videos list.'
b1d40cff 74 )
792dbaf0 75
b1d40cff 76 const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist'))
1f30a185 77 if (res === false) return
792dbaf0 78
26b7305a 79 this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe(
1f30a185 80 () => {
f8b2c1b4 81 this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name }))
1f30a185
C
82 this.loadData()
83 },
792dbaf0 84
f8b2c1b4 85 err => this.notifier.error(err.message)
792dbaf0
GS
86 )
87 }
88
89 protected loadData () {
7ccddd7b 90 this.videoBlacklistService.listBlacklist(this.pagination, this.sort, this.listBlacklistTypeFilter)
792dbaf0 91 .subscribe(
41d71344 92 async resultList => {
792dbaf0 93 this.totalRecords = resultList.total
41d71344
C
94
95 this.blacklist = resultList.data
96
97 for (const element of this.blacklist) {
98 Object.assign(element, { reasonHtml: await this.toHtml(element.reason) })
99 }
792dbaf0
GS
100 },
101
f8b2c1b4 102 err => this.notifier.error(err.message)
792dbaf0
GS
103 )
104 }
105}