From 619ebe4e61e6b523cb65a884788b0eb62967525d Mon Sep 17 00:00:00 2001 From: richard-loafle <44828666+richard-loafle@users.noreply.github.com> Date: Thu, 6 Feb 2020 17:49:05 +0900 Subject: [PATCH] validation of group name is modified --- .../chat/create-chat.dialog.component.html | 9 +++ .../chat/create-chat.dialog.component.ts | 57 ++++++++++++++++++- .../src/assets/i18n/en.json | 3 +- .../src/assets/i18n/ko.json | 3 +- 4 files changed, 67 insertions(+), 5 deletions(-) diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/create-chat.dialog.component.html b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/create-chat.dialog.component.html index 0249e670..a48311fc 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/create-chat.dialog.component.html +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/create-chat.dialog.component.html @@ -26,8 +26,17 @@ maxlength="20" placeholder="{{ 'group.name' | translate }}" formControlName="groupName" + (keyup)="onKeyupGroupName()" /> {{ input.value?.length || 0 }}/20 + + {{ + 'group.errors.bannedWords' + | translate: { bannedWords: bannedWords.join(',') } + }} + diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/create-chat.dialog.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/create-chat.dialog.component.ts index 05a3d4c9..49d5e376 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/create-chat.dialog.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/create-chat.dialog.component.ts @@ -20,7 +20,7 @@ import { } from '@angular/material'; import { NGXLogger } from 'ngx-logger'; import { Observable, combineLatest, Subscription, of } from 'rxjs'; -import { map, tap, catchError } from 'rxjs/operators'; +import { map, tap, catchError, take } from 'rxjs/operators'; import { Store, select } from '@ngrx/store'; import * as AppStore from '@app/store'; @@ -62,7 +62,7 @@ import { AlertDialogResult, AlertDialogData } from '@ucap-webmessenger/ui'; -import { TranslateService } from '@ngx-translate/core'; +import { TranslateService, TranslateParser } from '@ngx-translate/core'; import { environment } from '../../../../../environments/environment'; export interface CreateChatDialogData { @@ -115,11 +115,38 @@ export class CreateChatDialogComponent implements OnInit, OnDestroy { private logger: NGXLogger, private dialogService: DialogService, private translateService: TranslateService, + private translateParser: TranslateParser, private changeDetectorRef: ChangeDetectorRef ) { this.sessionVerinfo = this.sessionStorageService.get( KEY_VER_INFO ); + + const banKeys: string[] = [ + 'group.nameFavorite', + 'group.nameMyDept', + 'group.nameDefault' + ]; + + const currentLang = this.translateService.currentLang; + const langs = ['ko', 'en']; + + langs.forEach(lang => { + this.translateService + .getTranslation(lang) + .pipe(take(1)) + .subscribe( + translation => { + banKeys.forEach(banKey => { + this.bannedWords.push( + this.translateParser.getValue(translation, banKey) + ); + }); + }, + error => {}, + () => {} + ); + }); } currentTabIndex: number; @@ -162,6 +189,8 @@ export class CreateChatDialogComponent implements OnInit, OnDestroy { inputForm: FormGroup; + bannedWords: string[] = []; + ngOnInit() { const loginInfo = this.sessionStorageService.get(KEY_LOGIN_INFO); this.companyCode = loginInfo.companyCode; @@ -283,7 +312,14 @@ export class CreateChatDialogComponent implements OnInit, OnDestroy { .subscribe(); this.inputForm = this.formBuilder.group({ - groupName: ['', [Validators.required, this.checkSpecialCharacter()]] + groupName: [ + '', + [ + Validators.required, + this.checkSpecialCharacter(), + this.checkBanWords() + ] + ] }); if (this.data.type === UserSelectDialogType.EditChatMember) { @@ -302,6 +338,17 @@ export class CreateChatDialogComponent implements OnInit, OnDestroy { }; } + checkBanWords(): ValidatorFn { + return (control: AbstractControl): { [key: string]: any } | null => { + if (!control || !control.value) { + return null; + } + const ban = + -1 < this.bannedWords.indexOf((control.value as string).trim()); + return ban ? { groupNameBanned: { value: control.value } } : null; + }; + } + ngOnDestroy(): void { if (!!this.roomSubscription) { this.roomSubscription.unsubscribe(); @@ -754,4 +801,8 @@ export class CreateChatDialogComponent implements OnInit, OnDestroy { : undefined }); } + + onKeyupGroupName() { + this.inputForm.get('groupName').markAsTouched(); + } } diff --git a/projects/ucap-webmessenger-app/src/assets/i18n/en.json b/projects/ucap-webmessenger-app/src/assets/i18n/en.json index fd89a055..183b2763 100644 --- a/projects/ucap-webmessenger-app/src/assets/i18n/en.json +++ b/projects/ucap-webmessenger-app/src/assets/i18n/en.json @@ -177,7 +177,8 @@ "confirmRemoveGroup": "Are you sure you want to delete the group {{nameOfGroup}}?
Group members will only be deleted from that group.", "errors": { "label": "Group errors", - "requireName": "Group name is required." + "requireName": "Group name is required.", + "bannedWords": "Prohibited word. [{{bannedWords}}]" } }, "chat": { diff --git a/projects/ucap-webmessenger-app/src/assets/i18n/ko.json b/projects/ucap-webmessenger-app/src/assets/i18n/ko.json index 7a39ac99..d5f4d8e8 100644 --- a/projects/ucap-webmessenger-app/src/assets/i18n/ko.json +++ b/projects/ucap-webmessenger-app/src/assets/i18n/ko.json @@ -177,7 +177,8 @@ "confirmRemoveGroup": "그룹({{nameOfGroup}})을 삭제하시겠습니까?
그룹 멤버는 해당 그룹에서만 삭제됩니다.", "errors": { "label": "그룹 에러", - "requireName": "그룹명은 필수입력입니다." + "requireName": "그룹명은 필수입력입니다.", + "bannedWords": "금지단어 [{{bannedWords}}]" } }, "chat": {