From b68070aa01c16d7cce0ff583e60d0888c2d79f20 Mon Sep 17 00:00:00 2001 From: Aldo Mihasi Date: Thu, 21 Sep 2023 09:35:04 +0300 Subject: [PATCH] [wip] add control for the min/max multiplicity of a description template used in a section of a dmp --- .../dataset-editor.component.html | 2 +- .../dataset-editor.component.ts | 42 +++++++++++++++++++ .../dataset-wizard.component.ts | 2 +- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-editor/dataset-editor.component.html b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-editor/dataset-editor.component.html index cb8dab53d..4ffb357d5 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-editor/dataset-editor.component.html +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-editor/dataset-editor.component.html @@ -63,7 +63,7 @@
- + {{profile.label}} diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-editor/dataset-editor.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-editor/dataset-editor.component.ts index 341cb9a9e..361c850fb 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-editor/dataset-editor.component.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-editor/dataset-editor.component.ts @@ -7,6 +7,10 @@ import { GuidedTour, Orientation } from '@app/library/guided-tour/guided-tour.co import { TranslateService } from '@ngx-translate/core'; import { DatasetProfileModel } from '@app/core/model/dataset/dataset-profile'; import { takeUntil } from 'rxjs/operators'; +import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service'; +import { DatasetWizardEditorModel } from '../dataset-wizard-editor.model'; +import { MatDialog } from '@angular/material/dialog'; +import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component'; @Component({ selector: 'app-dataset-editor-component', @@ -25,6 +29,8 @@ export class DatasetEditorComponent extends BaseComponent { constructor( private router: Router, + private dmpProfileService: DmpProfileService, + private dialog: MatDialog, private guidedTourService: GuidedTourService, private language: TranslateService ) { super(); } @@ -44,6 +50,42 @@ export class DatasetEditorComponent extends BaseComponent { ] }; + checkMinMax(event, profile: DatasetProfileModel) { + const dmpSectionIndex = this.formGroup.get('dmpSectionIndex').value; + const blueprintId = this.formGroup.get('dmp').value.profile.id; + this.dmpProfileService.getSingleBlueprint(blueprintId) + .pipe(takeUntil(this._destroyed)) + .subscribe(result => { + const section = result.definition.sections[dmpSectionIndex]; + if(section.hasTemplates){ + const foundTemplate = section.descriptionTemplates.find(template => template.descriptionTemplateId === profile.id); + if (foundTemplate !== undefined) { + let count = 0; + if(this.formGroup.get('dmp').value.datasets != null){ + for(let dataset of this.formGroup.get('dmp').value.datasets){ + if(dataset.dmpSectionIndex === dmpSectionIndex && dataset.profile.id === foundTemplate.descriptionTemplateId){ + count++; + } + } + if(count === foundTemplate.maxMultiplicity){ + event.stopPropagation(); + this.dialog.open(ConfirmationDialogComponent, { + data:{ + message: 'MAX DATASETS USING TEMPLATE', + confirmButton: 'RETURN', + cancelButton: 'CANCEL' + }, + maxWidth:'30em' + }) + .afterClosed() + .subscribe(confirm=>{}) + } + } + } + } + }); + } + getDmpText(): string { return this.language.instant('DMP-LISTING.TEXT-INFO') + '\n\n' + this.language.instant('DMP-LISTING.TEXT-INFO-QUESTION') + ' ' + diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts index 496754b05..3180ce14b 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts @@ -268,7 +268,7 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme }); } else if (this.dmpId != null) { this.isNew = true; - this.dmpService.getSingleNoDatasets(this.dmpId).pipe(map(data => data as DmpModel)) + this.dmpService.getSingle(this.dmpId).pipe(map(data => data as DmpModel)) .pipe(takeUntil(this._destroyed)) .subscribe(data => { this.datasetWizardModel = new DatasetWizardEditorModel();