]>
Commit | Line | Data |
---|---|---|
efc9e845 | 1 | import { Component, OnInit, ViewChild } from '@angular/core' |
614d1ae9 | 2 | import { Account } from '../../../shared/account/account.model' |
f8b2c1b4 | 3 | import { Notifier } from '@app/core' |
f77eb73b | 4 | import { SortMeta } from 'primeng/api' |
efc9e845 | 5 | import { VideoAbuse, VideoAbuseState } from '../../../../../../shared' |
19a3b914 | 6 | import { RestPagination, RestTable, VideoAbuseService } from '../../../shared' |
b1d40cff | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
614d1ae9 C |
8 | import { DropdownAction } from '../../../shared/buttons/action-dropdown.component' |
9 | import { ConfirmService } from '../../../core/index' | |
efc9e845 | 10 | import { ModerationCommentModalComponent } from './moderation-comment-modal.component' |
614d1ae9 | 11 | import { Video } from '../../../shared/video/video.model' |
1506307f | 12 | import { 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 | 19 | export 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 | |
efc9e845 C |
65 | openModerationCommentModal (videoAbuse: VideoAbuse) { |
66 | this.moderationCommentModal.openModal(videoAbuse) | |
67 | } | |
68 | ||
69 | onModerationCommentUpdated () { | |
70 | this.loadData() | |
71 | } | |
72 | ||
19a3b914 C |
73 | createByString (account: Account) { |
74 | return Account.CREATE_BY_STRING(account.name, account.host) | |
d592e0a9 C |
75 | } |
76 | ||
efc9e845 C |
77 | isVideoAbuseAccepted (videoAbuse: VideoAbuse) { |
78 | return videoAbuse.state.id === VideoAbuseState.ACCEPTED | |
79 | } | |
80 | ||
81 | isVideoAbuseRejected (videoAbuse: VideoAbuse) { | |
82 | return videoAbuse.state.id === VideoAbuseState.REJECTED | |
83 | } | |
84 | ||
191764f3 C |
85 | getVideoUrl (videoAbuse: VideoAbuse) { |
86 | return Video.buildClientUrl(videoAbuse.video.uuid) | |
87 | } | |
88 | ||
efc9e845 | 89 | async removeVideoAbuse (videoAbuse: VideoAbuse) { |
198d764f | 90 | const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete')) |
efc9e845 C |
91 | if (res === false) return |
92 | ||
93 | this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe( | |
94 | () => { | |
f8b2c1b4 | 95 | this.notifier.success(this.i18n('Abuse deleted.')) |
efc9e845 C |
96 | this.loadData() |
97 | }, | |
98 | ||
f8b2c1b4 | 99 | err => this.notifier.error(err.message) |
efc9e845 C |
100 | ) |
101 | } | |
102 | ||
103 | updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) { | |
104 | this.videoAbuseService.updateVideoAbuse(videoAbuse, { state }) | |
105 | .subscribe( | |
106 | () => this.loadData(), | |
107 | ||
f8b2c1b4 | 108 | err => this.notifier.error(err.message) |
efc9e845 C |
109 | ) |
110 | ||
111 | } | |
112 | ||
d592e0a9 C |
113 | protected loadData () { |
114 | return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort) | |
115 | .subscribe( | |
41d71344 | 116 | async resultList => { |
d592e0a9 | 117 | this.totalRecords = resultList.total |
41d71344 C |
118 | |
119 | this.videoAbuses = resultList.data | |
120 | ||
121 | for (const abuse of this.videoAbuses) { | |
122 | Object.assign(abuse, { | |
123 | reasonHtml: await this.toHtml(abuse.reason), | |
124 | moderationCommentHtml: await this.toHtml(abuse.moderationComment) | |
125 | }) | |
126 | } | |
127 | ||
d592e0a9 C |
128 | }, |
129 | ||
f8b2c1b4 | 130 | err => this.notifier.error(err.message) |
d592e0a9 | 131 | ) |
11ac88de | 132 | } |
41d71344 C |
133 | |
134 | private toHtml (text: string) { | |
135 | return this.markdownRenderer.textMarkdownToHTML(text) | |
136 | } | |
11ac88de | 137 | } |