diff --git a/commons/commons-vitam/src/main/java/fr/gouv/vitamui/commons/vitam/api/config/converter/RuleConverter.java b/commons/commons-vitam/src/main/java/fr/gouv/vitamui/commons/vitam/api/config/converter/RuleConverter.java index 81a2c6dacd59f015ae95572a0f80eeb30fed5822..2b097759eeb1a839ec29abad34afc89e381f7bf8 100644 --- a/commons/commons-vitam/src/main/java/fr/gouv/vitamui/commons/vitam/api/config/converter/RuleConverter.java +++ b/commons/commons-vitam/src/main/java/fr/gouv/vitamui/commons/vitam/api/config/converter/RuleConverter.java @@ -37,6 +37,8 @@ package fr.gouv.vitamui.commons.vitam.api.config.converter; import fr.gouv.vitam.common.model.administration.FileRulesModel; +import fr.gouv.vitam.common.model.administration.RuleMeasurementEnum; +import fr.gouv.vitam.common.model.administration.RuleType; import fr.gouv.vitamui.commons.rest.dto.RuleDto; import fr.gouv.vitamui.commons.utils.VitamUIUtils; @@ -47,13 +49,15 @@ public class RuleConverter { public FileRulesModel convertDtoToVitam(final RuleDto dto) { final FileRulesModel rule = VitamUIUtils.copyProperties(dto, new FileRulesModel()); - + rule.setRuleType(RuleType.getEnumFromName(dto.getRuleType())); + rule.setRuleMeasurement(RuleMeasurementEnum.getEnumFromType(dto.getRuleMeasurement())); return rule; } public RuleDto convertVitamToDto(final FileRulesModel rule) { final RuleDto dto = VitamUIUtils.copyProperties(rule, new RuleDto()); - + dto.setRuleMeasurement(rule.getRuleMeasurement().getType()); + dto.setRuleType(rule.getRuleType().name()); return dto; } diff --git a/ui/ui-frontend/projects/archive-search/src/app/archive/management-rules/add-management-rules/add-management-rules.component.ts b/ui/ui-frontend/projects/archive-search/src/app/archive/management-rules/add-management-rules/add-management-rules.component.ts index 7d853fe6ae20895079a0e87dcc2cd75ed4e2adb8..cbe4dd90735ce9a120e3d9dcad4158b966bba0c1 100644 --- a/ui/ui-frontend/projects/archive-search/src/app/archive/management-rules/add-management-rules/add-management-rules.component.ts +++ b/ui/ui-frontend/projects/archive-search/src/app/archive/management-rules/add-management-rules/add-management-rules.component.ts @@ -42,7 +42,6 @@ import { cloneDeep } from 'lodash'; import { merge, Subscription } from 'rxjs'; import { debounceTime, filter, map } from 'rxjs/operators'; import { CriteriaDataType, CriteriaOperator, diff, Rule, RuleService } from 'ui-frontend-common'; -import { isEmpty } from 'underscore'; import { ManagementRulesSharedDataService } from '../../../core/management-rules-shared-data.service'; import { ArchiveService } from '../../archive.service'; import { RuleTypeEnum } from '../../models/rule-type-enum'; @@ -120,7 +119,7 @@ export class AddManagementRulesComponent implements OnInit, OnDestroy { rule: [ null, [Validators.required, this.managementRulesValidatorService.ruleIdPattern()], - [this.managementRulesValidatorService.uniqueRuleId(), , this.managementRulesValidatorService.checkRuleIdExistence()], + [this.managementRulesValidatorService.uniqueRuleId(), this.managementRulesValidatorService.checkRuleIdExistence()], ], name: [{ value: null, disabled: true }, Validators.required], startDate: [null, Validators.required], @@ -131,7 +130,7 @@ export class AddManagementRulesComponent implements OnInit, OnDestroy { .pipe( debounceTime(UPDATE_DEBOUNCE_TIME), map(() => diff(this.ruleDetailsForm.value, this.previousRuleDetails)), - filter((formData) => !isEmpty(formData)), + filter((formData) => this.isEmpty(formData)), filter((formData) => this.patchForm(formData)) ) .subscribe(() => { @@ -145,26 +144,29 @@ export class AddManagementRulesComponent implements OnInit, OnDestroy { this.selectedStartDate = date; }); - this.ruleDetailsForm.get('rule').valueChanges.subscribe((ruleSelected) => { - if (this.ruleDetailsForm.get('rule').value !== this.previousRuleDetails.rule) { - this.getRuleSuscription = this.ruleService.get(ruleSelected).subscribe((ruleResponse) => { + this.ruleDetailsForm.get('rule').valueChanges.subscribe(() => { + this.cancelStep.emit(); + }); + } + + isEmpty(formData: any): boolean { + if (formData) { + if (formData.rule) { + this.getRuleSuscription = this.ruleService.get(formData.rule.trim()).subscribe((ruleResponse) => { this.rule = ruleResponse; + this.ruleDetailsForm.patchValue({ name: ruleResponse.ruleValue }); }); + return true; } - - if (this.rule && this.rule.ruleValue) { - this.ruleDetailsForm.patchValue({ name: this.rule.ruleValue }); - } - - this.cancelStep.emit(); - }); + } + return false; } ngOnDestroy() { this.showConfirmDeleteAddRuleSuscription?.unsubscribe(); this.managementRulesSubscription?.unsubscribe(); this.criteriaSearchDSLQuerySuscription?.unsubscribe(); - this.getRuleSuscription.unsubscribe(); + this.getRuleSuscription?.unsubscribe(); } ngOnInit() {}