]>
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' |
3523b64a | 4 | import { SortMeta } from 'primeng/components/common/sortmeta' |
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' |
19a3b914 | 12 | |
11ac88de | 13 | @Component({ |
df98563e | 14 | selector: 'my-video-abuse-list', |
f595d394 | 15 | templateUrl: './video-abuse-list.component.html', |
83b5fe9c | 16 | styleUrls: [ '../moderation.component.scss'] |
11ac88de | 17 | }) |
d592e0a9 | 18 | export class VideoAbuseListComponent extends RestTable implements OnInit { |
efc9e845 C |
19 | @ViewChild('moderationCommentModal') moderationCommentModal: ModerationCommentModalComponent |
20 | ||
d592e0a9 C |
21 | videoAbuses: VideoAbuse[] = [] |
22 | totalRecords = 0 | |
d5050d1e | 23 | rowsPerPage = 10 |
ab998f7b | 24 | sort: SortMeta = { field: 'createdAt', order: 1 } |
d592e0a9 | 25 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
11ac88de | 26 | |
efc9e845 C |
27 | videoAbuseActions: DropdownAction<VideoAbuse>[] = [] |
28 | ||
df98563e | 29 | constructor ( |
f8b2c1b4 | 30 | private notifier: Notifier, |
b1d40cff | 31 | private videoAbuseService: VideoAbuseService, |
efc9e845 | 32 | private confirmService: ConfirmService, |
b1d40cff | 33 | private i18n: I18n |
28798b5d | 34 | ) { |
d592e0a9 | 35 | super() |
efc9e845 C |
36 | |
37 | this.videoAbuseActions = [ | |
38 | { | |
5aa4a3dd | 39 | label: this.i18n('Delete this report'), |
efc9e845 C |
40 | handler: videoAbuse => this.removeVideoAbuse(videoAbuse) |
41 | }, | |
42 | { | |
43 | label: this.i18n('Update moderation comment'), | |
44 | handler: videoAbuse => this.openModerationCommentModal(videoAbuse) | |
45 | }, | |
46 | { | |
47 | label: this.i18n('Mark as accepted'), | |
48 | handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED), | |
49 | isDisplayed: videoAbuse => !this.isVideoAbuseAccepted(videoAbuse) | |
50 | }, | |
51 | { | |
52 | label: this.i18n('Mark as rejected'), | |
53 | handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.REJECTED), | |
54 | isDisplayed: videoAbuse => !this.isVideoAbuseRejected(videoAbuse) | |
55 | } | |
56 | ] | |
d592e0a9 C |
57 | } |
58 | ||
59 | ngOnInit () { | |
24b9417c | 60 | this.initialize() |
df98563e | 61 | } |
11ac88de | 62 | |
efc9e845 C |
63 | openModerationCommentModal (videoAbuse: VideoAbuse) { |
64 | this.moderationCommentModal.openModal(videoAbuse) | |
65 | } | |
66 | ||
67 | onModerationCommentUpdated () { | |
68 | this.loadData() | |
69 | } | |
70 | ||
19a3b914 C |
71 | createByString (account: Account) { |
72 | return Account.CREATE_BY_STRING(account.name, account.host) | |
d592e0a9 C |
73 | } |
74 | ||
efc9e845 C |
75 | isVideoAbuseAccepted (videoAbuse: VideoAbuse) { |
76 | return videoAbuse.state.id === VideoAbuseState.ACCEPTED | |
77 | } | |
78 | ||
79 | isVideoAbuseRejected (videoAbuse: VideoAbuse) { | |
80 | return videoAbuse.state.id === VideoAbuseState.REJECTED | |
81 | } | |
82 | ||
191764f3 C |
83 | getVideoUrl (videoAbuse: VideoAbuse) { |
84 | return Video.buildClientUrl(videoAbuse.video.uuid) | |
85 | } | |
86 | ||
efc9e845 | 87 | async removeVideoAbuse (videoAbuse: VideoAbuse) { |
198d764f | 88 | const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete')) |
efc9e845 C |
89 | if (res === false) return |
90 | ||
91 | this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe( | |
92 | () => { | |
f8b2c1b4 | 93 | this.notifier.success(this.i18n('Abuse deleted.')) |
efc9e845 C |
94 | this.loadData() |
95 | }, | |
96 | ||
f8b2c1b4 | 97 | err => this.notifier.error(err.message) |
efc9e845 C |
98 | ) |
99 | } | |
100 | ||
101 | updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) { | |
102 | this.videoAbuseService.updateVideoAbuse(videoAbuse, { state }) | |
103 | .subscribe( | |
104 | () => this.loadData(), | |
105 | ||
f8b2c1b4 | 106 | err => this.notifier.error(err.message) |
efc9e845 C |
107 | ) |
108 | ||
109 | } | |
110 | ||
d592e0a9 C |
111 | protected loadData () { |
112 | return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort) | |
113 | .subscribe( | |
114 | resultList => { | |
115 | this.videoAbuses = resultList.data | |
116 | this.totalRecords = resultList.total | |
117 | }, | |
118 | ||
f8b2c1b4 | 119 | err => this.notifier.error(err.message) |
d592e0a9 | 120 | ) |
11ac88de C |
121 | } |
122 | } |