# 이슈처리 242
This commit is contained in:
parent
e87b27a4fa
commit
b4eaa336e2
|
@ -34,7 +34,6 @@
|
|||
value=""
|
||||
formControlName="groupName"
|
||||
/>
|
||||
|
||||
<button
|
||||
mat-button
|
||||
matSuffix
|
||||
|
@ -44,10 +43,22 @@
|
|||
>
|
||||
<mat-icon>close</mat-icon>
|
||||
</button>
|
||||
|
||||
<mat-hint align="end"
|
||||
>{{ 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>
|
||||
</form>
|
||||
|
||||
|
|
|
@ -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<any>,
|
||||
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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user