diff --git a/dmp-frontend/src/app/core/model/dmp/dmp.ts b/dmp-frontend/src/app/core/model/dmp/dmp.ts index 2115c7111..a186597c1 100644 --- a/dmp-frontend/src/app/core/model/dmp/dmp.ts +++ b/dmp-frontend/src/app/core/model/dmp/dmp.ts @@ -16,7 +16,7 @@ export interface DmpModel { id: string; label: string; groupId: String; - profile: String; + profile: DmpProfile; version: number; status: DmpStatus; lockable: boolean; @@ -38,3 +38,9 @@ export interface DmpModel { extraProperties: Map; language: String; } + + +export interface DmpProfile { + id: string; + label: string; +} \ No newline at end of file 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 4ffb357d5..c56c214e4 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,8 +63,10 @@
- - {{profile.label}} + +
+ {{profile.label}} +
{{formGroup.get('profile').getError('backendError').message}} 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 361c850fb..cae0ebdfd 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 @@ -1,4 +1,4 @@ -import { Component, Input, Output, EventEmitter } from '@angular/core'; +import { Component, Input } from '@angular/core'; import { FormGroup } from '@angular/forms'; import { Router } from '@angular/router'; import { BaseComponent } from '@common/base/base.component'; @@ -8,9 +8,8 @@ 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'; +import { PopupNotificationDialogComponent } from '@app/library/notification/popup/popup-notification.component'; @Component({ selector: 'app-dataset-editor-component', @@ -51,6 +50,7 @@ export class DatasetEditorComponent extends BaseComponent { }; checkMinMax(event, profile: DatasetProfileModel) { + event.stopPropagation(); const dmpSectionIndex = this.formGroup.get('dmpSectionIndex').value; const blueprintId = this.formGroup.get('dmp').value.profile.id; this.dmpProfileService.getSingleBlueprint(blueprintId) @@ -68,20 +68,24 @@ export class DatasetEditorComponent extends BaseComponent { } } 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=>{}) + this.dialog.open(PopupNotificationDialogComponent, { + data: { + title: 'Max datasets using this template.', + message: 'Select another profile.' + }, maxWidth: '30em' + }); + } + else{ + this.formGroup.get('profile').setValue(profile); } } } + else { + this.formGroup.get('profile').setValue(profile); + } + } + else { + this.formGroup.get('profile').setValue(profile); } }); } 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 3180ce14b..d82a349c3 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 @@ -289,6 +289,7 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme restoreFocus: false, data: { availableProfiles: this.availableDescriptionTemplates, + datasetFormGroup: this.formGroup }, panelClass: 'custom-modalbox' }); diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/prefill-dataset/prefill-dataset.component.html b/dmp-frontend/src/app/ui/dataset/dataset-wizard/prefill-dataset/prefill-dataset.component.html index 6f3e88887..b6d159d7b 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/prefill-dataset/prefill-dataset.component.html +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/prefill-dataset/prefill-dataset.component.html @@ -27,7 +27,9 @@ - {{profile.label}} +
+ {{profile.label}} +
{{prefillForm.get('profile').getError('backendError').message}} diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/prefill-dataset/prefill-dataset.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/prefill-dataset/prefill-dataset.component.ts index 999f51668..bfd5ec16e 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/prefill-dataset/prefill-dataset.component.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/prefill-dataset/prefill-dataset.component.ts @@ -1,5 +1,5 @@ import {Component, Inject, OnInit} from "@angular/core"; -import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; +import {MAT_DIALOG_DATA, MatDialog, MatDialogRef} from "@angular/material/dialog"; import {map, takeUntil} from "rxjs/operators"; import {ProgressIndicationService} from "@app/core/services/progress-indication/progress-indication-service"; import {BaseComponent} from "@common/base/base.component"; @@ -8,6 +8,9 @@ import {Observable, of} from "rxjs"; import {Prefilling} from "@app/core/model/dataset/prefilling"; import {PrefillingService} from "@app/core/services/prefilling.service"; import {FormBuilder, FormGroup, Validators} from "@angular/forms"; +import { DatasetProfileModel } from "@app/core/model/dataset/dataset-profile"; +import { DmpProfileService } from "@app/core/services/dmp/dmp-profile.service"; +import { PopupNotificationDialogComponent } from "@app/library/notification/popup/popup-notification.component"; @Component({ selector: 'prefill-dataset-component', @@ -23,6 +26,8 @@ export class PrefillDatasetComponent extends BaseComponent implements OnInit { constructor(public dialogRef: MatDialogRef, private prefillingService: PrefillingService, + private dmpProfileService: DmpProfileService, + private dialog: MatDialog, private progressIndicationService: ProgressIndicationService, private fb: FormBuilder, @Inject(MAT_DIALOG_DATA) public data: any) { @@ -39,7 +44,7 @@ export class PrefillDatasetComponent extends BaseComponent implements OnInit { prefill: this.fb.control(null, Validators.required) }) if(this.data.availableProfiles && this.data.availableProfiles.length === 1) { - this.prefillForm.get('profile').patchValue(this.data.availableProfiles[0]); + this.addProfileIfUsedLessThanMax(this.data.availableProfiles[0]); } this.prefillAutoCompleteConfiguration = { filterFn: this.searchDatasets.bind(this), @@ -50,6 +55,79 @@ export class PrefillDatasetComponent extends BaseComponent implements OnInit { }; } + addProfileIfUsedLessThanMax(profile: DatasetProfileModel) { + const dmpSectionIndex = this.data.datasetFormGroup.get('dmpSectionIndex').value; + const blueprintId = this.data.datasetFormGroup.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.data.datasetFormGroup.get('dmp').value.datasets != null){ + for(let dataset of this.data.datasetFormGroup.get('dmp').value.datasets){ + if(dataset.dmpSectionIndex === dmpSectionIndex && dataset.profile.id === foundTemplate.descriptionTemplateId){ + count++; + } + } + if(count < foundTemplate.maxMultiplicity){ + this.prefillForm.get('profile').patchValue(profile); + } + } + } + else{ + this.prefillForm.get('profile').patchValue(profile); + } + } + else{ + this.prefillForm.get('profile').patchValue(profile); + } + }); + } + + checkMinMax(event, profile: DatasetProfileModel) { + event.stopPropagation(); + const dmpSectionIndex = this.data.datasetFormGroup.get('dmpSectionIndex').value; + const blueprintId = this.data.datasetFormGroup.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.data.datasetFormGroup.get('dmp').value.datasets != null){ + for(let dataset of this.data.datasetFormGroup.get('dmp').value.datasets){ + if(dataset.dmpSectionIndex === dmpSectionIndex && dataset.profile.id === foundTemplate.descriptionTemplateId){ + count++; + } + } + if(count === foundTemplate.maxMultiplicity){ + this.dialog.open(PopupNotificationDialogComponent, { + data: { + title: 'Max datasets using this template.', + message: 'Select another profile.' + }, maxWidth: '30em' + }); + } + else{ + this.prefillForm.get('profile').setValue(profile); + } + } + } + else { + this.prefillForm.get('profile').setValue(profile); + } + } + else { + this.prefillForm.get('profile').setValue(profile); + } + }); + } + public compareWith(object1: any, object2: any) { return object1 && object2 && object1.id === object2.id; } diff --git a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.model.ts b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.model.ts index 42f641fd1..74880b99f 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.model.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.model.ts @@ -53,7 +53,7 @@ export class DmpEditorModel { fromModel(item: DmpModel): DmpEditorModel { this.id = item.id; - this.profile = item.profile; + this.profile = item.profile.id; this.label = item.label; this.groupId = item.groupId; this.version = item.version; diff --git a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts index 9b14376ce..8a56829b3 100644 --- a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts +++ b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts @@ -608,30 +608,33 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { }); dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe((result: DmpFinalizeDialogOutput) => { if (result && !result.cancelled) { - var datasetsToBeFinalized: DatasetsToBeFinalized = { - uuids: result.datasetsToBeFinalized - }; - this.dmpService.finalize(datasetsToBeFinalized, this.dmp.id) - .pipe(takeUntil(this._destroyed)) - .subscribe( - complete => { - if(extraProperties.visible){ - //this.publish(this.dmp.id); - this.dmpService.publish(this.dmp.id) - .pipe(takeUntil(this._destroyed)) - .subscribe(() => { - //this.hasPublishButton = false; + if(!this.checkIfAnyProfileIsUsedLessThanMin(data)) { + + var datasetsToBeFinalized: DatasetsToBeFinalized = { + uuids: result.datasetsToBeFinalized + }; + this.dmpService.finalize(datasetsToBeFinalized, this.dmp.id) + .pipe(takeUntil(this._destroyed)) + .subscribe( + complete => { + if(extraProperties.visible){ + //this.publish(this.dmp.id); + this.dmpService.publish(this.dmp.id) + .pipe(takeUntil(this._destroyed)) + .subscribe(() => { + //this.hasPublishButton = false; + this.dmp.status = DmpStatus.Finalized; + this.onUpdateCallbackSuccess(); + }); + } + else{ this.dmp.status = DmpStatus.Finalized; this.onUpdateCallbackSuccess(); - }); - } - else{ - this.dmp.status = DmpStatus.Finalized; - this.onUpdateCallbackSuccess(); - } - }, - error => this.onUpdateCallbackError(error) - ); + } + }, + error => this.onUpdateCallbackError(error) + ); + } } }); @@ -639,6 +642,37 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { } + private checkIfAnyProfileIsUsedLessThanMin(dmpModel: DmpModel): boolean { + const blueprintId = dmpModel.profile.id; + this.dmpProfileService.getSingleBlueprint(blueprintId) + .pipe(takeUntil(this._destroyed)) + .subscribe(result => { + result.definition.sections.forEach(section => { + if(section.hasTemplates){ + section.descriptionTemplates.forEach(template => { + if(template.minMultiplicity > 0) { + let count = 0; + dmpModel.datasets.filter(dataset => dataset.dmpSectionIndex === (section.ordinal - 1)).forEach(dataset => { + if(dataset.profile.id === template.descriptionTemplateId){ + count++; + } + }) + if(count < template.minMultiplicity){ + this.dialog.open(PopupNotificationDialogComponent, { + data: { + title: 'Min(' + template.minMultiplicity + ') datasets needed using this template.', + message: 'Add dataset.' + }, maxWidth: '30em' + }); + } + } + }) + } + }) + }); + return true; + } + // newVersion(id: String, label: String) { // let url = this.router.createUrlTree(['/plans/new_version/', id, { dmpLabel: label }]) // window.open(url.toString(), '_blank') diff --git a/dmp-frontend/src/app/ui/dmp/wizard/dmp-wizard-editor.model.ts b/dmp-frontend/src/app/ui/dmp/wizard/dmp-wizard-editor.model.ts index f4725cb41..208a8f2e0 100644 --- a/dmp-frontend/src/app/ui/dmp/wizard/dmp-wizard-editor.model.ts +++ b/dmp-frontend/src/app/ui/dmp/wizard/dmp-wizard-editor.model.ts @@ -43,7 +43,7 @@ export class DmpWizardEditorModel { fromModel(item: DmpModel): DmpWizardEditorModel { this.id = item.id; - this.profile = item.profile; + this.profile = item.profile.id; this.label = item.label; this.groupId = item.groupId; this.version = item.version;