]>
Commit | Line | Data |
---|---|---|
792dbaf0 GS |
1 | import { Component, OnInit } from '@angular/core' |
2 | import { SortMeta } from 'primeng/components/common/sortmeta' | |
f8b2c1b4 | 3 | import { Notifier } from '@app/core' |
792dbaf0 | 4 | import { ConfirmService } from '../../../core' |
b1d40cff | 5 | import { RestPagination, RestTable, VideoBlacklistService } from '../../../shared' |
191764f3 | 6 | import { VideoBlacklist } from '../../../../../../shared' |
b1d40cff | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
614d1ae9 C |
8 | import { DropdownAction } from '../../../shared/buttons/action-dropdown.component' |
9 | import { Video } from '../../../shared/video/video.model' | |
1506307f | 10 | import { 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 | 17 | export 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 GS |
22 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
23 | ||
191764f3 | 24 | videoBlacklistActions: DropdownAction<VideoBlacklist>[] = [] |
26b7305a | 25 | |
792dbaf0 | 26 | constructor ( |
f8b2c1b4 | 27 | private notifier: Notifier, |
792dbaf0 | 28 | private confirmService: ConfirmService, |
b1d40cff | 29 | private videoBlacklistService: VideoBlacklistService, |
1506307f | 30 | private markdownRenderer: MarkdownService, |
b1d40cff | 31 | private i18n: I18n |
792dbaf0 GS |
32 | ) { |
33 | super() | |
26b7305a C |
34 | |
35 | this.videoBlacklistActions = [ | |
36 | { | |
37 | label: this.i18n('Unblacklist'), | |
38 | handler: videoBlacklist => this.removeVideoFromBlacklist(videoBlacklist) | |
39 | } | |
40 | ] | |
792dbaf0 GS |
41 | } |
42 | ||
43 | ngOnInit () { | |
24b9417c | 44 | this.initialize() |
792dbaf0 GS |
45 | } |
46 | ||
191764f3 C |
47 | getVideoUrl (videoBlacklist: VideoBlacklist) { |
48 | return Video.buildClientUrl(videoBlacklist.video.uuid) | |
49 | } | |
50 | ||
5abb9fbb C |
51 | booleanToText (value: boolean) { |
52 | if (value === true) return this.i18n('yes') | |
53 | ||
54 | return this.i18n('no') | |
55 | } | |
56 | ||
1506307f C |
57 | toHtml (text: string) { |
58 | return this.markdownRenderer.textMarkdownToHTML(text) | |
59 | } | |
60 | ||
191764f3 | 61 | async removeVideoFromBlacklist (entry: VideoBlacklist) { |
b1d40cff | 62 | const confirmMessage = this.i18n( |
26b7305a | 63 | 'Do you really want to remove this video from the blacklist? It will be available again in the videos list.' |
b1d40cff | 64 | ) |
792dbaf0 | 65 | |
b1d40cff | 66 | const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist')) |
1f30a185 | 67 | if (res === false) return |
792dbaf0 | 68 | |
26b7305a | 69 | this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe( |
1f30a185 | 70 | () => { |
f8b2c1b4 | 71 | this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name })) |
1f30a185 C |
72 | this.loadData() |
73 | }, | |
792dbaf0 | 74 | |
f8b2c1b4 | 75 | err => this.notifier.error(err.message) |
792dbaf0 GS |
76 | ) |
77 | } | |
78 | ||
79 | protected loadData () { | |
35bf0c83 | 80 | this.videoBlacklistService.listBlacklist(this.pagination, this.sort) |
792dbaf0 | 81 | .subscribe( |
41d71344 | 82 | async resultList => { |
792dbaf0 | 83 | this.totalRecords = resultList.total |
41d71344 C |
84 | |
85 | this.blacklist = resultList.data | |
86 | ||
87 | for (const element of this.blacklist) { | |
88 | Object.assign(element, { reasonHtml: await this.toHtml(element.reason) }) | |
89 | } | |
792dbaf0 GS |
90 | }, |
91 | ||
f8b2c1b4 | 92 | err => this.notifier.error(err.message) |
792dbaf0 GS |
93 | ) |
94 | } | |
95 | } |