From f85c2cd393152b2c190f91b2fe37807db8d7a5f3 Mon Sep 17 00:00:00 2001
From: tekay <tom.kaesler@mni.thm.de>
Date: Wed, 8 Apr 2020 12:23:00 +0200
Subject: [PATCH] Allow filtering for userid for moderator view

---
 .../moderator-comment-list.component.html            |  5 +++--
 .../moderator-comment-list.component.ts              | 12 +++++++++++-
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.html b/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.html
index 71bbcd7ad..7bd79f671 100644
--- a/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.html
+++ b/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.html
@@ -67,8 +67,9 @@
 </button>
 
 <div *ngIf="!isLoading">
-  <app-comment *ngFor="let current of comments" [comment]="current" [userRole]="user.role"
-               [parseVote]="getVote(current)" [moderator]="true"></app-comment>
+  <app-comment *ngFor="let current of hideCommentsList ? filteredComments : comments" [comment]="current" [userRole]="user.role"
+               [parseVote]="getVote(current)" [moderator]="true" (clickedUserNumber)="clickedUserNumber($event)">
+              </app-comment>
 </div>
 
 <div *ngIf="comments && comments.length < 1 && !isLoading" fxLayout="row" fxLayoutAlign="center center"
diff --git a/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts b/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts
index 218a71388..4e454b740 100644
--- a/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts
+++ b/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts
@@ -44,6 +44,7 @@ export class ModeratorCommentListComponent implements OnInit {
   correct = 'correct';
   wrong = 'wrong';
   ack = 'ack';
+  userNumber = 'userNumber';
   currentFilter = '';
   commentVoteMap = new Map<string, Vote>();
   scroll = false;
@@ -204,6 +205,8 @@ export class ModeratorCommentListComponent implements OnInit {
         c.body = payload.body;
         c.id = payload.id;
         c.timestamp = payload.timestamp;
+        c.creatorId = payload.creatorId;
+        c.userNumber = this.commentService.hashCode(c.creatorId);
         this.comments = this.comments.concat(c);
         break;
     }
@@ -212,7 +215,7 @@ export class ModeratorCommentListComponent implements OnInit {
     this.searchComments();
   }
 
-  filterComments(type: string): void {
+  filterComments(type: string, compare?: any): void {
     this.currentFilter = type;
     if (type === '') {
       this.filteredComments = this.comments;
@@ -230,11 +233,18 @@ export class ModeratorCommentListComponent implements OnInit {
           return c.read;
         case this.unread:
           return !c.read;
+        case this.userNumber:
+          return c.userNumber === compare;
       }
     });
+    this.hideCommentsList = true;
     this.sortComments(this.currentSort);
   }
 
+  clickedUserNumber(usrNumber: number): void {
+    this.filterComments(this.userNumber, usrNumber);
+  }
+
   sort(array: any[], type: string): void {
     array.sort((a, b) => {
       if (type === this.voteasc) {
-- 
GitLab