fix multiplicity issue

This commit is contained in:
amentis 2024-06-18 17:32:06 +03:00
parent eba6aba19a
commit 3b426db49c
5 changed files with 17 additions and 14 deletions

View File

@ -8,27 +8,27 @@ import jakarta.xml.bind.annotation.XmlAttribute;
public class MultiplicityEntity {
@XmlAttribute(name="min")
private int min;
private Integer min;
@XmlAttribute(name="max")
private int max;
private Integer max;
@XmlAttribute(name="placeholder")
private String placeholder;
@XmlAttribute(name="tableView")
private boolean tableView;
public int getMin() {
public Integer getMin() {
return min;
}
public void setMin(int min) {
public void setMin(Integer min) {
this.min = min;
}
public int getMax() {
public Integer getMax() {
return max;
}
public void setMax(int max) {
public void setMax(Integer max) {
this.max = max;
}

View File

@ -85,7 +85,7 @@ public class MultiplicityPersist {
.failOn(MultiplicityPersist._min).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{MultiplicityPersist._min}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getMax()))
.must(() -> item.getMax() >= 0)
.must(() -> item.getMax() > 0)
.failOn(MultiplicityPersist._max).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{MultiplicityPersist._max}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getMax()))

View File

@ -354,10 +354,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
data.setHasMultiplicity(persist.getHasMultiplicity());
data.setAdditionalInformation(persist.getAdditionalInformation());
data.setExtendedDescription(persist.getExtendedDescription());
if (persist.getMultiplicity() != null && persist.getHasMultiplicity() && (
(persist.getMultiplicity().getMin() != null && persist.getMultiplicity().getMin() != 0)
|| (persist.getMultiplicity().getMax() != null && persist.getMultiplicity().getMax() != 0)
)) {
if (persist.getMultiplicity() != null && persist.getHasMultiplicity()) {
data.setMultiplicity(this.buildMultiplicityEntity(persist.getMultiplicity()));
}
data.setHasCommentField(persist.getHasCommentField());

View File

@ -32,7 +32,7 @@
</button>
</div>
</div>
<div *ngIf="fieldSet.hasMultiplicity && (fieldSet?.multiplicity?.max) > (propertiesFormGroup.get('items').length)" class="col-12 mt-1 ml-0 mr-0 addOneFieldButton">
<div *ngIf="canAddMultiplicityField()" class="col-12 mt-1 ml-0 mr-0 addOneFieldButton">
<mat-error *ngIf="fieldSet.hasMultiplicity && fieldSet?.multiplicity?.min && propertiesFormGroup.get('items').hasError('minlength')">{{'GENERAL.VALIDATION.MULTIPLICITY.MIN' | translate: { min: fieldSet.multiplicity.min} }}</mat-error>
<mat-error *ngIf="fieldSet.hasMultiplicity && fieldSet?.multiplicity?.max && propertiesFormGroup.get('items').hasError('maxlength')">{{'GENERAL.VALIDATION,MULTIPLICITY.MAX' | translate: { max: fieldSet.multiplicity.max} }}</mat-error>
<span class="d-inline-flex align-items-center" [ngClass]="propertiesFormGroup.disabled ? '' : 'pointer'" (click)="addMultiplicityField()">
@ -40,7 +40,7 @@
<mat-icon>add_circle</mat-icon>
</button>
<span class="mt-1" *ngIf="fieldSet?.multiplicity?.placeholder">{{fieldSet.multiplicity.placeholder}}</span>
<span class="mt-1" *ngIf="!fieldSet?.multiplicity?.placeholder">{{('DESCRIPTION-EDITOR.ACTIONS.MULTIPLICITY-ADD-ONE-FIELD' + (fieldSet.multiplicity.tableView?'-TABLEVIEW':'')) | translate}}</span>
<span class="mt-1" *ngIf="!fieldSet?.multiplicity?.placeholder">{{('DESCRIPTION-EDITOR.ACTIONS.MULTIPLICITY-ADD-ONE-FIELD' + (fieldSet.multiplicity?.tableView?'-TABLEVIEW':'')) | translate}}</span>
</span>
</div>
</div>
@ -70,7 +70,7 @@
</tr>
</ng-container>
<tr *ngIf="fieldSet.hasMultiplicity && (fieldSet.multiplicity.max - 1) > propertiesFormGroup?.get('items')?.controls.length">
<tr *ngIf="canAddMultiplicityField()">
<td [colSpan]="fieldSet.fields.length + 1" class="text-center">
<mat-error *ngIf="fieldSet.hasMultiplicity && fieldSet?.multiplicity?.min && propertiesFormGroup.get('items').hasError('minlength')">{{'GENERAL.VALIDATION.MULTIPLICITY.MIN' | translate: { min: fieldSet.multiplicity.min} }}</mat-error>
<mat-error *ngIf="fieldSet.hasMultiplicity && fieldSet?.multiplicity?.max && propertiesFormGroup.get('items').hasError('maxlength')">{{'GENERAL.VALIDATION,MULTIPLICITY.MAX' | translate: { max: fieldSet.multiplicity.max} }}</mat-error>

View File

@ -71,6 +71,12 @@ export class DescriptionFormFieldSetComponent extends BaseComponent {
});
}
canAddMultiplicityField(): boolean{
if (!this.fieldSet.hasMultiplicity) return false;
if (this.fieldSet?.multiplicity?.max) return this.fieldSet.multiplicity.max > (this.propertiesFormGroup.get('items') as UntypedFormArray).length;
return true;
}
addMultiplicityField() {
const formArray = this.propertiesFormGroup?.get('items') as UntypedFormArray;
if (formArray.disabled) {