From ef80621ab88b00ea28c97da8135307d9f836dcfb Mon Sep 17 00:00:00 2001
From: Stefan Plociennik <stefan.plociennik@mni.thm.de>
Date: Mon, 17 May 2021 15:56:27 +0200
Subject: [PATCH] removed cloned keyword array

---
 .../topic-cloud-administration.component.html |  3 +-
 .../topic-cloud-administration.component.ts   | 32 +++----------------
 .../topic-dialog-comment.component.ts         |  7 ++--
 .../util/topic-cloud-admin.service.ts         |  4 +--
 4 files changed, 12 insertions(+), 34 deletions(-)

diff --git a/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.html b/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.html
index b5c37e048..681b23824 100644
--- a/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.html
+++ b/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.html
@@ -114,8 +114,7 @@
     <mat-expansion-panel (opened)="panelOpenState = true"
                          (closed)="panelOpenState = edit = false"
                          *ngFor="let keyword of
-                         (searchMode ? filteredKeywords :
-                         (profanityFilter ? keywordsWithProfanity : keywords)); let i = index" [attr.data-index]="i">
+                         (searchMode ? filteredKeywords : keywords); let i = index" [attr.data-index]="i">
       <mat-expansion-panel-header class="color">
         <mat-panel-title [ngClass]="{'edit-keyword': editedKeyword}">
           {{keyword.keyword}}
diff --git a/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.ts b/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.ts
index ca9d02ce6..e8cd5099d 100644
--- a/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.ts
+++ b/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.ts
@@ -23,16 +23,15 @@ export class TopicCloudAdministrationComponent implements OnInit {
   newKeyword = undefined;
   edit = false;
   isCreatorOrMod: boolean;
-  enterBadword: boolean = false;
+  enterBadword = false;
   newBadWord: string = undefined;
-  keywordsWithProfanity: Keyword[] = [];
 
   sortMode = 'alphabetic';
   editedKeyword = false;
   searchedKeyword = undefined;
   searchMode = false;
   filteredKeywords: Keyword[] = [];
-  model=new FormControl('');
+  model = new FormControl('');
   output: any | undefined;
   newOutput: [];
 
@@ -88,6 +87,8 @@ export class TopicCloudAdministrationComponent implements OnInit {
         'Englisch: Fuck you!',
         'Deutsch: Fick dich!',
         'Französisch: Gros con!',
+        'Multi language: Ficken, Fuck, con',
+        'Custom: Nieder mit KQC'
       ]
     },
 
@@ -111,13 +112,7 @@ export class TopicCloudAdministrationComponent implements OnInit {
     this.translateService.use(localStorage.getItem('currentLang'));
     this.checkIfUserIsModOrCreator();
     this.checkIfThereAreQuestions();
-    this.refreshProfanityFilter();
     this.sortQuestions();
-    this.cloneKeywords();
-  }
-
-  cloneKeywords(){
-    this.keywordsWithProfanity = JSON.parse(JSON.stringify(this.keywords));
   }
 
   sortQuestions(sortMode?: string) {
@@ -214,15 +209,9 @@ export class TopicCloudAdministrationComponent implements OnInit {
     if (!this.searchedKeyword){
         this.searchMode = false;
     } else {
-      if (this.profanityFilter){
-        this.filteredKeywords = this.keywordsWithProfanity.filter(keyword =>
-          keyword.keyword.toLowerCase().includes(this.searchedKeyword.toLowerCase())
-        );
-      } else {
         this.filteredKeywords = this.keywords.filter(keyword =>
           keyword.keyword.toLowerCase().includes(this.searchedKeyword.toLowerCase())
         );
-      }
       this.searchMode = true;
     }
   }
@@ -277,25 +266,14 @@ export class TopicCloudAdministrationComponent implements OnInit {
   selectedLang = localStorage.getItem('currentLang');
   comment: Comment;
 
-  addBadword(){
+  addBadword() {
     this.topicCloudAdminService.addToBadwordList(this.newBadWord);
     this.newBadWord = undefined;
-    this.refreshProfanityFilter();
     if (this.searchMode){
       this.searchKeyword();
     }
   }
 
-  refreshProfanityFilter(){
-    for (let i = 0; i < this.keywordsWithProfanity.length; i++){
-      // TODO: filter also keywords
-      for (let j = 0; j < this.keywordsWithProfanity[i].questions.length; j++){
-        this.keywordsWithProfanity[i].questions[j] =
-        this.topicCloudAdminService.filterProfanityWords(this.keywords[i].questions[j]);
-      }
-    }
-  }
-
   refreshAllLists(){
     this.searchKeyword();
   }
diff --git a/src/app/components/shared/dialog/topic-dialog-comment/topic-dialog-comment.component.ts b/src/app/components/shared/dialog/topic-dialog-comment/topic-dialog-comment.component.ts
index 18d28570e..73b5b508b 100644
--- a/src/app/components/shared/dialog/topic-dialog-comment/topic-dialog-comment.component.ts
+++ b/src/app/components/shared/dialog/topic-dialog-comment/topic-dialog-comment.component.ts
@@ -21,13 +21,14 @@ export class TopicDialogCommentComponent implements OnInit, OnChanges {
 
   constructor(private topicCloudAdminService: TopicCloudAdminService) { }
 
-  ngOnChanges(changes: SimpleChanges){
+  ngOnChanges(changes: SimpleChanges) {
   }
 
   get partsOfQuestion() {
     if (this.profanityFilter) {
-      return this.questionWithProfinity
-          .slice(0,this.isCollapsed? this.questionWithProfinity.length: this.maxShowedCharachters)
+      const question = this.topicCloudAdminService.filterProfanityWords(this.question);
+      return question
+          .slice(0,this.isCollapsed? this.question.length: this.maxShowedCharachters)
           .split(new RegExp(this.keyword,'i'));
     } else {
       return this.question
diff --git a/src/app/services/util/topic-cloud-admin.service.ts b/src/app/services/util/topic-cloud-admin.service.ts
index defa915a5..e4bec1924 100644
--- a/src/app/services/util/topic-cloud-admin.service.ts
+++ b/src/app/services/util/topic-cloud-admin.service.ts
@@ -15,13 +15,13 @@ export class TopicCloudAdminService {
 
   constructor() {
     this.badWords = BadWords;
-    this.badWords['custom'] = ['nieder mit kqc'];
+    this.badWords['custom'] = [];
   }
 
   filterProfanityWords(str: string): string {
     let questionWithProfanity = str;
     const questionLowerCase = str.toLowerCase();
-    
+
     // German Profanity
     this.badWords['de'].map(word =>{
       questionWithProfanity = questionLowerCase.includes(word.toLowerCase()) ?
-- 
GitLab