[wip] add control in dataset creation/prefilling dialog for max multiplicity of a description template in a dmp section, add control in dmp finalization for min multiplicity of a description template in a dmp section

This commit is contained in:
Bernaldo Mihasi 2023-09-22 09:34:12 +03:00
parent beac6be706
commit 5f3ab00009
9 changed files with 171 additions and 44 deletions

View File

@ -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<String, any>;
language: String;
}
export interface DmpProfile {
id: string;
label: string;
}

View File

@ -63,8 +63,10 @@
<div class="profile-form">
<mat-form-field>
<mat-select placeholder="{{'DATASET-WIZARD.FIRST-STEP.PROFILE'| translate}}" [required]="true" [compareWith]="compareWith" formControlName="profile">
<mat-option *ngFor="let profile of availableProfiles" [value]="profile" (click)="checkMinMax($event, profile)">
{{profile.label}}
<mat-option *ngFor="let profile of availableProfiles" [value]="profile">
<div (click)="checkMinMax($event, profile)">
{{profile.label}}
</div>
</mat-option>
</mat-select>
<mat-error *ngIf="formGroup.get('profile').hasError('backendError')">{{formGroup.get('profile').getError('backendError').message}}</mat-error>

View File

@ -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);
}
});
}

View File

@ -289,6 +289,7 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme
restoreFocus: false,
data: {
availableProfiles: this.availableDescriptionTemplates,
datasetFormGroup: this.formGroup
},
panelClass: 'custom-modalbox'
});

View File

@ -27,7 +27,9 @@
<mat-form-field class="col-md-12">
<mat-select placeholder="{{'DATASET-CREATE-WIZARD.PREFILL-STEP.PROFILE'| translate}}" [required]="true" [compareWith]="compareWith" formControlName="profile">
<mat-option *ngFor="let profile of data.availableProfiles" [value]="profile">
{{profile.label}}
<div (click)="checkMinMax($event, profile)">
{{profile.label}}
</div>
</mat-option>
</mat-select>
<mat-error *ngIf="prefillForm.get('profile').hasError('backendError')">{{prefillForm.get('profile').getError('backendError').message}}</mat-error>

View File

@ -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<PrefillDatasetComponent>,
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;
}

View File

@ -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;

View File

@ -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')

View File

@ -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;