# 이슈처리 230
This commit is contained in:
parent
fc837fe441
commit
08f03b7043
|
@ -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) {
|
||||
|
|
|
@ -26,6 +26,19 @@
|
|||
formControlName="groupName"
|
||||
/>
|
||||
<mat-hint align="end">{{ input.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>
|
||||
</mat-card-content>
|
||||
|
|
|
@ -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<any>,
|
||||
public dialogRef: MatDialogRef<EditGroupDialogData, EditGroupDialogResult>,
|
||||
@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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user