From 1dfb5669e5e22dfe8f6de55b33245a3e6ced6dad Mon Sep 17 00:00:00 2001
From: Stefan Plociennik <stefan.plociennik@mni.thm.de>
Date: Wed, 19 May 2021 17:09:55 +0200
Subject: [PATCH] add option to enter irrelevant topics; add toggle to hide
 irrelevant topics in cloud

---
 .../topic-cloud-administration.component.html | 37 ++++++++++++++++---
 .../topic-cloud-administration.component.ts   | 34 +++++++++++------
 .../util/topic-cloud-admin.service.ts         | 17 ++++++---
 3 files changed, 67 insertions(+), 21 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 535a65ca5..8c9066e9b 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
@@ -2,21 +2,24 @@
   <mat-card class="color-surface">
     <div>
       <mat-slide-toggle [(ngModel)]="considerVotes">
-          {{'topic-cloud-dialog.consider-votes' | translate}}
+        {{'topic-cloud-dialog.consider-votes' | translate}}
       </mat-slide-toggle>
       <mat-slide-toggle (change)="refreshAllLists()" [(ngModel)]="profanityFilter">
         {{'topic-cloud-dialog.profanity' | translate}}
       </mat-slide-toggle>
+      <mat-slide-toggle [(ngModel)]="hideIrrelevant">
+        {{'topic-cloud-dialog.hide-irrelevant' | translate}}
+      </mat-slide-toggle>
 
       <mat-accordion hideToggle class="new-Badword" multi>
         <mat-expansion-panel class="color-background"
                             (opened)="enterBadword = true; focusBadWordInput()"
                             (closed)="enterBadword = false">
-        <mat-expansion-panel-header class="color-background">
+          <mat-expansion-panel-header class="color-background">
             <mat-panel-description>
               {{'topic-cloud-dialog.add-profanity-word' | translate}}
-              <mat-icon>{{!enterBadword ? 'add' : 'remove'}}</mat-icon>
-            </mat-panel-description>
+                <mat-icon>{{!enterBadword ? 'add' : 'remove'}}</mat-icon>
+          </mat-panel-description>
           </mat-expansion-panel-header>
 
           <mat-form-field>
@@ -26,10 +29,34 @@
 
           <button mat-button color="primary" (click)="addBadword()">
             <mat-icon>add_circle</mat-icon>
-            {{'topic-cloud-dialog.send' | translate}}
+              {{'topic-cloud-dialog.send' | translate}}
+          </button>
+        </mat-expansion-panel>
+      <!-- </mat-accordion>
+
+      <mat-accordion hideToggle class="new-Badword" multi> -->
+        <mat-expansion-panel class="color-background"
+                            (opened)="enterIrrelevantWord = true; focusIrrelevantWordInput()"
+                            (closed)="enterIrrelevantWord = false">
+          <mat-expansion-panel-header class="color-background">
+            <mat-panel-description>
+              {{'topic-cloud-dialog.add-irrelevant-word' | translate}}
+                <mat-icon>{{!enterIrrelevantWord ? 'add' : 'remove'}}</mat-icon>
+          </mat-panel-description>
+          </mat-expansion-panel-header>
+
+          <mat-form-field>
+            <mat-label>{{'topic-cloud-dialog.enter-word' | translate}}</mat-label>
+            <input matInput id="irrelevant-word-input" [(ngModel)]="newIrrelevantWord">
+          </mat-form-field>
+
+          <button mat-button color="primary" (click)="addIrrelevantWord()">
+            <mat-icon>add_circle</mat-icon>
+              {{'topic-cloud-dialog.send' | translate}}
           </button>
         </mat-expansion-panel>
       </mat-accordion>
+
     </div>
    </mat-card>
 
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 ad2a3e3cc..8b306ff95 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
@@ -19,20 +19,20 @@ import { TopicCloudAdminService } from '../../../../services/util/topic-cloud-ad
 export class TopicCloudAdministrationComponent implements OnInit {
   public panelOpenState = false;
   public considerVotes: boolean; // should be sent back to tagCloud component
-  public profanityFilter = true;
+  public profanityFilter = true; // should be sent back to tagCloud component
+  public hideIrrelevant: boolean; // should be sent back to tagCloud component
   newKeyword = undefined;
   edit = false;
   isCreatorOrMod: boolean;
   enterBadword = false;
+  enterIrrelevantWord = false;
   newBadWord: string = undefined;
+  newIrrelevantWord: string = undefined;
 
   sortMode = 'alphabetic';
   searchedKeyword = undefined;
   searchMode = false;
   filteredKeywords: Keyword[] = [];
-  model = new FormControl('');
-  output: any | undefined;
-  isenddKeyword= true;
 
   keywords: Keyword[] = [
     {
@@ -93,16 +93,11 @@ export class TopicCloudAdministrationComponent implements OnInit {
 
   ];
 
-  getKeywordWithoutProfanity(keyword: string): string {
-    return this.topicCloudAdminService.filterProfanityWords(keyword);
-  }
-
   constructor(public cloudDialogRef: MatDialogRef<TagCloudComponent>,
               public confirmDialog: MatDialog,
               private notificationService: NotificationService,
               private authenticationService: AuthenticationService,
               private translateService: TranslateService,
-              private spacyService: SpacyService,
               private langService: LanguageService,
               private topicCloudAdminService: TopicCloudAdminService) {
 
@@ -118,6 +113,10 @@ export class TopicCloudAdministrationComponent implements OnInit {
     this.sortQuestions();
   }
 
+  getKeywordWithoutProfanity(keyword: string): string {
+    return this.topicCloudAdminService.filterProfanityWords(keyword);
+  }
+
   sortQuestions(sortMode?: string) {
     if (sortMode !== undefined) {
       this.sortMode = sortMode;
@@ -203,7 +202,6 @@ export class TopicCloudAdministrationComponent implements OnInit {
     confirmDialogRef.afterClosed().subscribe(result => {
       if (result === 'delete') {
         this.deleteKeyword(keyword);
-        this.isenddKeyword= false;
       }
     });
   }
@@ -245,7 +243,13 @@ export class TopicCloudAdministrationComponent implements OnInit {
       document.getElementById('bad-word-input').focus();
     }, 100);
   }
-  
+
+  focusIrrelevantWordInput() {
+    setTimeout(() => {
+      document.getElementById('irrelevant-word-input').focus();
+    }, 100);
+  }
+
   addBadword() {
     this.topicCloudAdminService.addToBadwordList(this.newBadWord);
     this.newBadWord = undefined;
@@ -254,6 +258,14 @@ export class TopicCloudAdministrationComponent implements OnInit {
     }
   }
 
+  addIrrelevantWord() {
+    this.topicCloudAdminService.addToIrrelevantwordList(this.newIrrelevantWord);
+    this.newIrrelevantWord = undefined;
+    if (this.searchMode){
+      this.searchKeyword();
+    }
+  }
+
   refreshAllLists(){
     this.searchKeyword();
   }
diff --git a/src/app/services/util/topic-cloud-admin.service.ts b/src/app/services/util/topic-cloud-admin.service.ts
index 7045451eb..ac2fac3ec 100644
--- a/src/app/services/util/topic-cloud-admin.service.ts
+++ b/src/app/services/util/topic-cloud-admin.service.ts
@@ -13,14 +13,15 @@ const httpOptions = {
 })
 export class TopicCloudAdminService extends BaseHttpService{
 
+  private badWords = [];
+  private irrelevantWords = [];
+
   constructor(private http: HttpClient) {
     super();
     this.badWords = BadWords;
     this.badWords['custom'] = [];
   }
 
-  private badWords = [];
-
   get getBadWordList(): string[]{
     return this.badWords['custom'];
   }
@@ -39,14 +40,20 @@ export class TopicCloudAdminService extends BaseHttpService{
     return questionWithProfanity;
   }
 
-  addToBadwordList(word: string){
+  addToBadwordList(word: string) {
     if (word !== undefined) {
       this.badWords['custom'].push(word);
     }
   }
 
+  addToIrrelevantwordList(word: string) {
+    if (word !== undefined) {
+      this.irrelevantWords.push(word);
+    }
+  }
+
   private replaceString(str: string, search: string, replace: string){
-    return str.split(search).join(replace); 
+    return str.split(search).join(replace);
   }
 
   private generateXWord(count: number){
@@ -56,4 +63,4 @@ export class TopicCloudAdminService extends BaseHttpService{
     }
     return res;
   }
-}
\ No newline at end of file
+}
-- 
GitLab