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>
</div>
</div>
<form *ngIf="formGroup" (ngSubmit)="formSubmit()">
<form *ngIf="formGroup">
<mat-card class="pt-3 pb-3">
<mat-card-content>
<div class="row">
@ -331,7 +331,7 @@
</div>
<div class="col"></div>
<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}}
</button>
</div>

View File

@ -238,7 +238,8 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
formSubmit(): void {
this.formService.removeAllBackEndErrors(this.formGroup);
this.formService.touchAllFormFields(this.formGroup);
if (!this.isFormValid()) {
if (!this.isFormValid() || !this.hasDescriptionTemplates()) {
this.checkValidity();
return;
}
@ -485,7 +486,7 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
checkValidity() {
this.formService.touchAllFormFields(this.formGroup);
if (!this.isFormValid()) { return false; }
// if (!this.isFormValid()) { return false; }
let errorMessages = [];
if (!this.hasTitle()) {
errorMessages.push("Title should be set.");
@ -493,6 +494,12 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
if (!this.hasDescription()) {
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()) {
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));
}
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 {
const dmpBlueprint: DmpBlueprintPersist = this.formGroup.value;
return dmpBlueprint.definition.sections.some(section => section.hasTemplates == true);
@ -537,7 +554,7 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
}
finalize() {
if (this.checkValidity()) {
if (this.checkValidity() || !this.hasDescriptionTemplates()) {
this.formGroup.get('status').setValue(DmpBlueprintStatus.Finalized);
if(this.isNewVersion) this.isNewVersion = false;
this.formSubmit();