Fixes "Save and Finalize" on Quick wizard.

This commit is contained in:
Diamantis Tziotzios 2019-03-14 20:00:02 +02:00
parent fb70345d39
commit 460aa7d1e7
7 changed files with 45 additions and 12 deletions

View File

@ -3,6 +3,8 @@ package eu.eudat.controllers;
import eu.eudat.logic.managers.*; import eu.eudat.logic.managers.*;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.quickwizard.DatasetDescriptionQuickWizardModel; import eu.eudat.models.data.quickwizard.DatasetDescriptionQuickWizardModel;
import eu.eudat.models.data.quickwizard.QuickWizardModel; import eu.eudat.models.data.quickwizard.QuickWizardModel;
@ -16,6 +18,7 @@ import eu.eudat.models.data.quickwizard.DatasetCreateWizardModel;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.UUID;
@RestController @RestController
@CrossOrigin @CrossOrigin
@ -58,14 +61,12 @@ public class QuickWizardController extends BaseController {
//Create Datasets //Create Datasets
quickWizard.getDmp().setId(dmpEntity.getId()); quickWizard.getDmp().setId(dmpEntity.getId());
for (DatasetDescriptionQuickWizardModel dataset : quickWizard.getDatasets().getDatasetsList()) { for (DatasetDescriptionQuickWizardModel dataset : quickWizard.getDatasets().getDatasetsList()) {
this.datasetManager.createOrUpdate(dataset.toDataModel(quickWizard.getDmp().toDataDmp( DataManagementPlan dmp = quickWizard.getDmp().toDataDmp( projectEntity, principal);
projectEntity, UUID uuid = quickWizard.getDmp().getDatasetProfile().getId();
principal), DatasetWizardModel datasetWizardModel = dataset.toDataModel(dmp, uuid);
quickWizard.getDmp().getDatasetProfile().getId()), this.datasetManager.createOrUpdate(datasetWizardModel, principal);
principal);
} }
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<QuickWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created")); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<QuickWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
} }

View File

@ -28,7 +28,8 @@ public class DatasetDescriptionQuickWizardModel extends PagedDatasetProfile {
newDataset.setCreated(new Date()); newDataset.setCreated(new Date());
newDataset.setProfile(profile); newDataset.setProfile(profile);
newDataset.setDmp(dmp); newDataset.setDmp(dmp);
newDataset.setStatus(Dataset.Status.SAVED.getValue()); newDataset.setStatus((short) this.getStatus());
//newDataset.setStatus(Dataset.Status.SAVED.getValue());
newDataset.setDatasetProfileDefinition((PagedDatasetProfile) this); newDataset.setDatasetProfileDefinition((PagedDatasetProfile) this);

View File

@ -29,7 +29,9 @@
<div class="navigation-buttons-container"> <div class="navigation-buttons-container">
<button matStepperPrevious mat-raised-button <button matStepperPrevious mat-raised-button
color="primary">{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.BACK' | translate}}</button> color="primary">{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.BACK' | translate}}</button>
<button style="float:right;" matStepperNext mat-raised-button (click)='save()' <button class="saveAndFinalizeButton" matStepperNext mat-raised-button (click)='saveFinalize()' [disabled]="!formGroup.valid"
color="primary">{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.SAVE-AND-FINALIZE' | translate}}</button>
<button class="saveButton" matStepperNext mat-raised-button (click)='save()'
color="primary">{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.SAVE' | translate}}</button> color="primary">{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.SAVE' | translate}}</button>
</div> </div>
</mat-step> </mat-step>

View File

@ -0,0 +1,7 @@
.saveAndFinalizeButton{
float:right;
}
.saveButton{
float:right;
margin-right: 15px;
}

View File

@ -1,5 +1,5 @@
import { Component, OnInit, ViewChild } from '@angular/core'; import { Component, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms'; import { FormBuilder, FormGroup, FormArray } from '@angular/forms';
import { MatStepper } from '@angular/material'; import { MatStepper } from '@angular/material';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { BaseComponent } from '../../core/common/base/base.component'; import { BaseComponent } from '../../core/common/base/base.component';
@ -49,6 +49,17 @@ export class DatasetCreateWizard extends BaseComponent implements OnInit, IBread
} }
save() { save() {
for(let control of (this.formGroup.get('datasets').get('datasetsList') as FormArray).controls){
control.get('status').setValue('0');
}
this.submit();
}
saveFinalize() {
if (!this.isFormValid()) { return; }
for(let control of (this.formGroup.get('datasets').get('datasetsList') as FormArray).controls){
control.get('status').setValue('1');
}
this.submit(); this.submit();
} }
@ -60,6 +71,10 @@ export class DatasetCreateWizard extends BaseComponent implements OnInit, IBread
) )
} }
public isFormValid() {
return this.formGroup.valid;
}
onCallbackSuccess(): void { onCallbackSuccess(): void {
this.uiNotificationService.snackBarNotification(this.isNew ? this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-CREATION') : this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success); this.uiNotificationService.snackBarNotification(this.isNew ? this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-CREATION') : this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
this.router.navigate(['/home']); this.router.navigate(['/home']);

View File

@ -8,6 +8,7 @@ import { FormGroup, FormControl } from "@angular/forms";
export class QuickWizardDatasetDescriptionModel extends DatasetDescriptionFormEditorModel { export class QuickWizardDatasetDescriptionModel extends DatasetDescriptionFormEditorModel {
public datasetLabel: string; public datasetLabel: string;
//public status: number;
fromModel(item: DatasetProfileDefinitionModel): DatasetDescriptionFormEditorModel { fromModel(item: DatasetProfileDefinitionModel): DatasetDescriptionFormEditorModel {
super.fromModel(item); super.fromModel(item);
@ -17,6 +18,7 @@ export class QuickWizardDatasetDescriptionModel extends DatasetDescriptionFormEd
buildForm(): FormGroup { buildForm(): FormGroup {
const formGroup: FormGroup = super.buildForm(); const formGroup: FormGroup = super.buildForm();
formGroup.addControl('datasetLabel', new FormControl({value: this.datasetLabel})); formGroup.addControl('datasetLabel', new FormControl({value: this.datasetLabel}));
formGroup.addControl('status', new FormControl({value: this.status}));
return formGroup; return formGroup;
} }
} }

View File

@ -67,6 +67,9 @@ export class QuickWizardEditorComponent extends BaseComponent implements OnInit,
formSubmit(): void { formSubmit(): void {
this.touchAllFormFields(this.formGroup); this.touchAllFormFields(this.formGroup);
if (this.formGroup.get('datasets') && this.formGroup.get('datasets').get('datasetsList') && (this.formGroup.get('datasets').get('datasetsList') as FormArray).length > 0) { if (this.formGroup.get('datasets') && this.formGroup.get('datasets').get('datasetsList') && (this.formGroup.get('datasets').get('datasetsList') as FormArray).length > 0) {
for(let control of (this.formGroup.get('datasets').get('datasetsList') as FormArray).controls){
control.get('status').setValue('0');
}
this.onSubmit(); this.onSubmit();
} else { } else {
return; return;
@ -75,7 +78,9 @@ export class QuickWizardEditorComponent extends BaseComponent implements OnInit,
saveFinalize() { saveFinalize() {
if (!this.isFormValid()) { return; } if (!this.isFormValid()) { return; }
this.formGroup.get('status').setValue('1'); for(let control of (this.formGroup.get('datasets').get('datasetsList') as FormArray).controls){
control.get('status').setValue('1');
}
this.onSubmit(); this.onSubmit();
} }