diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/FieldPersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/FieldPersist.java index 3c8d19791..6c5f132da 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/FieldPersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/FieldPersist.java @@ -120,7 +120,8 @@ public class FieldPersist { private final ValidatorFactory validatorFactory; private final FieldDataHelperServiceProvider fieldDataHelperServiceProvider; - + private String fieldSetId; + protected FieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory, FieldDataHelperServiceProvider fieldDataHelperServiceProvider) { super(conventionService, errors); this.messageSource = messageSource; @@ -128,6 +129,11 @@ public class FieldPersist { this.fieldDataHelperServiceProvider = fieldDataHelperServiceProvider; } + public FieldPersistValidator withFieldSetId(String fieldSetId) { + this.fieldSetId = fieldSetId; + return this; + } + @Override protected Class modelClass() { return FieldPersist.class; @@ -150,7 +156,7 @@ public class FieldPersist { .iff(() -> !this.isListNullOrEmpty(item.getVisibilityRules())) .on(FieldPersist._visibilityRules) .over(item.getVisibilityRules()) - .using((itm) -> this.validatorFactory.validator(RulePersist.RulePersistValidator.class).withFieldPersist(item)), + .using((itm) -> this.validatorFactory.validator(RulePersist.RulePersistValidator.class).withFieldPersist(item).withFieldSetId(fieldSetId)), this.refSpec() .iff(() -> !this.isNull(item.getDefaultValue())) .on(FieldPersist._defaultValue) diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/FieldSetPersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/FieldSetPersist.java index 7098b7354..b1c01b71f 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/FieldSetPersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/FieldSetPersist.java @@ -176,7 +176,7 @@ public class FieldSetPersist { .iff(() -> !this.isListNullOrEmpty(item.getFields())) .on(FieldSetPersist._fields) .over(item.getFields()) - .using((itm) -> this.validatorFactory.validator(FieldPersist.FieldPersistValidator.class)) + .using((itm) -> this.validatorFactory.validator(FieldPersist.FieldPersistValidator.class).withFieldSetId(item.getId())) ); } } diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/RulePersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/RulePersist.java index 68f301f00..a470f1f7f 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/RulePersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/RulePersist.java @@ -84,6 +84,7 @@ public class RulePersist { private final MessageSource messageSource; private final ValidatorFactory validatorFactory; private org.opencdmp.model.persist.descriptiontemplatedefinition.FieldPersist fieldEntity; + private String fieldSetId; protected RulePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { super(conventionService, errors); @@ -96,6 +97,11 @@ public class RulePersist { return this; } + public RulePersistValidator withFieldSetId(String fieldSetId) { + this.fieldSetId = fieldSetId; + return this; + } + @Override protected Class modelClass() { return RulePersist.class; @@ -108,6 +114,10 @@ public class RulePersist { this.spec() .must(() -> !this.isEmpty(item.getTarget())) .failOn(RulePersist._target).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{RulePersist._target}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isEmpty(item.getTarget())) + .must(() -> !item.getTarget().equals(this.fieldEntity.getId()) && !item.getTarget().equals(this.fieldSetId)) + .failOn(RulePersist._target).failWith(this.messageSource.getMessage("Validation_UnexpectedValue", new Object[]{RulePersist._target}, LocaleContextHolder.getLocale())), this.spec() .iff(() -> this.isNull(fieldType)) .must(() -> !FieldType.TAGS.equals(fieldType) && !FieldType.INTERNAL_ENTRIES_DESCRIPTIONS.equals(fieldType) && !FieldType.INTERNAL_ENTRIES_PLANS.equals(fieldType) && diff --git a/frontend/src/app/ui/admin/description-template/editor/components/field-set/description-template-editor-field-set.component.html b/frontend/src/app/ui/admin/description-template/editor/components/field-set/description-template-editor-field-set.component.html index 0f3c9e850..70028f386 100644 --- a/frontend/src/app/ui/admin/description-template/editor/components/field-set/description-template-editor-field-set.component.html +++ b/frontend/src/app/ui/admin/description-template/editor/components/field-set/description-template-editor-field-set.component.html @@ -84,7 +84,7 @@
- +
  • diff --git a/frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.html b/frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.html index fe5909e3d..4583a70e4 100644 --- a/frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.html +++ b/frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.html @@ -155,7 +155,7 @@

    {{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.FIELDS.RULES-TITLE' | translate}}

    - +
diff --git a/frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.ts b/frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.ts index 3530d7c6a..31d5232fc 100644 --- a/frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.ts +++ b/frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.ts @@ -35,6 +35,7 @@ export class DescriptionTemplateEditorFieldComponent extends BaseComponent imple @Output() delete = new EventEmitter(); @Input() validationErrorModel: ValidationErrorModel; @Input() validationRootPath: string; + @Input() fieldSetId: string; readonly separatorKeysCodes: number[] = [ENTER, COMMA]; diff --git a/frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.html b/frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.html index eaa386fcf..26448a997 100644 --- a/frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.html +++ b/frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.html @@ -18,7 +18,7 @@ - +
@@ -33,7 +33,7 @@ - +
diff --git a/frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts b/frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts index 62370cec1..781618843 100644 --- a/frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts +++ b/frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts @@ -23,6 +23,8 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit { @Input() viewOnly: boolean; @Input() validationErrorModel: ValidationErrorModel; @Input() validationRootPath: string; + @Input() fieldId: string = null; + @Input() fieldSetId: string = null; options: OptionItem[]; @@ -83,6 +85,11 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit { } ngOnInit(): void { + this.form.controls?.forEach( + (control, index) => { + if (control.get('target').value == this.fieldId || control.get('target').value == this.fieldSetId) control.get('target').setValue(null); + } + ); this.rootForm = this.findRootForm(); this._computeOptions(); } diff --git a/frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts b/frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts index a7283456d..519ba968e 100644 --- a/frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts +++ b/frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts @@ -256,6 +256,9 @@ export class VisibilityRulesService { for (let i = 0; i < rulesForParentKey.length; i++) { const ruleForParentKey = rulesForParentKey[i]; + + if (ruleForParentKey.source == ruleForParentKey.target) continue; //Invalid rule where source and target are equal + const field: DescriptionFieldPersist = fieldsMap.get(ruleForParentKey.source); const rulesForGrandParentKey: RuleWithTarget[] = this.getChainParentRules(ruleForParentKey);