]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts
Improving select displays, focus box-shadows for paginators, instructions for index url
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / moderation / video-abuse-list / video-abuse-list.component.ts
CommitLineData
efc9e845 1import { Component, OnInit, ViewChild } from '@angular/core'
614d1ae9 2import { Account } from '../../../shared/account/account.model'
f8b2c1b4 3import { Notifier } from '@app/core'
f77eb73b 4import { SortMeta } from 'primeng/api'
efc9e845 5import { VideoAbuse, VideoAbuseState } from '../../../../../../shared'
19a3b914 6import { RestPagination, RestTable, VideoAbuseService } from '../../../shared'
b1d40cff 7import { I18n } from '@ngx-translate/i18n-polyfill'
614d1ae9
C
8import { DropdownAction } from '../../../shared/buttons/action-dropdown.component'
9import { ConfirmService } from '../../../core/index'
efc9e845 10import { ModerationCommentModalComponent } from './moderation-comment-modal.component'
614d1ae9 11import { Video } from '../../../shared/video/video.model'
1506307f 12import { MarkdownService } from '@app/shared/renderer'
19a3b914 13
11ac88de 14@Component({
df98563e 15 selector: 'my-video-abuse-list',
f595d394 16 templateUrl: './video-abuse-list.component.html',
83b5fe9c 17 styleUrls: [ '../moderation.component.scss']
11ac88de 18})
d592e0a9 19export class VideoAbuseListComponent extends RestTable implements OnInit {
f36da21e 20 @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent
efc9e845 21
41d71344 22 videoAbuses: (VideoAbuse & { moderationCommentHtml?: string, reasonHtml?: string })[] = []
d592e0a9 23 totalRecords = 0
d5050d1e 24 rowsPerPage = 10
ab998f7b 25 sort: SortMeta = { field: 'createdAt', order: 1 }
d592e0a9 26 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
11ac88de 27
efc9e845
C
28 videoAbuseActions: DropdownAction<VideoAbuse>[] = []
29
df98563e 30 constructor (
f8b2c1b4 31 private notifier: Notifier,
b1d40cff 32 private videoAbuseService: VideoAbuseService,
efc9e845 33 private confirmService: ConfirmService,
1506307f
C
34 private i18n: I18n,
35 private markdownRenderer: MarkdownService
28798b5d 36 ) {
d592e0a9 37 super()
efc9e845
C
38
39 this.videoAbuseActions = [
40 {
5aa4a3dd 41 label: this.i18n('Delete this report'),
efc9e845
C
42 handler: videoAbuse => this.removeVideoAbuse(videoAbuse)
43 },
44 {
45 label: this.i18n('Update moderation comment'),
46 handler: videoAbuse => this.openModerationCommentModal(videoAbuse)
47 },
48 {
49 label: this.i18n('Mark as accepted'),
50 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED),
51 isDisplayed: videoAbuse => !this.isVideoAbuseAccepted(videoAbuse)
52 },
53 {
54 label: this.i18n('Mark as rejected'),
55 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.REJECTED),
56 isDisplayed: videoAbuse => !this.isVideoAbuseRejected(videoAbuse)
57 }
58 ]
d592e0a9
C
59 }
60
61 ngOnInit () {
24b9417c 62 this.initialize()
df98563e 63 }
11ac88de 64
8e11a1b3
C
65 getIdentifier () {
66 return 'VideoAbuseListComponent'
67 }
68
efc9e845
C
69 openModerationCommentModal (videoAbuse: VideoAbuse) {
70 this.moderationCommentModal.openModal(videoAbuse)
71 }
72
73 onModerationCommentUpdated () {
74 this.loadData()
75 }
76
19a3b914
C
77 createByString (account: Account) {
78 return Account.CREATE_BY_STRING(account.name, account.host)
d592e0a9
C
79 }
80
efc9e845
C
81 isVideoAbuseAccepted (videoAbuse: VideoAbuse) {
82 return videoAbuse.state.id === VideoAbuseState.ACCEPTED
83 }
84
85 isVideoAbuseRejected (videoAbuse: VideoAbuse) {
86 return videoAbuse.state.id === VideoAbuseState.REJECTED
87 }
88
191764f3
C
89 getVideoUrl (videoAbuse: VideoAbuse) {
90 return Video.buildClientUrl(videoAbuse.video.uuid)
91 }
92
efc9e845 93 async removeVideoAbuse (videoAbuse: VideoAbuse) {
198d764f 94 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete'))
efc9e845
C
95 if (res === false) return
96
97 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
98 () => {
f8b2c1b4 99 this.notifier.success(this.i18n('Abuse deleted.'))
efc9e845
C
100 this.loadData()
101 },
102
f8b2c1b4 103 err => this.notifier.error(err.message)
efc9e845
C
104 )
105 }
106
107 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
108 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
109 .subscribe(
110 () => this.loadData(),
111
f8b2c1b4 112 err => this.notifier.error(err.message)
efc9e845
C
113 )
114
115 }
116
d592e0a9
C
117 protected loadData () {
118 return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort)
119 .subscribe(
41d71344 120 async resultList => {
d592e0a9 121 this.totalRecords = resultList.total
41d71344
C
122
123 this.videoAbuses = resultList.data
124
125 for (const abuse of this.videoAbuses) {
126 Object.assign(abuse, {
127 reasonHtml: await this.toHtml(abuse.reason),
128 moderationCommentHtml: await this.toHtml(abuse.moderationComment)
129 })
130 }
131
d592e0a9
C
132 },
133
f8b2c1b4 134 err => this.notifier.error(err.message)
d592e0a9 135 )
11ac88de 136 }
41d71344
C
137
138 private toHtml (text: string) {
139 return this.markdownRenderer.textMarkdownToHTML(text)
140 }
11ac88de 141}