[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:
parent
beac6be706
commit
5f3ab00009
|
@ -16,7 +16,7 @@ export interface DmpModel {
|
||||||
id: string;
|
id: string;
|
||||||
label: string;
|
label: string;
|
||||||
groupId: String;
|
groupId: String;
|
||||||
profile: String;
|
profile: DmpProfile;
|
||||||
version: number;
|
version: number;
|
||||||
status: DmpStatus;
|
status: DmpStatus;
|
||||||
lockable: boolean;
|
lockable: boolean;
|
||||||
|
@ -38,3 +38,9 @@ export interface DmpModel {
|
||||||
extraProperties: Map<String, any>;
|
extraProperties: Map<String, any>;
|
||||||
language: String;
|
language: String;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface DmpProfile {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
}
|
|
@ -63,8 +63,10 @@
|
||||||
<div class="profile-form">
|
<div class="profile-form">
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-select placeholder="{{'DATASET-WIZARD.FIRST-STEP.PROFILE'| translate}}" [required]="true" [compareWith]="compareWith" formControlName="profile">
|
<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)">
|
<mat-option *ngFor="let profile of availableProfiles" [value]="profile">
|
||||||
|
<div (click)="checkMinMax($event, profile)">
|
||||||
{{profile.label}}
|
{{profile.label}}
|
||||||
|
</div>
|
||||||
</mat-option>
|
</mat-option>
|
||||||
</mat-select>
|
</mat-select>
|
||||||
<mat-error *ngIf="formGroup.get('profile').hasError('backendError')">{{formGroup.get('profile').getError('backendError').message}}</mat-error>
|
<mat-error *ngIf="formGroup.get('profile').hasError('backendError')">{{formGroup.get('profile').getError('backendError').message}}</mat-error>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Component, Input, Output, EventEmitter } from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
import { FormGroup } from '@angular/forms';
|
import { FormGroup } from '@angular/forms';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { BaseComponent } from '@common/base/base.component';
|
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 { DatasetProfileModel } from '@app/core/model/dataset/dataset-profile';
|
||||||
import { takeUntil } from 'rxjs/operators';
|
import { takeUntil } from 'rxjs/operators';
|
||||||
import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service';
|
import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service';
|
||||||
import { DatasetWizardEditorModel } from '../dataset-wizard-editor.model';
|
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
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({
|
@Component({
|
||||||
selector: 'app-dataset-editor-component',
|
selector: 'app-dataset-editor-component',
|
||||||
|
@ -51,6 +50,7 @@ export class DatasetEditorComponent extends BaseComponent {
|
||||||
};
|
};
|
||||||
|
|
||||||
checkMinMax(event, profile: DatasetProfileModel) {
|
checkMinMax(event, profile: DatasetProfileModel) {
|
||||||
|
event.stopPropagation();
|
||||||
const dmpSectionIndex = this.formGroup.get('dmpSectionIndex').value;
|
const dmpSectionIndex = this.formGroup.get('dmpSectionIndex').value;
|
||||||
const blueprintId = this.formGroup.get('dmp').value.profile.id;
|
const blueprintId = this.formGroup.get('dmp').value.profile.id;
|
||||||
this.dmpProfileService.getSingleBlueprint(blueprintId)
|
this.dmpProfileService.getSingleBlueprint(blueprintId)
|
||||||
|
@ -68,20 +68,24 @@ export class DatasetEditorComponent extends BaseComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(count === foundTemplate.maxMultiplicity){
|
if(count === foundTemplate.maxMultiplicity){
|
||||||
event.stopPropagation();
|
this.dialog.open(PopupNotificationDialogComponent, {
|
||||||
this.dialog.open(ConfirmationDialogComponent, {
|
|
||||||
data: {
|
data: {
|
||||||
message: 'MAX DATASETS USING TEMPLATE',
|
title: 'Max datasets using this template.',
|
||||||
confirmButton: 'RETURN',
|
message: 'Select another profile.'
|
||||||
cancelButton: 'CANCEL'
|
}, maxWidth: '30em'
|
||||||
},
|
});
|
||||||
maxWidth:'30em'
|
}
|
||||||
})
|
else{
|
||||||
.afterClosed()
|
this.formGroup.get('profile').setValue(profile);
|
||||||
.subscribe(confirm=>{})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
this.formGroup.get('profile').setValue(profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.formGroup.get('profile').setValue(profile);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -289,6 +289,7 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme
|
||||||
restoreFocus: false,
|
restoreFocus: false,
|
||||||
data: {
|
data: {
|
||||||
availableProfiles: this.availableDescriptionTemplates,
|
availableProfiles: this.availableDescriptionTemplates,
|
||||||
|
datasetFormGroup: this.formGroup
|
||||||
},
|
},
|
||||||
panelClass: 'custom-modalbox'
|
panelClass: 'custom-modalbox'
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,7 +27,9 @@
|
||||||
<mat-form-field class="col-md-12">
|
<mat-form-field class="col-md-12">
|
||||||
<mat-select placeholder="{{'DATASET-CREATE-WIZARD.PREFILL-STEP.PROFILE'| translate}}" [required]="true" [compareWith]="compareWith" formControlName="profile">
|
<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">
|
<mat-option *ngFor="let profile of data.availableProfiles" [value]="profile">
|
||||||
|
<div (click)="checkMinMax($event, profile)">
|
||||||
{{profile.label}}
|
{{profile.label}}
|
||||||
|
</div>
|
||||||
</mat-option>
|
</mat-option>
|
||||||
</mat-select>
|
</mat-select>
|
||||||
<mat-error *ngIf="prefillForm.get('profile').hasError('backendError')">{{prefillForm.get('profile').getError('backendError').message}}</mat-error>
|
<mat-error *ngIf="prefillForm.get('profile').hasError('backendError')">{{prefillForm.get('profile').getError('backendError').message}}</mat-error>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {Component, Inject, OnInit} from "@angular/core";
|
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 {map, takeUntil} from "rxjs/operators";
|
||||||
import {ProgressIndicationService} from "@app/core/services/progress-indication/progress-indication-service";
|
import {ProgressIndicationService} from "@app/core/services/progress-indication/progress-indication-service";
|
||||||
import {BaseComponent} from "@common/base/base.component";
|
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 {Prefilling} from "@app/core/model/dataset/prefilling";
|
||||||
import {PrefillingService} from "@app/core/services/prefilling.service";
|
import {PrefillingService} from "@app/core/services/prefilling.service";
|
||||||
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
|
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({
|
@Component({
|
||||||
selector: 'prefill-dataset-component',
|
selector: 'prefill-dataset-component',
|
||||||
|
@ -23,6 +26,8 @@ export class PrefillDatasetComponent extends BaseComponent implements OnInit {
|
||||||
|
|
||||||
constructor(public dialogRef: MatDialogRef<PrefillDatasetComponent>,
|
constructor(public dialogRef: MatDialogRef<PrefillDatasetComponent>,
|
||||||
private prefillingService: PrefillingService,
|
private prefillingService: PrefillingService,
|
||||||
|
private dmpProfileService: DmpProfileService,
|
||||||
|
private dialog: MatDialog,
|
||||||
private progressIndicationService: ProgressIndicationService,
|
private progressIndicationService: ProgressIndicationService,
|
||||||
private fb: FormBuilder,
|
private fb: FormBuilder,
|
||||||
@Inject(MAT_DIALOG_DATA) public data: any) {
|
@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)
|
prefill: this.fb.control(null, Validators.required)
|
||||||
})
|
})
|
||||||
if(this.data.availableProfiles && this.data.availableProfiles.length === 1) {
|
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 = {
|
this.prefillAutoCompleteConfiguration = {
|
||||||
filterFn: this.searchDatasets.bind(this),
|
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) {
|
public compareWith(object1: any, object2: any) {
|
||||||
return object1 && object2 && object1.id === object2.id;
|
return object1 && object2 && object1.id === object2.id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ export class DmpEditorModel {
|
||||||
|
|
||||||
fromModel(item: DmpModel): DmpEditorModel {
|
fromModel(item: DmpModel): DmpEditorModel {
|
||||||
this.id = item.id;
|
this.id = item.id;
|
||||||
this.profile = item.profile;
|
this.profile = item.profile.id;
|
||||||
this.label = item.label;
|
this.label = item.label;
|
||||||
this.groupId = item.groupId;
|
this.groupId = item.groupId;
|
||||||
this.version = item.version;
|
this.version = item.version;
|
||||||
|
|
|
@ -608,6 +608,8 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
|
||||||
});
|
});
|
||||||
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe((result: DmpFinalizeDialogOutput) => {
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe((result: DmpFinalizeDialogOutput) => {
|
||||||
if (result && !result.cancelled) {
|
if (result && !result.cancelled) {
|
||||||
|
if(!this.checkIfAnyProfileIsUsedLessThanMin(data)) {
|
||||||
|
|
||||||
var datasetsToBeFinalized: DatasetsToBeFinalized = {
|
var datasetsToBeFinalized: DatasetsToBeFinalized = {
|
||||||
uuids: result.datasetsToBeFinalized
|
uuids: result.datasetsToBeFinalized
|
||||||
};
|
};
|
||||||
|
@ -633,12 +635,44 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
|
||||||
error => this.onUpdateCallbackError(error)
|
error => this.onUpdateCallbackError(error)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
// newVersion(id: String, label: String) {
|
||||||
// let url = this.router.createUrlTree(['/plans/new_version/', id, { dmpLabel: label }])
|
// let url = this.router.createUrlTree(['/plans/new_version/', id, { dmpLabel: label }])
|
||||||
// window.open(url.toString(), '_blank')
|
// window.open(url.toString(), '_blank')
|
||||||
|
|
|
@ -43,7 +43,7 @@ export class DmpWizardEditorModel {
|
||||||
|
|
||||||
fromModel(item: DmpModel): DmpWizardEditorModel {
|
fromModel(item: DmpModel): DmpWizardEditorModel {
|
||||||
this.id = item.id;
|
this.id = item.id;
|
||||||
this.profile = item.profile;
|
this.profile = item.profile.id;
|
||||||
this.label = item.label;
|
this.label = item.label;
|
||||||
this.groupId = item.groupId;
|
this.groupId = item.groupId;
|
||||||
this.version = item.version;
|
this.version = item.version;
|
||||||
|
|
Loading…
Reference in New Issue