disable dmp blueprint form after finalized new version

This commit is contained in:
Sofia Papacharalampous 2024-04-30 17:22:49 +03:00
parent 115892875e
commit 49d8df1894
4 changed files with 15 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import { BaseEntity, BaseEntityPersist } from "@common/base/base-entity.model";
import { Guid } from "@common/types/guid";
import { ReferenceType } from "../reference-type/reference-type";
import { PrefillingSource } from "../prefilling-source/prefilling-source";
import { DmpBlueprintVersionStatus } from "@app/core/common/enum/dmp-blueprint-version-status";
export interface DmpBlueprint extends BaseEntity {
@ -13,6 +14,7 @@ export interface DmpBlueprint extends BaseEntity {
definition: DmpBlueprintDefinition;
status: DmpBlueprintStatus;
version: number;
versionStatus: DmpBlueprintVersionStatus;
groupId: Guid;
}

View File

@ -45,6 +45,7 @@ import { DescriptionTemplatePreviewDialogComponent } from '../../description-tem
import { DmpBlueprintEditorModel, FieldInSectionEditorModel } from './dmp-blueprint-editor.model';
import { DmpBlueprintEditorResolver } from './dmp-blueprint-editor.resolver';
import { DmpBlueprintEditorService } from './dmp-blueprint-editor.service';
import { DmpBlueprintVersionStatus } from '@app/core/common/enum/dmp-blueprint-version-status';
@Component({
@ -61,6 +62,7 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
isDeleted = false;
formGroup: UntypedFormGroup = null;
showInactiveDetails = false;
finalized: boolean = false;
hoveredSectionIndex:number = -1;
hoveredDescriptionTemplateIndex:number = -1;
@ -103,6 +105,10 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
protected get isFinalized(): boolean {
return this.editorModel.status == DmpBlueprintStatus.Finalized;
}
protected get isObsoleteVersion(): boolean {
return this.editorModel.versionStatus == DmpBlueprintVersionStatus.Previous;
}
private hasPermission(permission: AppPermission): boolean {
return this.authService.hasPermission(permission) || this.editorModel?.permissions?.includes(permission);
@ -191,11 +197,11 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
buildForm() {
this.formGroup = this.editorModel.buildForm(null, this.isDeleted || !this.authService.hasPermission(AppPermission.EditDmpBlueprint));
this.dmpBlueprintEditorService.setValidationErrorModel(this.editorModel.validationErrorModel);
if (this.isFinalized || this.isDeleted) {
if (this.isFinalized || this.isDeleted || this.isObsoleteVersion || this.finalized) {
this.formGroup.disable();
}
const action = this.route.snapshot.data['action'];
if (action && action == 'new-version') {
if (action && action == 'new-version' && !(this.isObsoleteVersion || this.finalized)) {
this.formGroup.enable();
}
}
@ -557,6 +563,7 @@ export class DmpBlueprintEditorComponent extends BaseEditor<DmpBlueprintEditorMo
if (this.checkValidity() || !this.hasDescriptionTemplates()) {
this.formGroup.get('status').setValue(DmpBlueprintStatus.Finalized);
if(this.isNewVersion) this.isNewVersion = false;
this.finalized = true;
this.formSubmit();
}
}

View File

@ -3,6 +3,7 @@ import { DmpBlueprintFieldCategory } from "@app/core/common/enum/dmp-blueprint-f
import { DmpBlueprintExtraFieldDataType } from "@app/core/common/enum/dmp-blueprint-field-type";
import { DmpBlueprintStatus } from "@app/core/common/enum/dmp-blueprint-status";
import { DmpBlueprintSystemFieldType } from "@app/core/common/enum/dmp-blueprint-system-field-type";
import { DmpBlueprintVersionStatus } from "@app/core/common/enum/dmp-blueprint-version-status";
import { DescriptionTemplatesInSection, DescriptionTemplatesInSectionPersist, DmpBlueprint, DmpBlueprintDefinition, DmpBlueprintDefinitionPersist, DmpBlueprintDefinitionSection, DmpBlueprintDefinitionSectionPersist, DmpBlueprintPersist, ExtraFieldInSection, FieldInSection, FieldInSectionPersist, ReferenceTypeFieldInSection, SystemFieldInSection } from "@app/core/model/dmp-blueprint/dmp-blueprint";
import { BaseEditorModel } from "@common/base/base-form-editor-model";
import { BackendErrorValidator, DmpBlueprintSystemFieldRequiredValidator } from "@common/forms/validation/custom-validator";
@ -14,6 +15,7 @@ export class DmpBlueprintEditorModel extends BaseEditorModel implements DmpBluep
label: string;
definition: DmpBlueprintDefinitionEditorModel = new DmpBlueprintDefinitionEditorModel();
status: DmpBlueprintStatus = DmpBlueprintStatus.Draft;
versionStatus: DmpBlueprintVersionStatus = DmpBlueprintVersionStatus.Current;
description: string;
permissions: string[];
@ -27,6 +29,7 @@ export class DmpBlueprintEditorModel extends BaseEditorModel implements DmpBluep
super.fromModel(item);
this.label = item.label;
this.status = item.status;
this.versionStatus = item.versionStatus;
this.definition = new DmpBlueprintDefinitionEditorModel(this.validationErrorModel).fromModel(item.definition);
}
return this;

View File

@ -23,6 +23,7 @@ export class DmpBlueprintEditorResolver extends BaseEditorResolver {
nameof<DmpBlueprint>(x => x.id),
nameof<DmpBlueprint>(x => x.label),
nameof<DmpBlueprint>(x => x.status),
nameof<DmpBlueprint>(x => x.versionStatus),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.id)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.label)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.description)].join('.'),