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