]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.ts
Merge branch 'master' into develop
[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/components/common/sortmeta'
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 rowsPerPage = 10
21 sort: SortMeta = { field: 'createdAt', order: 1 }
22 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
23 listBlacklistTypeFilter: VideoBlacklistType = undefined
24
25 videoBlacklistActions: DropdownAction<VideoBlacklist>[] = []
26
27 constructor (
28 private notifier: Notifier,
29 private serverService: ServerService,
30 private confirmService: ConfirmService,
31 private videoBlacklistService: VideoBlacklistService,
32 private markdownRenderer: MarkdownService,
33 private i18n: I18n
34 ) {
35 super()
36
37 // don't filter if auto-blacklist not enabled as this will be only list
38 if (this.serverService.getConfig().autoBlacklist.videos.ofUsers.enabled) {
39 this.listBlacklistTypeFilter = VideoBlacklistType.MANUAL
40 }
41
42 this.videoBlacklistActions = [
43 {
44 label: this.i18n('Unblacklist'),
45 handler: videoBlacklist => this.removeVideoFromBlacklist(videoBlacklist)
46 }
47 ]
48 }
49
50 ngOnInit () {
51 this.initialize()
52 }
53
54 getVideoUrl (videoBlacklist: VideoBlacklist) {
55 return Video.buildClientUrl(videoBlacklist.video.uuid)
56 }
57
58 booleanToText (value: boolean) {
59 if (value === true) return this.i18n('yes')
60
61 return this.i18n('no')
62 }
63
64 toHtml (text: string) {
65 return this.markdownRenderer.textMarkdownToHTML(text)
66 }
67
68 async removeVideoFromBlacklist (entry: VideoBlacklist) {
69 const confirmMessage = this.i18n(
70 'Do you really want to remove this video from the blacklist? It will be available again in the videos list.'
71 )
72
73 const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist'))
74 if (res === false) return
75
76 this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe(
77 () => {
78 this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name }))
79 this.loadData()
80 },
81
82 err => this.notifier.error(err.message)
83 )
84 }
85
86 protected loadData () {
87 this.videoBlacklistService.listBlacklist(this.pagination, this.sort, this.listBlacklistTypeFilter)
88 .subscribe(
89 async resultList => {
90 this.totalRecords = resultList.total
91
92 this.blacklist = resultList.data
93
94 for (const element of this.blacklist) {
95 Object.assign(element, { reasonHtml: await this.toHtml(element.reason) })
96 }
97 },
98
99 err => this.notifier.error(err.message)
100 )
101 }
102 }