]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.ts
Merge branch 'release/2.1.0' 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/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 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
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 })
46
47 this.initialize()
48
49 this.videoBlacklistActions = [
50 {
51 label: this.i18n('Unblacklist'),
52 handler: videoBlacklist => this.removeVideoFromBlacklist(videoBlacklist)
53 }
54 ]
55 }
56
57 getVideoUrl (videoBlacklist: VideoBlacklist) {
58 return Video.buildClientUrl(videoBlacklist.video.uuid)
59 }
60
61 booleanToText (value: boolean) {
62 if (value === true) return this.i18n('yes')
63
64 return this.i18n('no')
65 }
66
67 toHtml (text: string) {
68 return this.markdownRenderer.textMarkdownToHTML(text)
69 }
70
71 async removeVideoFromBlacklist (entry: VideoBlacklist) {
72 const confirmMessage = this.i18n(
73 'Do you really want to remove this video from the blacklist? It will be available again in the videos list.'
74 )
75
76 const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist'))
77 if (res === false) return
78
79 this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe(
80 () => {
81 this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name }))
82 this.loadData()
83 },
84
85 err => this.notifier.error(err.message)
86 )
87 }
88
89 protected loadData () {
90 this.videoBlacklistService.listBlacklist(this.pagination, this.sort, this.listBlacklistTypeFilter)
91 .subscribe(
92 async resultList => {
93 this.totalRecords = resultList.total
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 }
100 },
101
102 err => this.notifier.error(err.message)
103 )
104 }
105 }