fixed dmp blueprint saving

This commit is contained in:
Sofia Papacharalampous 2024-04-30 15:19:09 +03:00
parent 1a3aa18d35
commit 97449226fe
2 changed files with 22 additions and 5 deletions

View File

@ -27,7 +27,7 @@
<button mat-button class="finalize-btn" (click)="finalize()" [disabled]="!this.isFormValid()" type="button">{{'DMP-BLUEPRINT-EDITOR.ACTIONS.FINALIZE' | translate }}</button> <button mat-button class="finalize-btn" (click)="finalize()" [disabled]="!this.isFormValid()" type="button">{{'DMP-BLUEPRINT-EDITOR.ACTIONS.FINALIZE' | translate }}</button>
</div> </div>
</div> </div>
<form *ngIf="formGroup" (ngSubmit)="formSubmit()"> <form *ngIf="formGroup">
<mat-card class="pt-3 pb-3"> <mat-card class="pt-3 pb-3">
<mat-card-content> <mat-card-content>
<div class="row"> <div class="row">
@ -331,7 +331,7 @@
</div> </div>
<div class="col"></div> <div class="col"></div>
<div class="col-auto"> <div class="col-auto">
<button mat-button class="action-btn" [disabled]="!canSave" type="submit"> <button mat-button class="action-btn" [disabled]="!canSave" type="submit" (click)="save(); formSubmit()">
{{'DMP-BLUEPRINT-EDITOR.ACTIONS.SAVE' | translate}} {{'DMP-BLUEPRINT-EDITOR.ACTIONS.SAVE' | translate}}
</button> </button>
</div> </div>

View File

@ -238,7 +238,8 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
formSubmit(): void { formSubmit(): void {
this.formService.removeAllBackEndErrors(this.formGroup); this.formService.removeAllBackEndErrors(this.formGroup);
this.formService.touchAllFormFields(this.formGroup); this.formService.touchAllFormFields(this.formGroup);
if (!this.isFormValid()) { if (!this.isFormValid() || !this.hasDescriptionTemplates()) {
this.checkValidity();
return; return;
} }
@ -485,7 +486,7 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
checkValidity() { checkValidity() {
this.formService.touchAllFormFields(this.formGroup); this.formService.touchAllFormFields(this.formGroup);
if (!this.isFormValid()) { return false; } // if (!this.isFormValid()) { return false; }
let errorMessages = []; let errorMessages = [];
if (!this.hasTitle()) { if (!this.hasTitle()) {
errorMessages.push("Title should be set."); errorMessages.push("Title should be set.");
@ -493,6 +494,12 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
if (!this.hasDescription()) { if (!this.hasDescription()) {
errorMessages.push("Description should be set."); errorMessages.push("Description should be set.");
} }
if (!this.hasLanguage()) {
errorMessages.push("Language should be set.");
}
if (!this.hasAccess()) {
errorMessages.push("Access should be set.");
}
if (!this.hasDescriptionTemplates()) { if (!this.hasDescriptionTemplates()) {
errorMessages.push("At least one section should have description templates."); errorMessages.push("At least one section should have description templates.");
} }
@ -513,6 +520,16 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
return dmpBlueprint.definition.sections.some(section => section.fields.some(field => (field.category == DmpBlueprintFieldCategory.System) && (field as SystemFieldInSection).systemFieldType === DmpBlueprintSystemFieldType.Description)); return dmpBlueprint.definition.sections.some(section => section.fields.some(field => (field.category == DmpBlueprintFieldCategory.System) && (field as SystemFieldInSection).systemFieldType === DmpBlueprintSystemFieldType.Description));
} }
hasLanguage(): boolean {
const dmpBlueprint: DmpBlueprintPersist = this.formGroup.value;
return dmpBlueprint.definition.sections.some(section => section.fields.some(field => (field.category == DmpBlueprintFieldCategory.System) && (field as SystemFieldInSection).systemFieldType === DmpBlueprintSystemFieldType.Language));
}
hasAccess(): boolean {
const dmpBlueprint: DmpBlueprintPersist = this.formGroup.value;
return dmpBlueprint.definition.sections.some(section => section.fields.some(field => (field.category == DmpBlueprintFieldCategory.System) && (field as SystemFieldInSection).systemFieldType === DmpBlueprintSystemFieldType.AccessRights));
}
hasDescriptionTemplates(): boolean { hasDescriptionTemplates(): boolean {
const dmpBlueprint: DmpBlueprintPersist = this.formGroup.value; const dmpBlueprint: DmpBlueprintPersist = this.formGroup.value;
return dmpBlueprint.definition.sections.some(section => section.hasTemplates == true); return dmpBlueprint.definition.sections.some(section => section.hasTemplates == true);
@ -537,7 +554,7 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
} }
finalize() { finalize() {
if (this.checkValidity()) { if (this.checkValidity() || !this.hasDescriptionTemplates()) {
this.formGroup.get('status').setValue(DmpBlueprintStatus.Finalized); this.formGroup.get('status').setValue(DmpBlueprintStatus.Finalized);
if(this.isNewVersion) this.isNewVersion = false; if(this.isNewVersion) this.isNewVersion = false;
this.formSubmit(); this.formSubmit();