From 3acb03abc70a8330e475e885b6ba097c2227e868 Mon Sep 17 00:00:00 2001
From: Lukas Haase <lukas.haase@mni.thm.de>
Date: Tue, 31 Aug 2021 19:56:22 +0200
Subject: [PATCH] add up and downvotes for lecturer as tooltip

---
 .../shared/comment/comment.component.html     |  5 ++++-
 .../shared/comment/comment.component.ts       | 19 +++++++++++++++++--
 src/app/services/http/comment.service.ts      |  1 -
 src/assets/i18n/creator/de.json               |  4 +++-
 src/assets/i18n/creator/en.json               |  4 +++-
 src/assets/i18n/participant/de.json           |  4 +++-
 src/assets/i18n/participant/en.json           |  4 +++-
 7 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/src/app/components/shared/comment/comment.component.html b/src/app/components/shared/comment/comment.component.html
index bd009b1e9..03b0a3a05 100644
--- a/src/app/components/shared/comment/comment.component.html
+++ b/src/app/components/shared/comment/comment.component.html
@@ -300,7 +300,10 @@
       <div *ngIf="!isStudent"
            fxLayout="column"
            fxLayoutAlign="center">
-        <span class="scoreCreator">{{comment.score}}</span>
+        <span class="scoreCreator" matTooltip="{{
+        ('comment-page.upvote' | translate) + ' ' + upvotes + ' | ' +
+        ('comment-page.downvote' | translate) + ' ' + downvotes
+        }}">{{comment.score}}</span>
       </div>
     </div>
     <ars-row #commentExpander
diff --git a/src/app/components/shared/comment/comment.component.ts b/src/app/components/shared/comment/comment.component.ts
index 76f7e91fa..e381d689c 100644
--- a/src/app/components/shared/comment/comment.component.ts
+++ b/src/app/components/shared/comment/comment.component.ts
@@ -1,4 +1,4 @@
-import { Component, Input, Output, OnInit, EventEmitter, ViewChild, AfterViewInit } from '@angular/core';
+import { Component, Input, Output, OnInit, EventEmitter, ViewChild, AfterViewInit, OnDestroy } from '@angular/core';
 import { Comment } from '../../../models/comment';
 import { Vote } from '../../../models/vote';
 import { AuthenticationService } from '../../../services/http/authentication.service';
@@ -34,7 +34,7 @@ import { UserBonusTokenComponent } from '../../participant/_dialogs/user-bonus-t
   ]
 })
 
-export class CommentComponent implements OnInit, AfterViewInit {
+export class CommentComponent implements OnInit, AfterViewInit, OnDestroy {
 
   static COMMENT_MAX_HEIGHT = 200;
 
@@ -65,6 +65,9 @@ export class CommentComponent implements OnInit, AfterViewInit {
   selectedKeyword = '';
   filterProfanityForModerators = false;
   createdBy;
+  voteInterval;
+  upvotes;
+  downvotes;
 
   constructor(protected authenticationService: AuthenticationService,
     private route: ActivatedRoute,
@@ -101,6 +104,18 @@ export class CommentComponent implements OnInit, AfterViewInit {
     this.translateService.use(this.language);
     this.deviceType = localStorage.getItem('deviceType');
     this.inAnswerView = !this.router.url.includes('comments');
+    this.voteInterval=setInterval(()=>{
+      if(this.comment){
+        this.commentService.getComment(this.comment.id).subscribe(e=>{
+          this.upvotes=e.upvotes;
+          this.downvotes=e.downvotes;
+        });
+      }
+    },1000);
+  }
+
+  ngOnDestroy(){
+    clearInterval(this.voteInterval);
   }
 
   checkProfanity(){
diff --git a/src/app/services/http/comment.service.ts b/src/app/services/http/comment.service.ts
index 4befb9e3b..7f82202e3 100644
--- a/src/app/services/http/comment.service.ts
+++ b/src/app/services/http/comment.service.ts
@@ -235,7 +235,6 @@ export class CommentService extends BaseHttpService {
     comment.keywordsFromQuestioner = comment.keywordsFromQuestioner ?
                                      JSON.parse(comment.keywordsFromQuestioner as unknown as string) : null;
     comment.keywordsFromSpacy = comment.keywordsFromSpacy ? JSON.parse(comment.keywordsFromSpacy as unknown as string) : null;
-    console.log(comment);
     return comment;
   }
 
diff --git a/src/assets/i18n/creator/de.json b/src/assets/i18n/creator/de.json
index 381960d8c..23e81df1c 100644
--- a/src/assets/i18n/creator/de.json
+++ b/src/assets/i18n/creator/de.json
@@ -191,7 +191,9 @@
     "edit-bookmark-reset": "Markierung zurücksetzen",
     "grammar-check": "Rechtschreibprüfung",
     "show-comment-with-filter": "Vulgäre Wörter ausixen",
-    "show-comment-without-filter": "Vulgäre Wörter anzeigen"
+    "show-comment-without-filter": "Vulgäre Wörter anzeigen",
+    "upvote": "positiv",
+    "downvote": "negativ"
   },
   "content": {
     "abort": "Abbrechen",
diff --git a/src/assets/i18n/creator/en.json b/src/assets/i18n/creator/en.json
index daf3b2b01..043d45991 100644
--- a/src/assets/i18n/creator/en.json
+++ b/src/assets/i18n/creator/en.json
@@ -192,7 +192,9 @@
     "edit-bookmark-reset": "Remove marker",
     "grammar-check": "Spell check",
     "show-comment-with-filter": "Hide vulgar words",
-    "show-comment-without-filter": "Show vulgar words"
+    "show-comment-without-filter": "Show vulgar words",
+    "upvote": "upvotes",
+    "downvote": "downvotes"
   },
   "content": {
     "abort": "Abort",
diff --git a/src/assets/i18n/participant/de.json b/src/assets/i18n/participant/de.json
index 7a63a6d40..8bd491462 100644
--- a/src/assets/i18n/participant/de.json
+++ b/src/assets/i18n/participant/de.json
@@ -158,7 +158,9 @@
     "show-more": "Mehr ansehen",
     "show-less": "Weniger anzeigen",
     "sure": "Bist du sicher?",
-    "grammar-check": "Rechtschreibprüfung"
+    "grammar-check": "Rechtschreibprüfung",
+    "upvote": "positiv",
+    "downvote": "negativ"
   },
   "home-page": {
     "exactly-8": "Ein Raum-Code hat genau 8 Ziffern.",
diff --git a/src/assets/i18n/participant/en.json b/src/assets/i18n/participant/en.json
index 936d67e96..54c36344b 100644
--- a/src/assets/i18n/participant/en.json
+++ b/src/assets/i18n/participant/en.json
@@ -167,7 +167,9 @@
     "show-more": "Show more",
     "show-less": "Show less",
     "delete": "Delete question",
-    "grammar-check": "Spell check"
+    "grammar-check": "Spell check",
+    "upvote": "upvotes",
+    "downvote": "downvotes"
   },
   "home-page": {
     "exactly-8": "A key is a combination of 8 digits.",
-- 
GitLab