From 2f851253319f3983139b0fd04de9b5e49589eedd Mon Sep 17 00:00:00 2001
From: Ruben Bimberg <ruben.bimberg@mni.thm.de>
Date: Wed, 16 Jun 2021 17:05:41 +0200
Subject: [PATCH] Remove unused comments

---
 .../spacy-dialog/spacy-dialog.component.ts    | 27 ++++----
 .../tag-cloud-pop-up.component.ts             | 19 +++++-
 .../shared/tag-cloud/tag-cloud.component.ts   | 63 ++++++++++---------
 3 files changed, 62 insertions(+), 47 deletions(-)

diff --git a/src/app/components/shared/_dialogs/spacy-dialog/spacy-dialog.component.ts b/src/app/components/shared/_dialogs/spacy-dialog/spacy-dialog.component.ts
index 81d59bd1c..b6c385d69 100644
--- a/src/app/components/shared/_dialogs/spacy-dialog/spacy-dialog.component.ts
+++ b/src/app/components/shared/_dialogs/spacy-dialog/spacy-dialog.component.ts
@@ -62,16 +62,17 @@ export class SpacyDialogComponent implements OnInit, AfterContentInit {
   }
 
   evalInput(model: Model) {
-    const keywords: Keyword[] = [];
     this.isLoading = true;
 
     // N at first pos = all Nouns(NN de/en) including singular(NN, NNP en), plural (NNPS, NNS en), proper Noun(NNE, NE de)
     this.spacyService.getKeywords(this.commentBodyChecked, model)
       .subscribe(words => {
+        const keywords: Keyword[] = [];
         for (const word of words) {
-          if (keywords.findIndex(item => item.word === word) < 0) {
+          const newWord = word.trim();
+          if (keywords.findIndex(item => item.word === newWord) < 0) {
             keywords.push({
-              word,
+              word: newWord,
               completed: false,
               editing: false,
               selected: false
@@ -80,8 +81,8 @@ export class SpacyDialogComponent implements OnInit, AfterContentInit {
         }
 
         // Deep copy
-        this.keywords = JSON.parse(JSON.stringify(keywords));
-        this.keywordsOriginal = JSON.parse(JSON.stringify(keywords));;
+        this.keywords = keywords;
+        this.keywordsOriginal = JSON.parse(JSON.stringify(keywords));
       }, () => {
         this.keywords = [];
         this.keywordsOriginal = [];
@@ -116,15 +117,15 @@ export class SpacyDialogComponent implements OnInit, AfterContentInit {
     }
   }
 
-  manualKeywordsToKeywords(){
-    const tempKeywords = this.manualKeywords.replace(/\s/g,'');
-    if(tempKeywords.length) {
+  manualKeywordsToKeywords() {
+    const tempKeywords = this.manualKeywords.replace(/\s/g, '');
+    if (tempKeywords.length) {
       this.keywords = tempKeywords.split(',').map((keyword) => (
-         {
-            word: keyword,
-            completed: true,
-            editing: false,
-            selected: true
+        {
+          word: keyword,
+          completed: true,
+          editing: false,
+          selected: true
         }
       ));
     } else {
diff --git a/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.ts b/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.ts
index c4fed49e8..0c25bfda2 100644
--- a/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.ts
+++ b/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.ts
@@ -81,7 +81,11 @@ export class TagCloudPopUpComponent implements OnInit, AfterViewInit {
     this.checkLanguage = checkLanguage;
     if (checkLanguage) {
       this.spellingData = [];
-      this.languagetoolService.checkSpellings(tag, this.selectedLang).subscribe(correction => {
+      this.languagetoolService.checkSpellings(tag, 'auto').subscribe(correction => {
+        const langKey = correction.language.code.split('-')[0].toUpperCase();
+        if (['DE', 'FR', 'EN'].indexOf(langKey) < 0) {
+          return;
+        }
         for (const match of correction.matches) {
           if (match.replacements != null && match.replacements.length > 0) {
             for (const replacement of match.replacements) {
@@ -137,11 +141,20 @@ export class TagCloudPopUpComponent implements OnInit, AfterViewInit {
         array[index] = tagReplacementInput;
       }
     };
+    const tagReplacementInputLower = tagReplacementInput.toLowerCase();
     this.tagData.comments.forEach(comment => {
       const changes = new TSMap<string, any>();
-      comment.keywordsFromQuestioner.forEach(renameKeyword);
+      if (comment.keywordsFromQuestioner.findIndex(e => e.toLowerCase() === tagReplacementInputLower) >= 0) {
+        comment.keywordsFromQuestioner = comment.keywordsFromQuestioner.filter(e => e !== this.tag);
+      } else {
+        comment.keywordsFromQuestioner.forEach(renameKeyword);
+      }
       changes.set('keywordsFromQuestioner', JSON.stringify(comment.keywordsFromQuestioner));
-      comment.keywordsFromSpacy.forEach(renameKeyword);
+      if (comment.keywordsFromSpacy.findIndex(e => e.toLowerCase() === tagReplacementInputLower) >= 0) {
+        comment.keywordsFromSpacy = comment.keywordsFromSpacy.filter(e => e !== this.tag);
+      } else {
+        comment.keywordsFromSpacy.forEach(renameKeyword);
+      }
       changes.set('keywordsFromSpacy', JSON.stringify(comment.keywordsFromSpacy));
       this.commentService.patchComment(comment, changes).subscribe(_ => {
         this.translateService.get('topic-cloud-dialog.keyword-edit').subscribe(msg => {
diff --git a/src/app/components/shared/tag-cloud/tag-cloud.component.ts b/src/app/components/shared/tag-cloud/tag-cloud.component.ts
index 86af6e98d..615d6f17d 100644
--- a/src/app/components/shared/tag-cloud/tag-cloud.component.ts
+++ b/src/app/components/shared/tag-cloud/tag-cloud.component.ts
@@ -61,20 +61,33 @@ class TagComment implements CloudData {
 
 const colorRegex = /rgba?\((\d+), (\d+), (\d+)(?:, (\d(?:\.\d+)?))?\)/;
 const transformationScaleKiller = /scale\([^)]*\)/;
-const defaultColors: string[] = [
-  // variable, fallback
-  'var(--secondary, greenyellow)', // hover
-  'var(--moderator, lightblue)', // w1
-  'var(--blue, green)', // w2
-  'var(--grey, yellow)', // w3
-  'var(--red, orange)', // w4
-  'var(--primary, pink)', // w5
-  'var(--yellow, gray)', // w6
-  'var(--on-background, lightgreen)', // w7
-  'var(--purple, tomato)', // w8
-  'var(--magenta, white)', // w9
-  'var(--light-green, brown)', // w10
-  'var(--background, black)' //background
+type DefaultColors = [
+  hover: string,
+  w1: string,
+  w2: string,
+  w3: string,
+  w4: string,
+  w5: string,
+  w6: string,
+  w7: string,
+  w8: string,
+  w9: string,
+  w10: string,
+  background: string
+];
+const defaultColors: DefaultColors = [
+  'var(--secondary, greenyellow)',
+  'var(--moderator, lightblue)',
+  'var(--blue, green)',
+  'var(--grey, yellow)',
+  'var(--red, orange)',
+  'var(--primary, pink)',
+  'var(--yellow, gray)',
+  'var(--on-background, lightgreen)',
+  'var(--purple, tomato)',
+  'var(--magenta, white)',
+  'var(--light-green, brown)',
+  'var(--background, black)'
 ];
 
 const getResolvedDefaultColors = (): string[] => {
@@ -83,7 +96,7 @@ const getResolvedDefaultColors = (): string[] => {
   document.body.appendChild(elem);
   const results = [];
   for (const color of defaultColors) {
-    elem.style.backgroundColor = 'rgb(0, 0, 0)'; // fallback
+    elem.style.backgroundColor = 'rgb(0, 0, 0)';
     elem.style.backgroundColor = color;
     const result = window.getComputedStyle(elem).backgroundColor.match(colorRegex);
     const r = parseInt(result[1], 10);
@@ -145,18 +158,16 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy {
   directSend = true;
   shortId: string;
   options: CloudOptions = {
-    // if width is between 0 and 1 it will be set to the width of the upper element multiplied by the value
     width: 1,
-    // if height is between 0 and 1 it will be set to the height of the upper element multiplied by the value
     height: 1,
     overflow: false,
-    font: 'Georgia', // not working
+    font: 'Not used',
     delay: 0
   };
   zoomOnHoverOptions: ZoomOnHoverOptions = {
-    scale: 1.3, // Elements will become 130 % of current size on hover
-    transitionTime: 0.6, // it will take 0.6 seconds until the zoom level defined in scale property has been reached
-    delay: 0.4 // Zoom will take affect after 0.4 seconds
+    scale: 1.3,
+    transitionTime: 0.6,
+    delay: 0.4
   };
   userRole: UserRole;
   data: TagComment[] = [];
@@ -164,7 +175,6 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy {
   lastDebounceTime = 0;
   configurationOpen = false;
   isLoading = true;
-  //Subscriptions
   headerInterface = null;
   themeSubscription = null;
   private _currentSettings: CloudParameters;
@@ -382,7 +392,6 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy {
       return;
     }
     this._subscriptionCommentlist = this.eventService.on('commentListCreated').subscribe(() => {
-      //send tag.text instead of 'Autos' -> wait for group 3 to implement...
       this.eventService.broadcast('setTagConfig', tag.text);
       this._subscriptionCommentlist.unsubscribe();
     });
@@ -412,7 +421,6 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy {
     if (!dataUpdate) {
       this.child.reDraw();
     }
-    // This should fix the hover bug (scale was not turned off sometimes)
     if (this.dataManager.currentData === null) {
       return;
     }
@@ -441,7 +449,6 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy {
     for (let i = rules.length - 1; i >= 0; i--) {
       customTagCloudStyles.sheet.deleteRule(i);
     }
-    // global
     let textTransform = '';
     if (this._currentSettings.textTransform === CloudTextStyle.capitalized) {
       textTransform = 'text-transform: capitalize;';
@@ -455,7 +462,6 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy {
       'font-size: ' + this._currentSettings.fontSize + '; ' +
       'font-weight: ' + this._currentSettings.fontWeight + '; ' +
       'font-style:' + this._currentSettings.fontStyle + '; }');
-    // custom spans
     const fontRange = (this._currentSettings.fontSizeMax - this._currentSettings.fontSizeMin) / 10;
     for (let i = 1; i <= 10; i++) {
       customTagCloudStyles.sheet.insertRule('.spacyTagCloud > span.w' + i + ', ' +
@@ -479,15 +485,11 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy {
     if (!this._currentSettings) {
       return 2;
     }
-    /*
-    hoverScale, hoverTime, hoverDelay, delayWord can be updated without refreshing
-     */
     const cssUpdates = ['backgroundColor', 'fontColor'];
     const dataUpdates = ['randomAngles', 'sortAlphabetically',
       'fontSizeMin', 'fontSizeMax', 'textTransform', 'fontStyle', 'fontWeight', 'fontFamily', 'fontSize'];
     const cssWeightUpdates = ['color'];
     const dataWeightUpdates = ['maxVisibleElements', 'rotation'];
-    //data updates
     for (const key of dataUpdates) {
       if (this._currentSettings[key] !== parameters[key]) {
         return 2;
@@ -500,7 +502,6 @@ export class TagCloudComponent implements OnInit, AfterViewInit, OnDestroy {
         }
       }
     }
-    //css updates
     for (const key of cssUpdates) {
       if (this._currentSettings[key] !== parameters[key]) {
         return 1;
-- 
GitLab