min multiplicity check for descriptions in dmp finalization
This commit is contained in:
parent
0c9601d6f0
commit
56a70636c3
|
@ -608,33 +608,34 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
|
|||
});
|
||||
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe((result: DmpFinalizeDialogOutput) => {
|
||||
if (result && !result.cancelled) {
|
||||
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.checkIfAnyProfileIsUsedLessThanMin(data).subscribe(checked => {
|
||||
if (!checked) {
|
||||
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)
|
||||
);
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -642,35 +643,36 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
|
|||
|
||||
}
|
||||
|
||||
private checkIfAnyProfileIsUsedLessThanMin(dmpModel: DmpModel): boolean {
|
||||
private checkIfAnyProfileIsUsedLessThanMin(dmpModel: DmpModel): Observable<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 this.dmpProfileService.getSingleBlueprint(blueprintId)
|
||||
.pipe(map(result => {
|
||||
return result.definition.sections.some(section => {
|
||||
if(!section.hasTemplates)
|
||||
return false;
|
||||
return section.descriptionTemplates.some(template => {
|
||||
if(!(template.minMultiplicity > 0))
|
||||
return false;
|
||||
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;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
})
|
||||
})
|
||||
});
|
||||
return true;
|
||||
}), takeUntil(this._destroyed));
|
||||
}
|
||||
|
||||
// newVersion(id: String, label: String) {
|
||||
|
|
Loading…
Reference in New Issue