disable add description in dmp editor when description templates is not selected

This commit is contained in:
amentis 2024-05-15 12:55:47 +03:00
parent 91bef6f7f0
commit e5abbe9aae
2 changed files with 19 additions and 6 deletions

View File

@ -104,8 +104,14 @@
</ol>
<ul *ngIf="item.id && section.hasTemplates && canEditSection(section.id) && !formGroup.disabled" class="add-description-option">
<li>
<a class="add-description-action" [ngClass]="{'drag-handle-disabled': !canAddDescription(section)}" [routerLink]="canAddDescription(section) ? ['/descriptions/edit/' + item.id + '/' + section.id] : null">
<mat-icon [matTooltipDisabled]="canAddDescription(section)" [matTooltip]="'DMP-EDITOR.DESCRIPTION-TEMPLATES-MAX-MULTIPLICITY' | translate">add</mat-icon>{{'DMP-EDITOR.ACTIONS.ADD-DESCRIPTION-IN-SECTION' | translate}}
<a class="add-description-action" [ngClass]="{'drag-handle-disabled': !hasDescriptionTemplates(section) || !hasValidMultiplicity(section)}" [routerLink]="hasDescriptionTemplates(section) && hasValidMultiplicity(section) ? ['/descriptions/edit/' + item.id + '/' + section.id] : null">
<ng-container *ngIf="!hasDescriptionTemplates(section)" >
<mat-icon [matTooltipDisabled]="hasDescriptionTemplates(section)" [matTooltip]="'DMP-EDITOR.DESCRIPTION-TEMPLATES.EMPTY' | translate">add</mat-icon>{{'DMP-EDITOR.ACTIONS.ADD-DESCRIPTION-IN-SECTION' | translate}}
</ng-container>
<ng-container *ngIf="hasDescriptionTemplates(section)">
<mat-icon [matTooltipDisabled]="hasValidMultiplicity(section)" [matTooltip]="'DMP-EDITOR.DESCRIPTION-TEMPLATES.MAX-MULTIPLICITY' | translate">add</mat-icon>{{'DMP-EDITOR.ACTIONS.ADD-DESCRIPTION-IN-SECTION' | translate}}
</ng-container>
</a>
</li>
</ul>

View File

@ -298,9 +298,11 @@ export class DmpEditorComponent extends BaseEditor<DmpEditorModel, Dmp> implemen
//Transform descriptionTemplates
formData.descriptionTemplates = [];
for (const sectionId in (this.formGroup.get('descriptionTemplates') as UntypedFormGroup).controls) {
formData.descriptionTemplates.push(
...(this.formGroup.get('descriptionTemplates').get(sectionId).value as Guid[]).map(x => { return { sectionId: Guid.parse(sectionId), descriptionTemplateGroupId: x } })
);
if (this.formGroup.get('descriptionTemplates').get(sectionId).value != undefined){
formData.descriptionTemplates.push(
...(this.formGroup.get('descriptionTemplates').get(sectionId).value as Guid[]).map(x => { return { sectionId: Guid.parse(sectionId), descriptionTemplateGroupId: x } })
);
}
}
this.dmpService.persist(formData)
@ -572,7 +574,12 @@ export class DmpEditorComponent extends BaseEditor<DmpEditorModel, Dmp> implemen
});
}
canAddDescription(section: DmpBlueprintDefinitionSection): boolean {
hasDescriptionTemplates(section: DmpBlueprintDefinitionSection): boolean {
if (this.item.dmpDescriptionTemplates?.filter(x => x.sectionId == section.id).length > 0) return true;
return false;
}
hasValidMultiplicity(section: DmpBlueprintDefinitionSection): boolean {
if (section.hasTemplates) {
if (section.descriptionTemplates?.length > 0) {
const descriptions = this.descriptionsInSection(section.id)