aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-06-02 20:50:42 +0200
committerRigel Kent <sendmemail@rigelk.eu>2020-06-10 21:12:05 +0200
commit5baee5fca418487e72ddcd6419d31bca8659b668 (patch)
tree6604cc16d42152f4929d888565d2d435e2480d47 /client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts
parentd840487fed32b4604b02030c0d7464afa925904f (diff)
downloadPeerTube-5baee5fca418487e72ddcd6419d31bca8659b668.tar.gz
PeerTube-5baee5fca418487e72ddcd6419d31bca8659b668.tar.zst
PeerTube-5baee5fca418487e72ddcd6419d31bca8659b668.zip
rename blacklist to block/blocklist, merge block and auto-block views
- also replace whitelist with allowlist - add advanced filters for video-block-list view - move icons in video-block-list and video-abuse-list to left side for visibility - add robot icon to depict automated nature of a block in video-block-list resolves #2790
Diffstat (limited to 'client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts')
-rw-r--r--client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts196
1 files changed, 196 insertions, 0 deletions
diff --git a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts
new file mode 100644
index 000000000..e72ab5348
--- /dev/null
+++ b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts
@@ -0,0 +1,196 @@
1import { Component, OnInit } from '@angular/core'
2import { SortMeta } from 'primeng/api'
3import { Notifier, ServerService } from '@app/core'
4import { ConfirmService } from '../../../core'
5import { RestPagination, RestTable, VideoBlockService } from '../../../shared'
6import { VideoBlocklist, VideoBlockType } from '../../../../../../shared'
7import { I18n } from '@ngx-translate/i18n-polyfill'
8import { DropdownAction } from '../../../shared/buttons/action-dropdown.component'
9import { Video } from '../../../shared/video/video.model'
10import { MarkdownService } from '@app/shared/renderer'
11import { Params, ActivatedRoute, Router } from '@angular/router'
12import { filter, switchMap } from 'rxjs/operators'
13import { VideoService } from '@app/shared/video/video.service'
14
15@Component({
16 selector: 'my-video-block-list',
17 templateUrl: './video-block-list.component.html',
18 styleUrls: [ '../moderation.component.scss', './video-block-list.component.scss' ]
19})
20export class VideoBlockListComponent extends RestTable implements OnInit {
21 blocklist: (VideoBlocklist & { reasonHtml?: string })[] = []
22 totalRecords = 0
23 sort: SortMeta = { field: 'createdAt', order: -1 }
24 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
25 listBlockTypeFilter: VideoBlockType = undefined
26
27 videoBlocklistActions: DropdownAction<VideoBlocklist>[][] = []
28
29 constructor (
30 private notifier: Notifier,
31 private serverService: ServerService,
32 private confirmService: ConfirmService,
33 private videoBlocklistService: VideoBlockService,
34 private markdownRenderer: MarkdownService,
35 private videoService: VideoService,
36 private route: ActivatedRoute,
37 private router: Router,
38 private i18n: I18n
39 ) {
40 super()
41
42 this.videoBlocklistActions = [
43 [
44 {
45 label: this.i18n('Internal actions'),
46 isHeader: true
47 },
48 {
49 label: this.i18n('Switch video block to manual'),
50 handler: videoBlock => {
51 this.videoBlocklistService.unblockVideo(videoBlock.video.id).pipe(
52 switchMap(_ => this.videoBlocklistService.blockVideo(videoBlock.video.id, undefined, true))
53 ).subscribe(
54 () => {
55 this.notifier.success(this.i18n('Video {{name}} switched to manual block.', { name: videoBlock.video.name }))
56 this.loadData()
57 },
58
59 err => this.notifier.error(err.message)
60 )
61 }
62 }
63 ],
64 [
65 {
66 label: this.i18n('Actions for the video'),
67 isHeader: true,
68 },
69 {
70 label: this.i18n('Unblock video'),
71 handler: videoBlock => this.unblockVideo(videoBlock)
72 },
73
74 {
75 label: this.i18n('Delete video'),
76 handler: async videoBlock => {
77 const res = await this.confirmService.confirm(
78 this.i18n('Do you really want to delete this video?'),
79 this.i18n('Delete')
80 )
81 if (res === false) return
82
83 this.videoService.removeVideo(videoBlock.video.id)
84 .subscribe(
85 () => {
86 this.notifier.success(this.i18n('Video deleted.'))
87 },
88
89 err => this.notifier.error(err.message)
90 )
91 }
92 }
93 ]
94 ]
95 }
96
97 ngOnInit () {
98 this.serverService.getConfig()
99 .subscribe(config => {
100 // don't filter if auto-blacklist is not enabled as this will be the only list
101 if (config.autoBlacklist.videos.ofUsers.enabled) {
102 this.listBlockTypeFilter = VideoBlockType.MANUAL
103 }
104 })
105
106 this.initialize()
107
108 this.route.queryParams
109 .pipe(filter(params => params.search !== undefined && params.search !== null))
110 .subscribe(params => {
111 this.search = params.search
112 this.setTableFilter(params.search)
113 this.loadData()
114 })
115 }
116
117 ngAfterViewInit () {
118 if (this.search) this.setTableFilter(this.search)
119 }
120
121 /* Table filter functions */
122 onBlockSearch (event: Event) {
123 this.onSearch(event)
124 this.setQueryParams((event.target as HTMLInputElement).value)
125 }
126
127 setQueryParams (search: string) {
128 const queryParams: Params = {}
129 if (search) Object.assign(queryParams, { search })
130 this.router.navigate([ '/admin/moderation/video-blocks/list' ], { queryParams })
131 }
132
133 resetTableFilter () {
134 this.setTableFilter('')
135 this.setQueryParams('')
136 this.resetSearch()
137 }
138 /* END Table filter functions */
139
140 getIdentifier () {
141 return 'VideoBlockListComponent'
142 }
143
144 getVideoUrl (videoBlock: VideoBlocklist) {
145 return Video.buildClientUrl(videoBlock.video.uuid)
146 }
147
148 booleanToText (value: boolean) {
149 if (value === true) return this.i18n('yes')
150
151 return this.i18n('no')
152 }
153
154 toHtml (text: string) {
155 return this.markdownRenderer.textMarkdownToHTML(text)
156 }
157
158 async unblockVideo (entry: VideoBlocklist) {
159 const confirmMessage = this.i18n(
160 'Do you really want to unblock this video? It will be available again in the videos list.'
161 )
162
163 const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblock'))
164 if (res === false) return
165
166 this.videoBlocklistService.unblockVideo(entry.video.id).subscribe(
167 () => {
168 this.notifier.success(this.i18n('Video {{name}} unblocked.', { name: entry.video.name }))
169 this.loadData()
170 },
171
172 err => this.notifier.error(err.message)
173 )
174 }
175
176 protected loadData () {
177 this.videoBlocklistService.listBlocks({
178 pagination: this.pagination,
179 sort: this.sort,
180 search: this.search,
181 })
182 .subscribe(
183 async resultList => {
184 this.totalRecords = resultList.total
185
186 this.blocklist = resultList.data
187
188 for (const element of this.blocklist) {
189 Object.assign(element, { reasonHtml: await this.toHtml(element.reason) })
190 }
191 },
192
193 err => this.notifier.error(err.message)
194 )
195 }
196}