]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts
Refactor feed component
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / moderation / video-comment-list / video-comment-list.component.ts
index d260471259569dff7552502e97e2c780004cbf1a..63493d00d59ccd6600dc81ddb74ba239014829b6 100644 (file)
@@ -1,7 +1,6 @@
 import { SortMeta } from 'primeng/api'
-import { filter } from 'rxjs/operators'
 import { AfterViewInit, Component, OnInit } from '@angular/core'
-import { ActivatedRoute, Params, Router } from '@angular/router'
+import { ActivatedRoute, Router } from '@angular/router'
 import { AuthService, ConfirmService, MarkdownService, Notifier, RestPagination, RestTable } from '@app/core'
 import { DropdownAction } from '@app/shared/shared-main'
 import { BulkService } from '@app/shared/shared-moderation'
@@ -14,6 +13,8 @@ import { FeedFormat, UserRight } from '@shared/models'
   styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-comment-list.component.scss' ]
 })
 export class VideoCommentListComponent extends RestTable implements OnInit, AfterViewInit {
+  baseRoute = '/admin/moderation/video-comments/list'
+
   comments: VideoCommentAdmin[]
   totalRecords = 0
   sort: SortMeta = { field: 'createdAt', order: -1 }
@@ -39,18 +40,21 @@ export class VideoCommentListComponent extends RestTable implements OnInit, Afte
     }
   ]
 
+  selectedComments: VideoCommentAdmin[] = []
+  bulkCommentActions: DropdownAction<VideoCommentAdmin[]>[] = []
+
   get authUser () {
     return this.auth.getUser()
   }
 
   constructor (
+    protected router: Router,
+    protected route: ActivatedRoute,
     private auth: AuthService,
     private notifier: Notifier,
     private confirmService: ConfirmService,
     private videoCommentService: VideoCommentService,
     private markdownRenderer: MarkdownService,
-    private route: ActivatedRoute,
-    private router: Router,
     private bulkService: BulkService
     ) {
     super()
@@ -75,39 +79,22 @@ export class VideoCommentListComponent extends RestTable implements OnInit, Afte
 
   ngOnInit () {
     this.initialize()
-
-    this.route.queryParams
-      .pipe(filter(params => params.search !== undefined && params.search !== null))
-      .subscribe(params => {
-        this.search = params.search
-        this.setTableFilter(params.search)
-        this.loadData()
-      })
+    this.listenToSearchChange()
+
+    this.bulkCommentActions = [
+      {
+        label: $localize`Delete`,
+        handler: comments => this.removeComments(comments),
+        isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT),
+        iconName: 'delete'
+      }
+    ]
   }
 
   ngAfterViewInit () {
-    if (this.search) this.setTableFilter(this.search)
-  }
-
-  onInputSearch (event: Event) {
-    this.onSearch(event)
-    this.setQueryParams((event.target as HTMLInputElement).value)
-  }
-
-  setQueryParams (search: string) {
-    const queryParams: Params = {}
-
-    if (search) Object.assign(queryParams, { search })
-    this.router.navigate([ '/admin/moderation/video-comments/list' ], { queryParams })
+    if (this.search) this.setTableFilter(this.search, false)
   }
 
-  resetTableFilter () {
-    this.setTableFilter('')
-    this.setQueryParams('')
-    this.resetSearch()
-  }
-  /* END Table filter functions */
-
   getIdentifier () {
     return 'VideoCommentListComponent'
   }
@@ -116,6 +103,10 @@ export class VideoCommentListComponent extends RestTable implements OnInit, Afte
     return this.markdownRenderer.textMarkdownToHTML(text, true, true)
   }
 
+  isInSelectionMode () {
+    return this.selectedComments.length !== 0
+  }
+
   protected loadData () {
     this.videoCommentService.getAdminVideoComments({
       pagination: this.pagination,
@@ -138,6 +129,21 @@ export class VideoCommentListComponent extends RestTable implements OnInit, Afte
       )
   }
 
+  private async removeComments (comments: VideoCommentAdmin[]) {
+    const commentArgs = comments.map(c => ({ videoId: c.video.id, commentId: c.id }))
+
+    this.videoCommentService.deleteVideoComments(commentArgs).subscribe(
+      () => {
+        this.notifier.success($localize`${commentArgs.length} comments deleted.`)
+        this.loadData()
+      },
+
+      err => this.notifier.error(err.message),
+
+      () => this.selectedComments = []
+    )
+  }
+
   private deleteComment (comment: VideoCommentAdmin) {
     this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
       .subscribe(