# 이슈처리 242

This commit is contained in:
leejinho 2020-02-12 16:54:24 +09:00
parent e87b27a4fa
commit b4eaa336e2
2 changed files with 91 additions and 7 deletions

View File

@ -34,7 +34,6 @@
value="" value=""
formControlName="groupName" formControlName="groupName"
/> />
<button <button
mat-button mat-button
matSuffix matSuffix
@ -44,10 +43,22 @@
> >
<mat-icon>close</mat-icon> <mat-icon>close</mat-icon>
</button> </button>
<mat-hint align="end" <mat-hint align="end"
>{{ inputGroupName.value?.length || 0 }}/20</mat-hint >{{ inputGroupName.value?.length || 0 }}/20</mat-hint
> >
<mat-error
*ngIf="inputForm.get('groupName').hasError('groupNameBanned')"
>
{{
'group.errors.bannedWords'
| translate: { bannedWords: bannedWords.join(',') }
}}
</mat-error>
<mat-error
*ngIf="inputForm.get('groupName').hasError('groupNameSamed')"
>
{{ 'group.errors.sameNameExist' | translate }}
</mat-error>
</mat-form-field> </mat-form-field>
</form> </form>

View File

@ -5,7 +5,7 @@ import {
MatSelectionList, MatSelectionList,
MatSelectionListChange MatSelectionListChange
} from '@angular/material'; } from '@angular/material';
import { Observable, combineLatest } from 'rxjs'; import { Observable, combineLatest, Subscription } from 'rxjs';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
import { map, take } from 'rxjs/operators'; import { map, take } from 'rxjs/operators';
@ -20,8 +20,14 @@ import {
} from '@ucap-webmessenger/ui'; } from '@ucap-webmessenger/ui';
import { GroupDetailData, UserInfo } from '@ucap-webmessenger/protocol-sync'; import { GroupDetailData, UserInfo } from '@ucap-webmessenger/protocol-sync';
import { environment } from '../../../../../environments/environment'; import { environment } from '../../../../../environments/environment';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService, TranslateParser } from '@ngx-translate/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms'; import {
FormGroup,
FormBuilder,
Validators,
ValidatorFn,
AbstractControl
} from '@angular/forms';
import { StringUtil } from '@ucap-webmessenger/core'; import { StringUtil } from '@ucap-webmessenger/core';
export interface SelectGroupDialogData { export interface SelectGroupDialogData {
@ -43,6 +49,10 @@ export class SelectGroupDialogComponent implements OnInit {
groupName: string; groupName: string;
inputForm: FormGroup; inputForm: FormGroup;
bannedWords: string[] = [];
groupListSubscription: Subscription;
groupList: GroupDetailData[];
constructor( constructor(
public dialogRef: MatDialogRef< public dialogRef: MatDialogRef<
SelectGroupDialogData, SelectGroupDialogData,
@ -52,8 +62,34 @@ export class SelectGroupDialogComponent implements OnInit {
private store: Store<any>, private store: Store<any>,
private dialogService: DialogService, private dialogService: DialogService,
private translateService: TranslateService, private translateService: TranslateService,
private translateParser: TranslateParser,
private formBuilder: FormBuilder 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; @ViewChild('groups', { static: true }) groups: MatSelectionList;
groupBuddyList$: Observable< groupBuddyList$: Observable<
@ -64,7 +100,15 @@ export class SelectGroupDialogComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.inputForm = this.formBuilder.group({ 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) => { this.groups.selectionChange.subscribe((s: MatSelectionListChange) => {
@ -82,6 +126,8 @@ export class SelectGroupDialogComponent implements OnInit {
) )
]).pipe( ]).pipe(
map(([buddyList, groupList]) => { map(([buddyList, groupList]) => {
this.groupList = groupList;
// sort.. // sort..
if (!!groupList && groupList.length > 0) { if (!!groupList && groupList.length > 0) {
const tempOrderArr: GroupDetailData[] = []; const tempOrderArr: GroupDetailData[] = [];
@ -214,4 +260,31 @@ export class SelectGroupDialogComponent implements OnInit {
} }
return false; 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;
};
}
} }