]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts
Add users search filter
[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'
df98563e 3import { NotificationsService } from 'angular2-notifications'
3523b64a 4import { SortMeta } from 'primeng/components/common/sortmeta'
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'
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 18export 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 (
7ddd02c9 30 private notificationsService: NotificationsService,
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 {
39 label: this.i18n('Delete'),
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
C
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
90
91 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
92 () => {
93 this.notificationsService.success(
94 this.i18n('Success'),
95 this.i18n('Abuse deleted.')
96 )
97 this.loadData()
98 },
99
100 err => this.notificationsService.error(this.i18n('Error'), err.message)
101 )
102 }
103
104 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
105 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
106 .subscribe(
107 () => this.loadData(),
108
109 err => this.notificationsService.error(this.i18n('Error'), err.message)
110 )
111
112 }
113
d592e0a9
C
114 protected loadData () {
115 return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort)
116 .subscribe(
117 resultList => {
118 this.videoAbuses = resultList.data
119 this.totalRecords = resultList.total
120 },
121
b1d40cff 122 err => this.notificationsService.error(this.i18n('Error'), err.message)
d592e0a9 123 )
11ac88de
C
124 }
125}