From ce1553d8e0f5f5e9db1331f9b8c5055c2b68413e Mon Sep 17 00:00:00 2001
From: Hagen <hagen.dressler@mni.thm.de>
Date: Tue, 13 Mar 2018 12:29:47 +0100
Subject: [PATCH] Fix bugs

---
 src/app/comment-list/comment-list.component.html   |  4 ++--
 src/app/comment-list/comment-list.component.ts     | 11 ++++++++---
 src/app/comment.ts                                 |  2 +-
 src/app/create-comment/create-comment.component.ts |  5 ++++-
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/app/comment-list/comment-list.component.html b/src/app/comment-list/comment-list.component.html
index cafb90256..53058da0a 100644
--- a/src/app/comment-list/comment-list.component.html
+++ b/src/app/comment-list/comment-list.component.html
@@ -7,7 +7,7 @@
 
             {{comment.body}}
 
-            <div class="body-buttons" *ngIf="userRole === CREATOR">
+            <div class="body-buttons" *ngIf="userRole === userRoleTemp">
               <button *ngIf="!comment.read" mat-fab color="warn" matTooltip="Is not read" (click)="setRead(comment)">
                 <mat-icon>clear</mat-icon>
               </button>
@@ -27,6 +27,6 @@
         </mat-card><br>
       </div>
 
-    <button *ngIf="userRole === CREATOR" mat-raised-button color="primary" (click)="goBack()">Back</button>
+    <button *ngIf="userRole === userRoleTemp" mat-raised-button color="primary" (click)="goBack()">Back</button>
   </div>
 </div>
diff --git a/src/app/comment-list/comment-list.component.ts b/src/app/comment-list/comment-list.component.ts
index 9c758e770..64a0dc403 100644
--- a/src/app/comment-list/comment-list.component.ts
+++ b/src/app/comment-list/comment-list.component.ts
@@ -15,6 +15,7 @@ import { User } from '../user';
   styleUrls: ['./comment-list.component.scss']
 })
 export class CommentListComponent implements OnInit {
+  userRoleTemp: any = UserRole.CREATOR;
   userRole: UserRole;
   user: User;
   comments: Comment[];
@@ -43,9 +44,13 @@ export class CommentListComponent implements OnInit {
   }
 
   getComments(roomId: string): void {
-    console.log(this.user.id);
-    this.commentService.searchComments(roomId, this.user.id)
-      .subscribe(comments => this.comments = comments);
+    if (this.userRole === UserRole.CREATOR) {
+      this.commentService.getComments(roomId)
+        .subscribe(comments => this.comments = comments);
+    } else if (this.userRole === UserRole.PARTICIPANT) {
+      this.commentService.searchComments(roomId, this.user.id)
+        .subscribe(comments => this.comments = comments);
+    }
   }
 
   setRead(comment: Comment): void {
diff --git a/src/app/comment.ts b/src/app/comment.ts
index ed636d119..4cf12e8cf 100644
--- a/src/app/comment.ts
+++ b/src/app/comment.ts
@@ -1,7 +1,7 @@
 export class Comment {
   id: string;
   roomId: string;
-  userId: string;
+  userId: number;
   revision: string;
   subject: string;
   body: string;
diff --git a/src/app/create-comment/create-comment.component.ts b/src/app/create-comment/create-comment.component.ts
index dedf7e08d..3d62dfa17 100644
--- a/src/app/create-comment/create-comment.component.ts
+++ b/src/app/create-comment/create-comment.component.ts
@@ -1,4 +1,4 @@
-import { Component, OnInit, Input } from '@angular/core';
+import { Component, OnInit, Input, ViewChild } from '@angular/core';
 import { ActivatedRoute } from '@angular/router';
 import { Location } from '@angular/common';
 import { Room } from '../room';
@@ -8,6 +8,7 @@ import { CommentService } from '../comment.service';
 import { NotificationService } from '../notification.service';
 import { AuthenticationService } from '../authentication.service';
 import { User } from '../user';
+import { CommentListComponent } from '../comment-list/comment-list.component';
 
 @Component({
   selector: 'app-create-comment',
@@ -15,6 +16,7 @@ import { User } from '../user';
   styleUrls: ['./create-comment.component.scss']
 })
 export class CreateCommentComponent implements OnInit {
+  @ViewChild(CommentListComponent) child: CommentListComponent;
   @Input() room: Room;
   user: User;
 
@@ -50,6 +52,7 @@ export class CreateCommentComponent implements OnInit {
       body: body,
       creationTimestamp: new Date(Date.now())
     } as Comment).subscribe(() => {
+      this.child.getComments(this.room.id);
       this.notification.show(`Comment '${subject}' successfully created.`);
     });
   }
-- 
GitLab