1 import { SortMeta } from 'primeng/api'
2 import { filter } from 'rxjs/operators'
3 import { AfterViewInit, Component, OnInit } from '@angular/core'
4 import { ActivatedRoute, Params, Router } from '@angular/router'
5 import { AuthService, ConfirmService, MarkdownService, Notifier, RestPagination, RestTable } from '@app/core'
6 import { DropdownAction } from '@app/shared/shared-main'
7 import { BulkService } from '@app/shared/shared-moderation'
8 import { VideoCommentAdmin, VideoCommentService } from '@app/shared/shared-video-comment'
9 import { FeedFormat, UserRight } from '@shared/models'
12 selector: 'my-video-comment-list',
13 templateUrl: './video-comment-list.component.html',
14 styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-comment-list.component.scss' ]
16 export class VideoCommentListComponent extends RestTable implements OnInit, AfterViewInit {
17 comments: VideoCommentAdmin[]
19 sort: SortMeta = { field: 'createdAt', order: -1 }
20 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
22 videoCommentActions: DropdownAction<VideoCommentAdmin>[][] = []
26 format: FeedFormat.RSS,
27 label: 'media rss 2.0',
28 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.RSS.toLowerCase()
31 format: FeedFormat.ATOM,
33 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.ATOM.toLowerCase()
36 format: FeedFormat.JSON,
38 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.JSON.toLowerCase()
43 return this.auth.getUser()
47 private auth: AuthService,
48 private notifier: Notifier,
49 private confirmService: ConfirmService,
50 private videoCommentService: VideoCommentService,
51 private markdownRenderer: MarkdownService,
52 private route: ActivatedRoute,
53 private router: Router,
54 private bulkService: BulkService
58 this.videoCommentActions = [
61 label: $localize`Delete this comment`,
62 handler: comment => this.deleteComment(comment),
63 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
67 label: $localize`Delete all comments of this account`,
68 description: $localize`Comments are deleted after a few minutes`,
69 handler: comment => this.deleteUserComments(comment),
70 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
79 this.route.queryParams
80 .pipe(filter(params => params.search !== undefined && params.search !== null))
81 .subscribe(params => {
82 this.search = params.search
83 this.setTableFilter(params.search)
89 if (this.search) this.setTableFilter(this.search)
92 onInputSearch (event: Event) {
94 this.setQueryParams((event.target as HTMLInputElement).value)
97 setQueryParams (search: string) {
98 const queryParams: Params = {}
100 if (search) Object.assign(queryParams, { search })
101 this.router.navigate([ '/admin/moderation/video-comments/list' ], { queryParams })
104 resetTableFilter () {
105 this.setTableFilter('')
106 this.setQueryParams('')
109 /* END Table filter functions */
112 return 'VideoCommentListComponent'
115 toHtml (text: string) {
116 return this.markdownRenderer.textMarkdownToHTML(text, true, true)
119 protected loadData () {
120 this.videoCommentService.getAdminVideoComments({
121 pagination: this.pagination,
125 async resultList => {
126 this.totalRecords = resultList.total
130 for (const c of resultList.data) {
132 new VideoCommentAdmin(c, await this.toHtml(c.text))
137 err => this.notifier.error(err.message)
141 private deleteComment (comment: VideoCommentAdmin) {
142 this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
144 () => this.loadData(),
146 err => this.notifier.error(err.message)
150 private async deleteUserComments (comment: VideoCommentAdmin) {
151 const message = $localize`Do you really want to delete all comments of ${comment.by}?`
152 const res = await this.confirmService.confirm(message, $localize`Delete`)
153 if (res === false) return
156 accountName: comment.by,
157 scope: 'instance' as 'instance'
160 this.bulkService.removeCommentsOf(options)
163 this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`)
166 err => this.notifier.error(err.message)