From b4eaa336e2885c11b23c95f590ac268ead11d2ed Mon Sep 17 00:00:00 2001 From: leejinho Date: Wed, 12 Feb 2020 16:54:24 +0900 Subject: [PATCH] =?UTF-8?q?#=20=EC=9D=B4=EC=8A=88=EC=B2=98=EB=A6=AC=20242?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../group/select-group.dialog.component.html | 15 +++- .../group/select-group.dialog.component.ts | 83 +++++++++++++++++-- 2 files changed, 91 insertions(+), 7 deletions(-) diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/group/select-group.dialog.component.html b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/group/select-group.dialog.component.html index 3f05fc2b..52539aec 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/group/select-group.dialog.component.html +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/group/select-group.dialog.component.html @@ -34,7 +34,6 @@ value="" formControlName="groupName" /> - - {{ inputGroupName.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/select-group.dialog.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/group/select-group.dialog.component.ts index e32b0ea7..a19855bc 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/group/select-group.dialog.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/group/select-group.dialog.component.ts @@ -5,7 +5,7 @@ import { MatSelectionList, MatSelectionListChange } from '@angular/material'; -import { Observable, combineLatest } from 'rxjs'; +import { Observable, combineLatest, Subscription } from 'rxjs'; import { Store, select } from '@ngrx/store'; import { map, take } from 'rxjs/operators'; @@ -20,8 +20,14 @@ import { } from '@ucap-webmessenger/ui'; import { GroupDetailData, UserInfo } from '@ucap-webmessenger/protocol-sync'; import { environment } from '../../../../../environments/environment'; -import { TranslateService } from '@ngx-translate/core'; -import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +import { TranslateService, TranslateParser } from '@ngx-translate/core'; +import { + FormGroup, + FormBuilder, + Validators, + ValidatorFn, + AbstractControl +} from '@angular/forms'; import { StringUtil } from '@ucap-webmessenger/core'; export interface SelectGroupDialogData { @@ -43,6 +49,10 @@ export class SelectGroupDialogComponent implements OnInit { groupName: string; inputForm: FormGroup; + bannedWords: string[] = []; + groupListSubscription: Subscription; + groupList: GroupDetailData[]; + constructor( public dialogRef: MatDialogRef< SelectGroupDialogData, @@ -52,8 +62,34 @@ export class SelectGroupDialogComponent implements OnInit { private store: Store, private dialogService: DialogService, 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 => {}, + () => {} + ); + }); + } @ViewChild('groups', { static: true }) groups: MatSelectionList; groupBuddyList$: Observable< @@ -64,7 +100,15 @@ export class SelectGroupDialogComponent implements OnInit { ngOnInit(): void { this.inputForm = this.formBuilder.group({ - groupName: ['', [Validators.required, StringUtil.checkSpecialCharacter()]] + groupName: [ + '', + [ + Validators.required, + StringUtil.checkSpecialCharacter(), + this.checkBanWords(), + this.checkSameName() + ] + ] }); this.groups.selectionChange.subscribe((s: MatSelectionListChange) => { @@ -82,6 +126,8 @@ export class SelectGroupDialogComponent implements OnInit { ) ]).pipe( map(([buddyList, groupList]) => { + this.groupList = groupList; + // sort.. if (!!groupList && groupList.length > 0) { const tempOrderArr: GroupDetailData[] = []; @@ -214,4 +260,31 @@ export class SelectGroupDialogComponent implements OnInit { } return false; } + + 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; + }; + } }