Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Sofia Papacharalampous 2024-06-18 18:02:32 +03:00
commit 1d2858dd42
7 changed files with 23 additions and 15 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

@ -44,7 +44,7 @@
<mat-divider *ngIf="formGroup.get('id').value && (!viewOnly || (!isLocked && !viewOnly) || isLocked || (hasReversableStatus() && !isLocked))" [vertical]="true" class="ml-2 mr-2"></mat-divider>
<div *ngIf="isDirty() && !viewOnly" class="col-auto d-flex align-items-center pr-0">
<div *ngIf="!isPristine() && !viewOnly" class="col-auto d-flex align-items-center pr-0">
<button [disabled]="saving" type="button" mat-raised-button class="description-discard-btn" (click)="discardChanges()">
{{'DESCRIPTION-EDITOR.ACTIONS.DISCARD.DISCARD' | translate}}
</button>

View File

@ -533,6 +533,10 @@ export class DescriptionEditorComponent extends BaseEditor<DescriptionEditorMode
return this.formGroup.dirty; //TODO: check if needed //&& this.hasChanges; // do we need this.formGroup.dirty
}
isPristine() {
return this.formGroup.pristine; //use for discard
}
hasReversableStatus(): boolean {
if (this.item?.dmp) {
return (this.item.dmp.status == DmpStatus.Draft && this.isFinalized);
@ -768,5 +772,6 @@ export class DescriptionEditorComponent extends BaseEditor<DescriptionEditorMode
this.formService.removeAllBackEndErrors(this.formGroup);
this.formService.validateAllFormFields(this.formGroup);
this.descriptionFormService.detectChanges(true);
this.formGroup.markAsPristine();
}
}

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) {