]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts
Refractor notification service
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / moderation / video-abuse-list / video-abuse-list.component.ts
... / ...
CommitLineData
1import { Component, OnInit, ViewChild } from '@angular/core'
2import { Account } from '../../../shared/account/account.model'
3import { Notifier } from '@app/core'
4import { SortMeta } from 'primeng/components/common/sortmeta'
5import { VideoAbuse, VideoAbuseState } from '../../../../../../shared'
6import { RestPagination, RestTable, VideoAbuseService } from '../../../shared'
7import { I18n } from '@ngx-translate/i18n-polyfill'
8import { DropdownAction } from '../../../shared/buttons/action-dropdown.component'
9import { ConfirmService } from '../../../core/index'
10import { ModerationCommentModalComponent } from './moderation-comment-modal.component'
11import { Video } from '../../../shared/video/video.model'
12
13@Component({
14 selector: 'my-video-abuse-list',
15 templateUrl: './video-abuse-list.component.html',
16 styleUrls: [ '../moderation.component.scss']
17})
18export class VideoAbuseListComponent extends RestTable implements OnInit {
19 @ViewChild('moderationCommentModal') moderationCommentModal: ModerationCommentModalComponent
20
21 videoAbuses: VideoAbuse[] = []
22 totalRecords = 0
23 rowsPerPage = 10
24 sort: SortMeta = { field: 'createdAt', order: 1 }
25 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
26
27 videoAbuseActions: DropdownAction<VideoAbuse>[] = []
28
29 constructor (
30 private notifier: Notifier,
31 private videoAbuseService: VideoAbuseService,
32 private confirmService: ConfirmService,
33 private i18n: I18n
34 ) {
35 super()
36
37 this.videoAbuseActions = [
38 {
39 label: this.i18n('Delete this report'),
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 ]
57 }
58
59 ngOnInit () {
60 this.initialize()
61 }
62
63 openModerationCommentModal (videoAbuse: VideoAbuse) {
64 this.moderationCommentModal.openModal(videoAbuse)
65 }
66
67 onModerationCommentUpdated () {
68 this.loadData()
69 }
70
71 createByString (account: Account) {
72 return Account.CREATE_BY_STRING(account.name, account.host)
73 }
74
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
83 getVideoUrl (videoAbuse: VideoAbuse) {
84 return Video.buildClientUrl(videoAbuse.video.uuid)
85 }
86
87 async removeVideoAbuse (videoAbuse: VideoAbuse) {
88 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete'))
89 if (res === false) return
90
91 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
92 () => {
93 this.notifier.success(this.i18n('Abuse deleted.'))
94 this.loadData()
95 },
96
97 err => this.notifier.error(err.message)
98 )
99 }
100
101 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
102 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
103 .subscribe(
104 () => this.loadData(),
105
106 err => this.notifier.error(err.message)
107 )
108
109 }
110
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
119 err => this.notifier.error(err.message)
120 )
121 }
122}