diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-14 16:38:37 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-14 18:01:22 +0200 |
commit | 614d1ae928ec307b708c4a3eb423797353b1df2a (patch) | |
tree | 8281785fc158073e56d31a9e1923906b72622ae2 /client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts | |
parent | 65b247ddc75aa9f131af86dde21c8d958f7f4b39 (diff) | |
download | PeerTube-614d1ae928ec307b708c4a3eb423797353b1df2a.tar.gz PeerTube-614d1ae928ec307b708c4a3eb423797353b1df2a.tar.zst PeerTube-614d1ae928ec307b708c4a3eb423797353b1df2a.zip |
Regroup abuse and blacklisted videos inside "moderation"
Diffstat (limited to 'client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts')
-rw-r--r-- | client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts new file mode 100644 index 000000000..b17278b94 --- /dev/null +++ b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts | |||
@@ -0,0 +1,125 @@ | |||
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' | ||
12 | |||
13 | @Component({ | ||
14 | selector: 'my-video-abuse-list', | ||
15 | templateUrl: './video-abuse-list.component.html', | ||
16 | styleUrls: [ './video-abuse-list.component.scss'] | ||
17 | }) | ||
18 | export 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 notificationsService: NotificationsService, | ||
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'), | ||
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.loadSort() | ||
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?'), 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 | |||
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 | |||
122 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
123 | ) | ||
124 | } | ||
125 | } | ||