diff --git a/src/app/components/shared/_dialogs/topic-cloud-administration/TopicCloudAdminData.ts b/src/app/components/shared/_dialogs/topic-cloud-administration/TopicCloudAdminData.ts index e20969aa89fd13f8f857dc00e9461068e1e795d7..cbbc0d8ebbf31b4d022a62cf117a359b4aa1cf2c 100644 --- a/src/app/components/shared/_dialogs/topic-cloud-administration/TopicCloudAdminData.ts +++ b/src/app/components/shared/_dialogs/topic-cloud-administration/TopicCloudAdminData.ts @@ -1,3 +1,5 @@ +import { ProfanityFilter } from '../../../../models/room'; + export interface TopicCloudAdminData { blacklist: string[]; wantedLabels: { @@ -5,7 +7,7 @@ export interface TopicCloudAdminData { en: string[]; }; considerVotes: boolean; - profanityFilter: boolean; + profanityFilter: ProfanityFilter; blacklistIsActive: boolean; keywordORfulltext: KeywordOrFulltext; } 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 2f918ec39dea22417943f1dc7ac40536aef1f9a8..bbbad73ffdab25f66475b291a2a39b0ba45438c1 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 @@ -27,17 +27,29 @@ </mat-radio-button> </mat-radio-group> </mat-card> - - <mat-slide-toggle [(ngModel)]="considerVotes"> - {{'topic-cloud-dialog.consider-votes' | translate}} - </mat-slide-toggle> - <div *ngIf="isCreatorOrMod"> - <mat-slide-toggle (change)="changeProfanityFilter()" [(ngModel)]="profanityFilter"> - {{'topic-cloud-dialog.profanity' | translate}} - </mat-slide-toggle> - <mat-slide-toggle [(ngModel)]="blacklistIsActive"> - {{'topic-cloud-dialog.hide-blacklist-words' | translate}} + + <mat-card style="background: none;"> + <mat-slide-toggle [(ngModel)]="considerVotes"> + {{'topic-cloud-dialog.consider-votes' | translate}} </mat-slide-toggle> + </mat-card> + <div *ngIf="isCreatorOrMod"> + <mat-card style="background: none;"> + <mat-slide-toggle (change)="changeProfanityFilter()" [(ngModel)]="profanityFilter"> + {{'topic-cloud-dialog.profanity' | translate}} + </mat-slide-toggle> + <mat-slide-toggle *ngIf="profanityFilter" (change)="changeProfanityFilter()" [(ngModel)]="censorLanguageSpecificCheck"> + Sprachspezifisch + </mat-slide-toggle> + <mat-slide-toggle *ngIf="profanityFilter" (change)="changeProfanityFilter()" [(ngModel)]="censorPartialWordsCheck"> + Teilwörter + </mat-slide-toggle> + </mat-card> + <mat-card style="background: none;"> + <mat-slide-toggle [(ngModel)]="blacklistIsActive"> + {{'topic-cloud-dialog.hide-blacklist-words' | translate}} + </mat-slide-toggle> + </mat-card> </div> <mat-accordion class="new-profanity-word" multi> @@ -225,7 +237,8 @@ <div *ngFor="let question of keyword.comments"> <mat-divider></mat-divider> <app-topic-dialog-comment [question]="question.body" [keyword]="keyword.keyword" [maxShowedCharachters]="140" - [profanityFilter]="profanityFilter"></app-topic-dialog-comment> + [profanityFilter]="profanityFilter" [languageSpecific]="censorLanguageSpecificCheck" + [partialWords]="censorPartialWordsCheck" [language]="question.language"></app-topic-dialog-comment> </div> <div *ngIf="isCreatorOrMod"> 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 5088205464787d718e56e630b759bfbdff170fb7..83dc251dcdd7bfa6b0b698fbdea0ab09c560ba2f 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 @@ -12,6 +12,7 @@ import { Comment } from '../../../../models/comment'; import { CommentService } from '../../../../services/http/comment.service'; import { TSMap } from 'typescript-map'; import { RoomDataService } from '../../../../services/util/room-data.service'; +import { ProfanityFilter } from '../../../../models/room'; @Component({ @@ -22,7 +23,6 @@ import { RoomDataService } from '../../../../services/util/room-data.service'; export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { public panelOpenState = false; public considerVotes: boolean; - public profanityFilter: boolean; public blacklistIsActive: boolean; blacklist: string[] = []; profanitywordlist: string[] = []; @@ -54,9 +54,11 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { }; spacyLabelsAllSelectedDE = true; isLoading: boolean; - keywords: Keyword[] = []; private topicCloudAdminData: TopicCloudAdminData; + private profanityFilter: boolean; + private censorPartialWordsCheck: boolean; + private censorLanguageSpecificCheck: boolean; constructor( @Inject(MAT_DIALOG_DATA) public data: Data, @@ -137,7 +139,7 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { const keyword: Keyword = { keyword: _keyword, keywordType: _keywordType, - keywordWithoutProfanity: this.getKeywordWithoutProfanity(_keyword), + keywordWithoutProfanity: this.getKeywordWithoutProfanity(_keyword, comment.language), comments: [comment], vote: comment.score }; @@ -201,6 +203,15 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { } setAdminData() { + let profFilter = this.profanityFilter ? ProfanityFilter.none : ProfanityFilter.deactivated; + if (this.profanityFilter) { + if (this.censorLanguageSpecificCheck && this.censorPartialWordsCheck) { + profFilter = ProfanityFilter.all; + } else { + profFilter = this.censorLanguageSpecificCheck ? ProfanityFilter.languageSpecific : ProfanityFilter.none; + profFilter = this.censorPartialWordsCheck ? ProfanityFilter.partialWords : profFilter; + } + } this.topicCloudAdminData = { blacklist: [], wantedLabels: { @@ -208,7 +219,7 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { en: this.wantedLabels.en }, considerVotes: this.considerVotes, - profanityFilter: this.profanityFilter, + profanityFilter: profFilter, blacklistIsActive: this.blacklistIsActive, keywordORfulltext: KeywordOrFulltext[this.keywordORfulltext] }; @@ -219,7 +230,13 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { this.topicCloudAdminData = TopicCloudAdminService.getDefaultAdminData; if (this.topicCloudAdminData) { this.considerVotes = this.topicCloudAdminData.considerVotes; - this.profanityFilter = this.topicCloudAdminData.profanityFilter; + this.profanityFilter = this.topicCloudAdminData.profanityFilter !== ProfanityFilter.deactivated; + if (this.topicCloudAdminData.profanityFilter === ProfanityFilter.all){ + this.censorLanguageSpecificCheck = this.censorPartialWordsCheck = true; + } else if (this.profanityFilter){ + this.censorLanguageSpecificCheck = this.topicCloudAdminData.profanityFilter === ProfanityFilter.languageSpecific; + this.censorPartialWordsCheck = this.topicCloudAdminData.profanityFilter === ProfanityFilter.partialWords; + } this.blacklistIsActive = this.topicCloudAdminData.blacklistIsActive; this.keywordORfulltext = KeywordOrFulltext[this.topicCloudAdminData.keywordORfulltext]; this.wantedLabels = { @@ -229,8 +246,8 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { } } - getKeywordWithoutProfanity(keyword: string): string { - return this.topicCloudAdminService.filterProfanityWords(keyword, true, false); + getKeywordWithoutProfanity(keyword: string, lang: string): string { + return this.topicCloudAdminService.filterProfanityWords(keyword, this.censorPartialWordsCheck, this.censorLanguageSpecificCheck, lang); } sortQuestions(sortMode?: string) { @@ -424,6 +441,7 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { this.searchKeyword(); } } + this.refreshKeywords(); } selectAllDE() { 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 2c58cb257810e1642c127b8af2f712a3d166b7fe..f5848afe0fe5c4ac4f37de5e89b33e834580f88c 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 @@ -1,4 +1,5 @@ -import { Component, Input, OnChanges, OnInit, SimpleChange, SimpleChanges } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; +import { Language } from '../../../../models/comment'; import { TopicCloudAdminService } from '../../../../services/util/topic-cloud-admin.service'; @Component({ @@ -9,9 +10,13 @@ import { TopicCloudAdminService } from '../../../../services/util/topic-cloud-ad export class TopicDialogCommentComponent implements OnInit { @Input() question: string; + @Input() language: Language; @Input() keyword: string ; @Input() maxShowedCharachters: number; - @Input() profanityFilter = true; + @Input() profanityFilter: boolean; + @Input() languageSpecific; + @Input() partialWords; + isCollapsed = false; public badWords = []; @@ -34,16 +39,20 @@ export class TopicDialogCommentComponent implements OnInit { splitShortQuestion(question: string){ const cleanedKeyword = this.keyword.replace(/([^a-z0-9]+)/gi, ''); - return question.slice(0, this.maxShowedCharachters).split(new RegExp(cleanedKeyword, 'i')); + return question.slice(0, this.maxShowedCharachters).split(new RegExp(this.keyword, 'i')); } splitQuestion(question: string){ const cleanedKeyword = this.keyword.replace(/([^a-z0-9]+)/gi, ''); - return question.split(new RegExp(cleanedKeyword,'i')); + return question.split(new RegExp(this.keyword,'i')); } ngOnInit(): void { - this.questionWithoutProfanity = this.topicCloudAdminService.filterProfanityWords(this.question, true, false); + if (!this.language) { + return; + } + this.questionWithoutProfanity = this.topicCloudAdminService. + filterProfanityWords(this.question, this.partialWords, this.languageSpecific, this.language); this.partsWithoutProfanity = this.splitQuestion(this.questionWithoutProfanity); this.parts = this.splitQuestion(this.question); this.partsWithoutProfanityShort = this.splitShortQuestion(this.questionWithoutProfanity); diff --git a/src/app/services/util/topic-cloud-admin.service.ts b/src/app/services/util/topic-cloud-admin.service.ts index 0fbd81e1edec709a4d3590aa8bfbe4ba8c4add95..bdb0ff6d0cd7ed0ef4180de60ce9661e4dcbd790 100644 --- a/src/app/services/util/topic-cloud-admin.service.ts +++ b/src/app/services/util/topic-cloud-admin.service.ts @@ -6,7 +6,7 @@ import { spacyLabels } from '../../components/shared/_dialogs/topic-cloud-administration/TopicCloudAdminData'; import { RoomService } from '../http/room.service'; -import { Room } from '../../models/room'; +import { ProfanityFilter, Room } from '../../models/room'; import { TranslateService } from '@ngx-translate/core'; import { NotificationService } from './notification.service'; import { Observable, Subject } from 'rxjs'; @@ -47,7 +47,7 @@ export class TopicCloudAdminService { en: this.getDefaultSpacyTagsEN() }, considerVotes: true, - profanityFilter: true, + profanityFilter: ProfanityFilter.none, blacklistIsActive: true, keywordORfulltext: KeywordOrFulltext.both }; @@ -86,7 +86,7 @@ export class TopicCloudAdminService { if (_adminData.blacklistIsActive) { _adminData.blacklist = list; } - if (_adminData.profanityFilter) { + if (_adminData.profanityFilter !== ProfanityFilter.deactivated) { _adminData.blacklist = _adminData.blacklist.concat(this.getProfanityListFromStorage().concat(this.profanityWords)); } this.adminData.next(_adminData);