Commit d97ebd30 authored by EL HAJJIOUI Nabil's avatar EL HAJJIOUI Nabil Committed by Ro3034
Browse files

[VAS] Bug 9022 Fix rule identifier check design

parent 4e5cfb67
......@@ -8,42 +8,25 @@
<div class="row justify-content-start">
<div class="col-5 form-control">
<vitamui-common-input
class="field-ruleId"
<vitamui-common-editable-input
formControlName="appraisalRuleIdentifier"
minlength="2"
maxlength="100"
required
placeholder="{{ 'ARCHIVE_SEARCH.SEARCH_CRITERIA_FILTER.FIELDS.ID_DUA' | translate }}"
[validator]="appraisalRuleCriteriaForm?.get('appraisalRuleIdentifier')?.validator"
[asyncValidator]="appraisalRuleCriteriaForm?.get('appraisalRuleIdentifier')?.asyncValidator"
label="{{ 'ARCHIVE_SEARCH.SEARCH_CRITERIA_FILTER.FIELDS.ID_DUA' | translate }}"
minlength="1"
>
<ng-container *ngIf="appraisalRuleCriteriaForm.get('appraisalRuleIdentifier')?.touched">
<vitamui-common-input-error *ngIf="!!appraisalRuleCriteriaForm?.get('appraisalRuleIdentifier')?.errors?.ruleIdExists"
>{{ 'ARCHIVE_SEARCH.RULE.CODE_NOT_EXIST' | translate }}
</vitamui-common-input-error>
<vitamui-common-input-error *ngIf="!!appraisalRuleCriteriaForm?.get('appraisalRuleIdentifier')?.errors?.ruleIdPattern"
>{{ 'ARCHIVE_SEARCH.RULE.WRONG_FORMAT' | translate }}
</vitamui-common-input-error>
</ng-container>
</vitamui-common-input>
</div>
<vitamui-common-field-error errorKey="required">{{ 'COMMON.REQUIRED' | translate }}</vitamui-common-field-error>
<vitamui-common-field-error errorKey="ruleIdPattern"
>{{ 'ARCHIVE_SEARCH.RULE.WRONG_FORMAT' | translate }}
</vitamui-common-field-error>
<div class="check-rule">
<button
[ngStyle]="{ 'background-color': 'green', width: '30', height: '30' }"
*ngIf="appraisalRuleCriteriaForm.get('appraisalRuleIdentifier').value"
type="button"
mat-mini-fab
[disabled]="
appraisalRuleCriteriaForm.get('appraisalRuleIdentifier')?.touched &&
!!appraisalRuleCriteriaForm?.get('appraisalRuleIdentifier')?.errors?.ruleIdExists
"
(click)="addCriteriaRulePostCheck()"
>
<i class="material-icons">check</i>
</button>
<vitamui-common-field-error errorKey="ruleIdExists"
>{{ 'ARCHIVE_SEARCH.RULE.CODE_NOT_EXIST' | translate }}
</vitamui-common-field-error>
</vitamui-common-editable-input>
</div>
<div class="col-4 form-control">
<div class="col-1 form-control"></div>
<div class="col-5 form-control">
<vitamui-common-editable-input
formControlName="appraisalRuleTitle"
[validator]="appraisalRuleCriteriaForm?.get('appraisalRuleTitle')?.validator"
......
......@@ -97,7 +97,7 @@ export class AppraisalRuleSearchComponent implements OnInit, OnDestroy {
merge(this.appraisalRuleCriteriaForm.statusChanges, this.appraisalRuleCriteriaForm.valueChanges)
.pipe(
debounceTime(UPDATE_DEBOUNCE_TIME),
filter(() => this.appraisalRuleCriteriaForm.valid),
//filter(() => this.appraisalRuleCriteriaForm.valid),
map(() => this.appraisalRuleCriteriaForm.value),
map(() => diff(this.appraisalRuleCriteriaForm.value, this.previousAppraisalCriteriaValue)),
filter((formData) => this.isEmpty(formData))
......@@ -106,6 +106,25 @@ export class AppraisalRuleSearchComponent implements OnInit, OnDestroy {
this.resetAppraisalRuleCriteriaForm();
});
this.appraisalRuleCriteriaForm.get('appraisalRuleTitle').valueChanges.subscribe((value) => {
if (
this.appraisalRuleCriteriaForm.get('appraisalRuleTitle').value != null &&
this.appraisalRuleCriteriaForm.get('appraisalRuleTitle').value != ''
) {
this.addCriteria(
APPRAISAL_RULE_TITLE,
{ id: value, value: value },
value,
true,
'EQ',
false,
'STRING',
SearchCriteriaTypeEnum.APPRAISAL_RULE
);
this.resetAppraisalRuleCriteriaForm();
}
});
this.subscriptionAppraisalFromMainSearchCriteria = this.archiveExchangeDataService.appraisalFromMainSearchCriteriaObservable.subscribe(
(criteria) => {
if (criteria) {
......@@ -374,7 +393,21 @@ export class AppraisalRuleSearchComponent implements OnInit, OnDestroy {
isEmpty(formData: any): boolean {
if (formData) {
if (formData.appraisalRuleTitle) {
if (formData.appraisalRuleIdentifier) {
this.addCriteria(
APPRAISAL_RULE_IDENTIFIER,
{ id: formData.appraisalRuleIdentifier.trim(), value: formData.appraisalRuleIdentifier.trim() },
formData.appraisalRuleIdentifier.trim(),
true,
'EQ',
false,
'STRING',
SearchCriteriaTypeEnum.APPRAISAL_RULE
);
this.resetAppraisalRuleCriteriaForm();
return true;
} else if (formData.appraisalRuleTitle) {
this.addCriteria(
APPRAISAL_RULE_TITLE,
{ id: formData.appraisalRuleTitle.trim(), value: formData.appraisalRuleTitle.trim() },
......
......@@ -60,15 +60,19 @@ export class RuleValidator {
private uniqueFields(field: string, existTag: string, valueToIgnore?: string) {
return (control: AbstractControl) => {
const properties: any = {};
properties[field] = control.value;
const existField: any = {};
existField[existTag] = true;
if (control.value) {
properties[field] = control.value;
const existField: any = {};
existField[existTag] = true;
return timer(this.debounceTime).pipe(
switchMap(() => (control.value !== valueToIgnore ? this.ruleService.existsProperties(properties) : of(false))),
take(1),
map((exists: boolean) => (exists ? null : existField))
);
return timer(this.debounceTime).pipe(
switchMap(() => (control.value !== valueToIgnore ? this.ruleService.existsProperties(properties) : of(false))),
take(1),
map((exists: boolean) => (exists ? null : existField))
);
} else {
return of(false);
}
};
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment