From 08f03b70439c4df9ef67accdc4529586401e5e91 Mon Sep 17 00:00:00 2001 From: leejinho Date: Wed, 12 Feb 2020 08:40:49 +0900 Subject: [PATCH] =?UTF-8?q?#=20=EC=9D=B4=EC=8A=88=EC=B2=98=EB=A6=AC=20230?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/create-chat.dialog.component.ts | 12 +-- .../group/edit-group.dialog.component.html | 13 +++ .../group/edit-group.dialog.component.ts | 92 ++++++++++++++++++- 3 files changed, 103 insertions(+), 14 deletions(-) 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 1c74473f..989245ec 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 @@ -71,6 +71,7 @@ import { } from '@ucap-webmessenger/ui'; import { TranslateService, TranslateParser } from '@ngx-translate/core'; import { environment } from '../../../../../environments/environment'; +import { StringUtil } from '@ucap-webmessenger/core'; export interface CreateChatDialogData { type?: string; @@ -328,7 +329,7 @@ export class CreateChatDialogComponent implements OnInit, OnDestroy { '', [ Validators.required, - this.checkSpecialCharacter(), + StringUtil.checkSpecialCharacter(), this.checkBanWords(), this.checkSameName() ] @@ -342,15 +343,6 @@ export class CreateChatDialogComponent implements OnInit, OnDestroy { this.currentTabIndex = 0; } - checkSpecialCharacter(): ValidatorFn { - return (control: AbstractControl): { [key: string]: any } | null => { - const forbidden = /[\{\}\[\]\/?.;:|\)*~`!^+<>@\#$%&\\\=\(\'\"]/g.test( - control.value - ); - return forbidden ? { groupName: { value: control.value } } : null; - }; - } - checkBanWords(): ValidatorFn { return (control: AbstractControl): { [key: string]: any } | null => { if (!control || !control.value) { diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/group/edit-group.dialog.component.html b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/group/edit-group.dialog.component.html index 9f89038e..5aa69bde 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/group/edit-group.dialog.component.html +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/group/edit-group.dialog.component.html @@ -26,6 +26,19 @@ formControlName="groupName" /> {{ input.value?.length || 0 }}/20 + + {{ + 'group.errors.bannedWords' + | translate: { bannedWords: bannedWords.join(',') } + }} + + + {{ 'group.errors.sameNameExist' | translate }} + diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/group/edit-group.dialog.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/group/edit-group.dialog.component.ts index 1aa0ec48..efdc229b 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/group/edit-group.dialog.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/group/edit-group.dialog.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Inject } from '@angular/core'; +import { Component, OnInit, Inject, OnDestroy } from '@angular/core'; import { FormGroup, FormBuilder, @@ -9,6 +9,11 @@ import { import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; import { GroupDetailData } from '@ucap-webmessenger/protocol-sync'; import { StringUtil } from '@ucap-webmessenger/core'; +import { TranslateService, TranslateParser } from '@ngx-translate/core'; +import { take, tap } from 'rxjs/operators'; +import { Store, select } from '@ngrx/store'; +import { Subscription } from 'rxjs'; +import * as AppStore from '@app/store'; export interface EditGroupDialogData { title: string; @@ -26,23 +31,75 @@ export interface EditGroupDialogResult { templateUrl: './edit-group.dialog.component.html', styleUrls: ['./edit-group.dialog.component.scss'] }) -export class EditGroupDialogComponent implements OnInit { +export class EditGroupDialogComponent implements OnInit, OnDestroy { groupName: string; inputForm: FormGroup; + bannedWords: string[] = []; + groupListSubscription: Subscription; + groupList: GroupDetailData[]; + constructor( + private store: Store, public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: EditGroupDialogData, + private translateService: TranslateService, + private translateParser: TranslateParser, private formBuilder: FormBuilder - ) {} + ) { + const banKeys: string[] = [ + 'group.nameFavorite', + 'group.nameMyDept', + 'group.nameDefault' + ]; + + 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 => {}, + () => {} + ); + }); + } ngOnInit(): void { this.inputForm = this.formBuilder.group({ groupName: [ this.data.group.name, - [Validators.required, StringUtil.checkSpecialCharacter()] + [ + Validators.required, + StringUtil.checkSpecialCharacter(), + this.checkBanWords(), + this.checkSameName() + ] ] }); + + this.groupListSubscription = this.store + .pipe( + select(AppStore.MessengerSelector.SyncSelector.selectAllGroup2), + tap(groupList => { + this.groupList = groupList; + }) + ) + .subscribe(); + } + + ngOnDestroy(): void { + if (!!this.groupListSubscription) { + this.groupListSubscription.unsubscribe(); + } } onClickChoice(choice: boolean): void { @@ -52,4 +109,31 @@ export class EditGroupDialogComponent implements OnInit { group: this.data.group }); } + + 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; + }; + } + + checkSameName(): ValidatorFn { + return (control: AbstractControl): { [key: string]: any } | null => { + if ( + !control || + !control.value || + !this.groupList || + 0 === this.groupList.length + ) { + return null; + } + const v = (control.value as string).trim(); + const ban = -1 < this.groupList.findIndex(g => g.name === v); + return ban ? { groupNameSamed: { value: control.value } } : null; + }; + } }