aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts')
-rw-r--r--client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts77
1 files changed, 74 insertions, 3 deletions
diff --git a/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts b/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts
index 6ddebff7e..a850c0ec2 100644
--- a/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts
+++ b/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts
@@ -1,11 +1,13 @@
1import { Component, OnInit } from '@angular/core' 1import { Component, OnInit, ViewChild } from '@angular/core'
2import { Account } from '@app/shared/account/account.model' 2import { Account } from '@app/shared/account/account.model'
3import { NotificationsService } from 'angular2-notifications' 3import { NotificationsService } from 'angular2-notifications'
4import { SortMeta } from 'primeng/components/common/sortmeta' 4import { SortMeta } from 'primeng/components/common/sortmeta'
5import { VideoAbuse } from '../../../../../../shared' 5import { VideoAbuse, VideoAbuseState } from '../../../../../../shared'
6
7import { RestPagination, RestTable, VideoAbuseService } from '../../../shared' 6import { RestPagination, RestTable, VideoAbuseService } from '../../../shared'
8import { I18n } from '@ngx-translate/i18n-polyfill' 7import { I18n } from '@ngx-translate/i18n-polyfill'
8import { DropdownAction } from '@app/shared/buttons/action-dropdown.component'
9import { ConfirmService } from '@app/core'
10import { ModerationCommentModalComponent } from './moderation-comment-modal.component'
9 11
10@Component({ 12@Component({
11 selector: 'my-video-abuse-list', 13 selector: 'my-video-abuse-list',
@@ -13,28 +15,97 @@ import { I18n } from '@ngx-translate/i18n-polyfill'
13 styleUrls: [ './video-abuse-list.component.scss'] 15 styleUrls: [ './video-abuse-list.component.scss']
14}) 16})
15export class VideoAbuseListComponent extends RestTable implements OnInit { 17export class VideoAbuseListComponent extends RestTable implements OnInit {
18 @ViewChild('moderationCommentModal') moderationCommentModal: ModerationCommentModalComponent
19
16 videoAbuses: VideoAbuse[] = [] 20 videoAbuses: VideoAbuse[] = []
17 totalRecords = 0 21 totalRecords = 0
18 rowsPerPage = 10 22 rowsPerPage = 10
19 sort: SortMeta = { field: 'createdAt', order: 1 } 23 sort: SortMeta = { field: 'createdAt', order: 1 }
20 pagination: RestPagination = { count: this.rowsPerPage, start: 0 } 24 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
21 25
26 videoAbuseActions: DropdownAction<VideoAbuse>[] = []
27
22 constructor ( 28 constructor (
23 private notificationsService: NotificationsService, 29 private notificationsService: NotificationsService,
24 private videoAbuseService: VideoAbuseService, 30 private videoAbuseService: VideoAbuseService,
31 private confirmService: ConfirmService,
25 private i18n: I18n 32 private i18n: I18n
26 ) { 33 ) {
27 super() 34 super()
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 ]
28 } 56 }
29 57
30 ngOnInit () { 58 ngOnInit () {
31 this.loadSort() 59 this.loadSort()
32 } 60 }
33 61
62 openModerationCommentModal (videoAbuse: VideoAbuse) {
63 this.moderationCommentModal.openModal(videoAbuse)
64 }
65
66 onModerationCommentUpdated () {
67 this.loadData()
68 }
69
34 createByString (account: Account) { 70 createByString (account: Account) {
35 return Account.CREATE_BY_STRING(account.name, account.host) 71 return Account.CREATE_BY_STRING(account.name, account.host)
36 } 72 }
37 73
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
38 protected loadData () { 109 protected loadData () {
39 return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort) 110 return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort)
40 .subscribe( 111 .subscribe(