1 import { Component, OnInit, ViewChild } from '@angular/core'
2 import { Account } from '../../../shared/account/account.model'
3 import { NotificationsService } from 'angular2-notifications'
4 import { SortMeta } from 'primeng/components/common/sortmeta'
5 import { VideoAbuse, VideoAbuseState } from '../../../../../../shared'
6 import { RestPagination, RestTable, VideoAbuseService } from '../../../shared'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
8 import { DropdownAction } from '../../../shared/buttons/action-dropdown.component'
9 import { ConfirmService } from '../../../core/index'
10 import { ModerationCommentModalComponent } from './moderation-comment-modal.component'
11 import { Video } from '../../../shared/video/video.model'
14 selector: 'my-video-abuse-list',
15 templateUrl: './video-abuse-list.component.html',
16 styleUrls: [ '../moderation.component.scss']
18 export class VideoAbuseListComponent extends RestTable implements OnInit {
19 @ViewChild('moderationCommentModal') moderationCommentModal: ModerationCommentModalComponent
21 videoAbuses: VideoAbuse[] = []
24 sort: SortMeta = { field: 'createdAt', order: 1 }
25 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
27 videoAbuseActions: DropdownAction<VideoAbuse>[] = []
30 private notificationsService: NotificationsService,
31 private videoAbuseService: VideoAbuseService,
32 private confirmService: ConfirmService,
37 this.videoAbuseActions = [
39 label: this.i18n('Delete'),
40 handler: videoAbuse => this.removeVideoAbuse(videoAbuse)
43 label: this.i18n('Update moderation comment'),
44 handler: videoAbuse => this.openModerationCommentModal(videoAbuse)
47 label: this.i18n('Mark as accepted'),
48 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED),
49 isDisplayed: videoAbuse => !this.isVideoAbuseAccepted(videoAbuse)
52 label: this.i18n('Mark as rejected'),
53 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.REJECTED),
54 isDisplayed: videoAbuse => !this.isVideoAbuseRejected(videoAbuse)
63 openModerationCommentModal (videoAbuse: VideoAbuse) {
64 this.moderationCommentModal.openModal(videoAbuse)
67 onModerationCommentUpdated () {
71 createByString (account: Account) {
72 return Account.CREATE_BY_STRING(account.name, account.host)
75 isVideoAbuseAccepted (videoAbuse: VideoAbuse) {
76 return videoAbuse.state.id === VideoAbuseState.ACCEPTED
79 isVideoAbuseRejected (videoAbuse: VideoAbuse) {
80 return videoAbuse.state.id === VideoAbuseState.REJECTED
83 getVideoUrl (videoAbuse: VideoAbuse) {
84 return Video.buildClientUrl(videoAbuse.video.uuid)
87 async removeVideoAbuse (videoAbuse: VideoAbuse) {
88 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse?'), this.i18n('Delete'))
89 if (res === false) return
91 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
93 this.notificationsService.success(
95 this.i18n('Abuse deleted.')
100 err => this.notificationsService.error(this.i18n('Error'), err.message)
104 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
105 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
107 () => this.loadData(),
109 err => this.notificationsService.error(this.i18n('Error'), err.message)
114 protected loadData () {
115 return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort)
118 this.videoAbuses = resultList.data
119 this.totalRecords = resultList.total
122 err => this.notificationsService.error(this.i18n('Error'), err.message)