quickWizard Create project

quickWizard Create Dmp
quickWizard Create Datasets
This commit is contained in:
Diamantis Tziotzios 2019-03-01 17:16:21 +02:00
parent 88f789bbb4
commit da8d929d9e
27 changed files with 1475 additions and 0 deletions

View File

@ -0,0 +1,61 @@
package eu.eudat.controllers;
import eu.eudat.logic.managers.*;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.quickwizard.DatasetDescriptionQuickWizardModel;
import eu.eudat.models.data.quickwizard.QuickWizardModel;
import eu.eudat.models.data.security.Principal;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.transaction.Transactional;
import javax.validation.Valid;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/quick-wizard/"})
public class QuickWizardController extends BaseController {
private QuickWizardManager quickWizardManager;
private DatasetManager datasetManager;
@Autowired
public QuickWizardController(ApiContext apiContext, QuickWizardManager quickWizardManager,DatasetManager datasetManager) {
super(apiContext);
this.quickWizardManager = quickWizardManager;
this.datasetManager = datasetManager;
}
@Transactional
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<QuickWizardModel>> addQuickWizardModel(@Valid @RequestBody QuickWizardModel quickWizard, Principal principal) throws Exception {
//Create Project
eu.eudat.data.entities.Project projectEntity = this.quickWizardManager.createOrUpdate(this.getApiContext().getOperationsContext().getFileStorageService(),
this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(),
this.getApiContext().getOperationsContext().getDatabaseRepository().getContentDao(),
this.getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao(),
quickWizard.getProject().toDataProject(), principal);
//Create Dmp
eu.eudat.data.entities.DMP dmpEntity = this.quickWizardManager.createOrUpdate(this.getApiContext(), quickWizard.getDmp().toDataDmp(projectEntity), principal);
//Create Datasets
quickWizard.getDmp().setId(dmpEntity.getId());
for(DatasetDescriptionQuickWizardModel dataset : quickWizard.getDatasets().getDatasetsList()){
this.datasetManager.createOrUpdate(this.getApiContext(), dataset.toDataModel(quickWizard.getDmp().toDataDmp(projectEntity),quickWizard.getDmp().getDatasetProfile().getId()), principal);
}
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<QuickWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
}
}

View File

@ -0,0 +1,47 @@
package eu.eudat.logic.managers;
import eu.eudat.data.dao.entities.ContentDao;
import eu.eudat.data.dao.entities.ProjectDao;
import eu.eudat.data.dao.entities.UserInfoDao;
import eu.eudat.data.entities.*;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.helpers.FileStorageService;
import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.security.Principal;
import org.springframework.stereotype.Component;
import eu.eudat.data.entities.DMP;
import java.io.IOException;
import java.text.ParseException;
@Component
public class QuickWizardManager {
public static Project createOrUpdate(FileStorageService fileStorageService, ProjectDao projectRepository, ContentDao contentRepository, UserInfoDao userInfoRepository, eu.eudat.models.data.project.Project project, Principal principal) throws ParseException, IOException {
eu.eudat.data.entities.Project projectEntity = project.toDataModel();
projectEntity.setType(eu.eudat.data.entities.Project.ProjectType.INTERNAL.getValue());
projectEntity.setCreationUser(userInfoRepository.find(principal.getId()));
Project projectEntityRet = projectRepository.createOrUpdate(projectEntity);
return projectEntityRet;
}
public DMP createOrUpdate(ApiContext apiContext, DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
DMP newDmp = dataManagementPlan.toDataModel();
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
newDmp.setCreator(user);
DMP dmpret = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
return dmpret;
}
/*public void createOrUpdate(ApiContext apiContext, DatasetDao datasetRepository,DMP dmp, eu.eudat.data.entities.DatasetProfile profile , DatasetQuickWizardModel datasetwrapper, Principal principal) throws Exception {
for (DatasetDescriptionQuickWizardModel dataset :datasetwrapper.getDatasetsList()){
datasetRepository.createOrUpdate(dataset.toDataModel(dmp,profile));
}
}*/
}

View File

@ -0,0 +1,39 @@
package eu.eudat.models.data.quickwizard;
import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.data.entities.Dataset;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import java.util.Date;
import java.util.UUID;
public class DatasetDescriptionQuickWizardModel extends PagedDatasetProfile {
private String datasetLabel;
public String getDatasetLabel() {
return datasetLabel;
}
public void setDatasetLabel(String datasetLabel) {
this.datasetLabel = datasetLabel;
}
public DatasetWizardModel toDataModel(DataManagementPlan dmp,UUID profile){
DatasetWizardModel newDataset = new DatasetWizardModel();
newDataset.setLabel(datasetLabel);
newDataset.setCreated(new Date());
newDataset.setProfile(profile);
newDataset.setDmp(dmp);
newDataset.setStatus(Dataset.Status.SAVED.getValue());
newDataset.setDatasetProfileDefinition((PagedDatasetProfile) this);
return newDataset;
}
}

View File

@ -0,0 +1,15 @@
package eu.eudat.models.data.quickwizard;
import java.util.List;
public class DatasetQuickWizardModel {
private List<DatasetDescriptionQuickWizardModel> datasetsList;
public List<DatasetDescriptionQuickWizardModel> getDatasetsList() {
return datasetsList;
}
public void setDatasetsList(List<DatasetDescriptionQuickWizardModel> datasetsList) {
this.datasetsList = datasetsList;
}
}

View File

@ -0,0 +1,108 @@
package eu.eudat.models.data.quickwizard;
import eu.eudat.data.entities.Project;
import eu.eudat.models.data.dmp.AssociatedProfile;
import eu.eudat.models.data.userinfo.UserInfo;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
public class DmpQuickWizardModel {
private UUID id;
private String label;
private int status;
private AssociatedProfile profile;
private String description;
private eu.eudat.models.data.project.Project project;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public AssociatedProfile getProfile() {
return profile;
}
public void setProfile(AssociatedProfile profile) {
this.profile = profile;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public eu.eudat.models.data.project.Project getProject() {
return project;
}
public void setProject(eu.eudat.models.data.project.Project project) {
this.project = project;
}
public eu.eudat.models.data.dmp.DataManagementPlan toDataDmp(Project project) {
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlanEntity = new eu.eudat.models.data.dmp.DataManagementPlan();
dataManagementPlanEntity.setId(this.id);
dataManagementPlanEntity.setVersion(0);
dataManagementPlanEntity.setLabel(this.label);
if (project != null) {
eu.eudat.models.data.project.Project importProject = new eu.eudat.models.data.project.Project();
dataManagementPlanEntity.setProject(importProject.fromDataModel(project));
}
if(this.profile!=null) {
List<AssociatedProfile> assProfile = new LinkedList<>();
assProfile.add(this.profile);
dataManagementPlanEntity.setProfiles(assProfile);
}
dataManagementPlanEntity.setStatus((short) this.status);
dataManagementPlanEntity.setDescription(this.description);
dataManagementPlanEntity.setProperties(null);
dataManagementPlanEntity.setCreated(new Date());
List<UserInfo> user = new LinkedList<UserInfo>();
eu.eudat.models.data.userinfo.UserInfo usetInfo = new eu.eudat.models.data.userinfo.UserInfo();
usetInfo.fromDataModel(project.getCreationUser());
user.add(usetInfo);
dataManagementPlanEntity.setAssociatedUsers(user);
return dataManagementPlanEntity;
}
public eu.eudat.data.entities.DatasetProfile getDatasetProfile(){
eu.eudat.data.entities.DatasetProfile datasetProfile = new eu.eudat.data.entities.DatasetProfile();
datasetProfile.setDefinition(this.profile.getLabel());
datasetProfile.setLabel(this.profile.getLabel());
datasetProfile.setId(this.profile.getId());
return datasetProfile;
}
}

View File

@ -0,0 +1,64 @@
package eu.eudat.models.data.quickwizard;
import java.util.Date;
import java.util.UUID;
public class ProjectQuickWizardModel {
private UUID id;
private String label;
private eu.eudat.data.entities.Project.Status status;
private String description;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public short getStatus() {
return status.getValue();
}
public void setStatus(Short status) {
this.status = eu.eudat.data.entities.Project.Status.fromInteger(status);
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public eu.eudat.models.data.project.Project toDataProject(){
eu.eudat.models.data.project.Project toProject = new eu.eudat.models.data.project.Project();
toProject.setId(this.id);
toProject.setAbbreviation("");
toProject.setLabel(this.label);
toProject.setReference("dmp:" + this.label);
toProject.setUri("");
toProject.setDefinition("");
toProject.setCreated(new Date());
toProject.setStatus(this.status != null ? this.getStatus() : eu.eudat.data.entities.Project.Status.ACTIVE.getValue());
toProject.setModified(new Date());
toProject.setDescription(this.description);
return toProject;
}
}

View File

@ -0,0 +1,35 @@
package eu.eudat.models.data.quickwizard;
public class QuickWizardModel {
private ProjectQuickWizardModel project;
private DmpQuickWizardModel dmp;
private DatasetQuickWizardModel datasets;
public ProjectQuickWizardModel getProject() {
return project;
}
public void setProject(ProjectQuickWizardModel project) {
this.project = project;
}
public DmpQuickWizardModel getDmp() {
return dmp;
}
public void setDmp(DmpQuickWizardModel dmp) {
this.dmp = dmp;
}
public DatasetQuickWizardModel getDatasets() {
return datasets;
}
public void setDatasets(DatasetQuickWizardModel datasets) {
this.datasets = datasets;
}
}

View File

@ -0,0 +1,26 @@
import { HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from '../../../../environments/environment';
import { QuickWizardEditorWizardModel } from '../../../ui/quick-wizard/quick-wizard-editor/quick-wizard-editor.model';
import { BaseHttpService } from '../http/base-http.service';
@Injectable()
export class QuickWizardService {
private actionUrl: string;
private headers: HttpHeaders;
constructor(private http: BaseHttpService) {
this.actionUrl = environment.Server + 'quick-wizard/';
}
createQuickWizard(quickWizard: QuickWizardEditorWizardModel): Observable<QuickWizardEditorWizardModel> {
return this.http.post<QuickWizardEditorWizardModel>(this.actionUrl, quickWizard, { headers: this.headers });
}
}

View File

@ -0,0 +1,40 @@
import { FormBuilder, FormGroup } from "@angular/forms";
import { BackendErrorValidator } from "../../../common/forms/validation/custom-validator";
import { ValidationErrorModel } from "../../../common/forms/validation/error-model/validation-error-model";
import { ValidationContext } from "../../../common/forms/validation/validation-context";
import { BaseFormModel } from "../../../core/model/base-form-model";
import { DatasetWizardEditorModel } from "../../dataset/dataset-wizard/dataset-wizard-editor.model";
import { QuickWizardDatasetDescriptionModel } from "./quick-wizard-dataset-description-model";
export class DatasetEditorWizardModel extends BaseFormModel {
public datasetsList: Array<QuickWizardDatasetDescriptionModel> = [];
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel();
fromModel(item: DatasetWizardEditorModel[]): DatasetEditorWizardModel {
return this;
}
buildForm(context: ValidationContext = null, disabled: boolean = false): FormGroup {
if (context == null) { context = this.createValidationContext(); }
const formGroup = new FormBuilder().group({});
const formArray = new Array<FormGroup>();
this.datasetsList.forEach(item => {
const form: FormGroup = item.buildForm();
formArray.push(form);
});
formGroup.addControl('datasetsList', this.formBuilder.array(formArray));
return formGroup;
}
createValidationContext(): ValidationContext {
const baseContext: ValidationContext = new ValidationContext();
baseContext.validation.push({ key: 'datasetsList', validators: [BackendErrorValidator(this.validationErrorModel, 'datasetsList')] });
return baseContext;
}
}

View File

@ -0,0 +1,57 @@
<div class="row">
<div class="col">
<h3>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.THIRD-STEP.NEW-TITLE' | translate}} {{titlePrefix}}</h3>
</div>
<div></div>
<div class="col-auto">
<mat-button-toggle-group [ngModel]="_inputValue">
<mat-button-toggle value="list" (change)="onValChange($event.value)">
<mat-icon>format_align_left</mat-icon>
</mat-button-toggle>
<mat-button-toggle value="add" (change)="onValChange($event.value)">
<mat-icon>add</mat-icon>
</mat-button-toggle>
</mat-button-toggle-group>
</div>
<div class="col-12">
<div *ngIf="toggleButton=='0'" class="row">
<div class="col-12"
*ngFor="let dataset of this.formGroup.get('datasets').get('datasetsList')['controls'] let i=index;">
<mat-card>
<mat-card-content>
<div class="row">
<div class="col">
<h4>{{dataset.get('datasetLabel').value}}</h4>
</div>
<div class="col-auto">
<button mat-icon-button type="button" (click)="editDataset(i);" [disabled]="viewOnly">
<mat-icon>edit</mat-icon>
</button>
</div>
<div class="col-auto">
<button mat-icon-button type="button" (click)="deleteDataset(i);" [disabled]="viewOnly">
<mat-icon>delete</mat-icon>
</button>
</div>
</div>
<!-- {{this.formGroup.get('datasets').get('datasetsList').value | json }} -->
</mat-card-content>
</mat-card>
</div>
<!-- <button mat-fab class="mat-fab-bottom-right" color="primary" (click)="listOrEditor()">
<mat-icon class="mat-24">add</mat-icon>
</button> -->
</div>
</div>
<div *ngIf="toggleButton=='2' && editedDataset" class="row">
<mat-form-field class="col-md-12">
<input matInput placeholder="{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.THIRD-STEP.DATASET-LABEL' | translate}}" type="string" name="datasetLabel"
[formControl]="this.formGroup.get('datasets').get('datasetsList')['controls'][lastIndexOfDataset].get('datasetLabel')" required>
</mat-form-field>
<app-dataset-description-form class="col-12"
[form]="this.formGroup.get('datasets').get('datasetsList')['controls'][lastIndexOfDataset]"
[visibilityRules]="this.datasetProfileDefinition.rules" [datasetProfileId]="profile.value">
</app-dataset-description-form>
</div>
</div>

View File

@ -0,0 +1,97 @@
import { Component, Input, OnInit } from "@angular/core";
import { FormArray, FormGroup } from "@angular/forms";
import { Observable } from "rxjs";
import { takeUntil } from "rxjs/operators";
import { BaseComponent } from "../../../core/common/base/base.component";
import { DatasetProfileModel } from "../../../core/model/dataset/dataset-profile";
import { DatasetWizardService } from "../../../core/services/dataset-wizard/dataset-wizard.service";
import { DatasetWizardEditorModel } from "../../dataset/dataset-wizard/dataset-wizard-editor.model";
import { BreadcrumbItem } from "../../misc/breadcrumb/definition/breadcrumb-item";
import { IBreadCrumbComponent } from "../../misc/breadcrumb/definition/IBreadCrumbComponent";
import { DatasetDescriptionFormEditorModel } from "../../misc/dataset-description-form/dataset-description-form.model";
import { QuickWizardDatasetDescriptionModel } from "./quick-wizard-dataset-description-model";
import { IfStmt } from "@angular/compiler";
@Component({
selector: 'app-dataset-editor-wizard-component',
templateUrl: 'dataset-editor-wizard.component.html',
styleUrls: ['./dataset-editor-wizard.component.scss']
})
export class DatasetEditorWizardComponent extends BaseComponent implements OnInit, IBreadCrumbComponent {
breadCrumbs: Observable<BreadcrumbItem[]>;
@Input() formGroup: FormGroup;
@Input() profile: FormGroup;// DatasetProfileModel;
@Input() datasetLabel:FormGroup;
editedDataset: boolean = false;
dataset: DatasetDescriptionFormEditorModel;
public datasetProfileDefinition: DatasetDescriptionFormEditorModel;
public lastIndexOfDataset = 0;
public toggleButton=0;
public _inputValue: string;
constructor(
private datasetWizardService: DatasetWizardService
) {
super();
}
ngOnInit(): void {
}
onValChange(event: any){
if(event=="list"){
this.toggleButton=0;
this.editedDataset=false;
this._inputValue="list";
}else if (event=="add"){
this.addDataset();
this.toggleButton=2;
this._inputValue="dataset";
}else if (event=="dataset"){
this.toggleButton=2;
this._inputValue="dataset";
}
}
editDataset(index:number){
this.lastIndexOfDataset = index;
this.toggleButton=2;
this.editedDataset=true;
this._inputValue="dataset"
}
deleteDataset(index:number){//TODO: delete Dataset From List
this.lastIndexOfDataset = index;
this.toggleButton=0;
this.editedDataset=false;
this._inputValue="list";
(this.formGroup.get('datasets').get('datasetsList') as FormArray).removeAt(index);
}
addDataset() {
this.datasetWizardService.getDefinition(this.profile.value["id"])
.pipe(takeUntil(this._destroyed))
.subscribe(item => {
this.datasetProfileDefinition = new DatasetDescriptionFormEditorModel().fromModel(item);
const formArray: FormArray = (this.formGroup.get('datasets').get('datasetsList') as FormArray);
this.lastIndexOfDataset = formArray.length;
let dataset = new QuickWizardDatasetDescriptionModel().fromModel(this.datasetProfileDefinition);
let formGroup = dataset.buildForm();
formGroup.get('datasetLabel').setValue("Dataset :"+this.profile.value["label"]+" For Dmp : "+this.datasetLabel.value);
formArray.push(formGroup);
this.editedDataset=true;
});
}
}

View File

@ -0,0 +1,22 @@
import { DatasetDescriptionFormEditorModel } from "../../misc/dataset-description-form/dataset-description-form.model";
import { DatasetProfileDefinitionModel } from "../../../core/model/dataset-profile-definition/dataset-profile-definition";
import { FormGroup, FormControl } from "@angular/forms";
export class QuickWizardDatasetDescriptionModel extends DatasetDescriptionFormEditorModel {
public datasetLabel: string;
fromModel(item: DatasetProfileDefinitionModel): DatasetDescriptionFormEditorModel {
super.fromModel(item);
return this;
}
buildForm(): FormGroup {
const formGroup: FormGroup = super.buildForm();
formGroup.addControl('datasetLabel', new FormControl({value: this.datasetLabel}));
return formGroup;
}
}

View File

@ -0,0 +1,51 @@
import { Status } from "../../../core/common/enum/Status";
import { DmpProfile, DmpProfileDefinition } from "../../../core/model/dmp-profile/dmp-profile";
import { ValidationErrorModel } from "../../../common/forms/validation/error-model/validation-error-model";
import { DmpModel } from "../../../core/model/dmp/dmp";
import { ValidationContext } from "../../../common/forms/validation/validation-context";
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
import { BackendErrorValidator } from "../../../common/forms/validation/custom-validator";
import { ValidJsonValidator } from "../../../library/auto-complete/auto-complete-custom-validator";
export class DmpEditorWizardModel {
public id: string;
public label: string;
public status: Status = Status.Active;
public description: String;
public profile: DmpProfile;
public definition: DmpProfileDefinition;
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel();
fromModel(item: DmpModel): DmpEditorWizardModel {
this.id = item.id;
this.label = item.label;
this.status = item.status;
this.description = item.description;
this.profile = item.profiles[0];
return this;
}
buildForm(context: ValidationContext = null, disabled: boolean = false): FormGroup {
if (context == null) { context = this.createValidationContext(); }
const formGroup = new FormBuilder().group({
id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators],
label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators],
status: [{ value: this.status, disabled: disabled }, context.getValidation('status').validators],
description: [{ value: this.description, disabled: disabled }, context.getValidation('description').validators],
profile: [{ value: this.profile, disabled: disabled }, context.getValidation('profile').validators],
});
return formGroup;
}
createValidationContext(): ValidationContext {
const baseContext: ValidationContext = new ValidationContext();
baseContext.validation.push({ key: 'id', validators: [BackendErrorValidator(this.validationErrorModel, 'id')] });
baseContext.validation.push({ key: 'label', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'label')] });
baseContext.validation.push({ key: 'status', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'status')] });
baseContext.validation.push({ key: 'description', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'description')] });
baseContext.validation.push({ key: 'profile', validators: [Validators.required, ValidJsonValidator, BackendErrorValidator(this.validationErrorModel, 'profile')] });
return baseContext;
}
}

View File

@ -0,0 +1,67 @@
<div class="dmp-editor">
<div>
<mat-card-title *ngIf="isNew">{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.SECOND-STEP.NEW-TITLE' | translate}}</mat-card-title>
<mat-card-title *ngIf="!isNew">
<h3>{{formGroup?.get('label')?.value}} </h3>
</mat-card-title>
</div>
<form *ngIf="formGroup" (ngSubmit)="formSubmit()" [formGroup]="formGroup">
<mat-card>
<mat-card-content>
<div class="row">
<mat-form-field class="col-md-12">
<input matInput placeholder="{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.SECOND-STEP.FIELDS.NAME' | translate}}" type="text" name="label"
formControlName="label" required>
<mat-error *ngIf="formGroup.get('label').hasError('backendError')">
{{formGroup.get('label').getError('backendError').message}}</mat-error>
<mat-error *ngIf="formGroup.get('label').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<mat-form-field class="col-md-12">
<textarea matInput class="description-area"
placeholder="{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.SECOND-STEP.FIELDS.DESCRIPTION' | translate}}" formControlName="description"
required></textarea>
<mat-error *ngIf="formGroup.get('description').hasError('backendError')">
{{formGroup.get('description').getError('backendError').message}}</mat-error>
<mat-error *ngIf="formGroup.get('description').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' |
translate}}</mat-error>
</mat-form-field>
<mat-form-field class="col-12">
<app-single-auto-complete [required]='true' [formControl]="formGroup.get('profile')"
placeholder="{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.SECOND-STEP.FIELDS.PROFILE' | translate}}"
[configuration]="profilesAutoCompleteConfiguration">
</app-single-auto-complete>
<mat-error *ngIf="formGroup.get('profile').hasError('backendError')">
{{formGroup.get('profile').getError('backendError').message}}</mat-error>
<mat-error *ngIf="formGroup.get('profile').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<!-- <mat-form-field class="col-md-6">
<app-single-auto-complete [required]='false' [formControl]="formGroup.get('profile')"
placeholder="{{'DMP-EDITOR.FIELDS.PROFILE' | translate}}"
[configuration]="dmpProfileAutoCompleteConfiguration">
</app-single-auto-complete>
</mat-form-field>
<div class="col-md-12">
<div class="row">
<div class="col-auto"><button mat-raised-button color="primary" (click)="cancel()"
type="button">{{'DMP-EDITOR.ACTIONS.CANCEL'
| translate}}</button></div>
<div class="col"></div>
<div class="col-auto" *ngIf="!isNew && this.formGroup.enabled"><button mat-raised-button
color="primary" type="button"
(click)="delete()">{{'DMP-EDITOR.ACTIONS.DELETE' | translate}}</button></div>
<div class="col-auto" *ngIf="this.formGroup.enabled"><button mat-raised-button
color="primary" type="submit">{{'DMP-EDITOR.ACTIONS.SAVE'
| translate}}</button></div>
<div class="col-auto" *ngIf="dmp.lockable && this.formGroup.enabled"><button type="button"
mat-raised-button color="primary"
(click)="saveAndFinalize()">{{'DMP-EDITOR.ACTIONS.FINALISE' | translate}}</button>
</div>
</div>
</div> -->
</div>
</mat-card-content>
</mat-card>
</form>
</div>

View File

@ -0,0 +1,158 @@
import { Component, OnInit, Input } from '@angular/core';
import { BaseComponent } from "../../../core/common/base/base.component";
import { BreadcrumbItem } from '../../misc/breadcrumb/definition/breadcrumb-item';
import { Observable } from 'rxjs';
import { IBreadCrumbComponent } from '../../misc/breadcrumb/definition/IBreadCrumbComponent';
import { MatSnackBar } from '@angular/material';
import { Router, ActivatedRoute } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { FormGroup, AbstractControl, FormControl, FormArray } from '@angular/forms';
import { DmpEditorWizardModel } from './dmp-editor-wizard-model';
import { UiNotificationService, SnackBarNotificationLevel } from '../../../core/services/notification/ui-notification-service';
import { ValidationErrorModel } from '../../../common/forms/validation/error-model/validation-error-model';
import { SingleAutoCompleteConfiguration } from '../../../library/auto-complete/single/single-auto-complete-configuration';
import { DatasetProfileModel } from '../../../core/model/dataset/dataset-profile';
import { RequestItem } from '../../../core/query/request-item';
import { DatasetProfileCriteria } from '../../../core/query/dataset-profile/dataset-profile-criteria';
import { DmpService } from '../../../core/services/dmp/dmp.service';
@Component({
selector: 'app-quick-wizard-dmp-editor-component',
templateUrl: 'dmp-editor-wizard.component.html',
styleUrls: ['./dmp-editor-wizard.component.scss']
})
export class DmpEditorWizardComponent extends BaseComponent implements OnInit, IBreadCrumbComponent {
breadCrumbs: Observable<BreadcrumbItem[]> = Observable.of([]);
isNew = true;
dmp: DmpEditorWizardModel;
@Input() formGroup: FormGroup;
@Input() dmpLabel: FormGroup;
//formGroup: FormGroup = null;
private uiNotificationService: UiNotificationService
profilesAutoCompleteConfiguration:SingleAutoCompleteConfiguration;
filteredProfiles: DatasetProfileModel[];
filteredProfilesAsync = false;
constructor(
public snackBar: MatSnackBar,
public router: Router,
private route: ActivatedRoute,
private _service: DmpService,
public language: TranslateService,
) {
super();
}
ngOnInit(): void {
this.profilesAutoCompleteConfiguration = {
filterFn: this.filterProfiles.bind(this),
initialItems: (extraData) => this.filterProfiles(''),
displayFn: (item) => item['label'],
titleFn: (item) => item['label']
};
if (this.formGroup == null) {
this.dmp = new DmpEditorWizardModel();
this.formGroup = this.dmp.buildForm();
}
this.formGroup.get('label').setValue("Dmp From Project : "+ this.dmpLabel.value);
this.breadCrumbs = Observable.of([
{
parentComponentName: 'project',
label: 'Dmp',
url: '/quick-wizard/dmp'
}]
);
}
formSubmit(): void {
this.touchAllFormFields(this.formGroup);
if (!this.isFormValid()) { return; }
this.onSubmit();
}
public isFormValid() {
return this.formGroup.valid;
}
public touchAllFormFields(formControl: AbstractControl) {
if (formControl instanceof FormControl) {
formControl.markAsTouched();
} else if (formControl instanceof FormGroup) {
Object.keys(formControl.controls).forEach(item => {
const control = formControl.get(item);
this.touchAllFormFields(control);
});
} else if (formControl instanceof FormArray) {
formControl.controls.forEach(item => {
this.touchAllFormFields(item);
});
}
}
onSubmit(): void {
// this.projectService.createProject(this.formGroup.value)
// .pipe(takeUntil(this._destroyed))
// .subscribe(
// complete => this.onCallbackSuccess(),
// error => this.onCallbackError(error)
// );
}
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.router.navigate(['/dmp']);
}
onCallbackError(errorResponse: any) {
this.setErrorModel(errorResponse.error.payload);
this.validateAllFormFields(this.formGroup);
}
public setErrorModel(validationErrorModel: ValidationErrorModel) {
Object.keys(validationErrorModel).forEach(item => {
(<any>this.dmp.validationErrorModel)[item] = (<any>validationErrorModel)[item];
});
}
public validateAllFormFields(formControl: AbstractControl) {
if (formControl instanceof FormControl) {
formControl.updateValueAndValidity({ emitEvent: false });
} else if (formControl instanceof FormGroup) {
Object.keys(formControl.controls).forEach(item => {
const control = formControl.get(item);
this.validateAllFormFields(control);
});
} else if (formControl instanceof FormArray) {
formControl.controls.forEach(item => {
this.validateAllFormFields(item);
});
}
}
filterProfiles(value: string): Observable<DatasetProfileModel[]> {
this.filteredProfiles = undefined;
this.filteredProfilesAsync = true;
const request = new RequestItem<DatasetProfileCriteria>();
const criteria = new DatasetProfileCriteria();
criteria.like = value;
request.criteria = criteria;
return this._service.searchDMPProfiles(request);
}
}

View File

@ -0,0 +1,44 @@
import { Status } from "../../../core/common/enum/Status";
import { ProjectListingModel } from "../../../core/model/project/project-listing";
import { ValidationContext } from "../../../common/forms/validation/validation-context";
import { FormGroup, FormBuilder, Validators } from "@angular/forms";
import { BackendErrorValidator } from "../../../common/forms/validation/custom-validator";
import { ValidationErrorModel } from "../../../common/forms/validation/error-model/validation-error-model";
export class ProjectEditorWizardModel {
public id: string;
public label: string;
public status: Status = Status.Active;
public description: String;
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel();
fromModel(item: ProjectListingModel): ProjectEditorWizardModel {
this.id = item.id;
this.label = item.label;
this.status = item.status;
this.description = item.description;
return this;
}
buildForm(context: ValidationContext = null, disabled: boolean = false): FormGroup {
if (context == null) { context = this.createValidationContext(); }
const formGroup = new FormBuilder().group({
id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators],
label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators],
status: [{ value: this.status, disabled: disabled }, context.getValidation('status').validators],
description: [{ value: this.description, disabled: disabled }, context.getValidation('description').validators],
});
return formGroup;
}
createValidationContext(): ValidationContext {
const baseContext: ValidationContext = new ValidationContext();
baseContext.validation.push({ key: 'id', validators: [] });
baseContext.validation.push({ key: 'label', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'label')] });
baseContext.validation.push({ key: 'status', validators: [] });
baseContext.validation.push({ key: 'description', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'description')] });
return baseContext;
}
}

View File

@ -0,0 +1,42 @@
<div class="project-editor">
<mat-card-title *ngIf="isNew">{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.FIRST-STEP.NEW-TITLE' | translate}}</mat-card-title>
<form *ngIf="formGroup" (ngSubmit)="formSubmit()" [formGroup]="formGroup">
<mat-card>
<mat-card-header>
</mat-card-header>
<mat-card-content>
<div class="row">
<mat-form-field class="col-md-12">
<input matInput placeholder="{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.FIRST-STEP.FIELDS.LABEL' | translate}}" type="text" name="label" formControlName="label" required>
<mat-error *ngIf="formGroup.get('label').hasError('backendError')">{{formGroup.get('label').getError('backendError').message}}</mat-error>
<mat-error *ngIf="formGroup.get('label').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<!--
<mat-form-field class="col-md-6">
<input matInput (focus)="startDate.open()" (click)="startDate.open()" placeholder="{{'PROJECT-EDITOR.FIELDS.START' | translate}}" class="table-input" [matDatepicker]="startDate" formControlName="startDate">
<mat-datepicker-toggle matSuffix [for]="startDate"></mat-datepicker-toggle>
<mat-datepicker #startDate></mat-datepicker>
<mat-error *ngIf="formGroup.get('startDate').hasError('backendError')">{{formGroup.get('startDate').getError('backendError').message}}</mat-error>
<mat-error *ngIf="formGroup.get('startDate').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<mat-form-field class="col-md-6">
<input matInput (focus)="endDate.open()" (click)="endDate.open()" placeholder="{{'PROJECT-EDITOR.FIELDS.END' | translate}}" class="table-input" [matDatepicker]="endDate" formControlName="endDate">
<mat-datepicker-toggle matSuffix [for]="endDate"></mat-datepicker-toggle>
<mat-datepicker #endDate></mat-datepicker>
<mat-error *ngIf="formGroup.get('endDate').hasError('backendError')">{{formGroup.get('endDate').getError('backendError').message}}</mat-error>
<mat-error *ngIf="formGroup.get('endDate').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<mat-error *ngIf="formGroup.hasError('startAfterEndError')"class="col-md-12">{{'GENERAL.VALIDATION.PROJECT-START-AFTER-END' | translate}}</mat-error> -->
<mat-form-field class="col-md-12">
<textarea matInput class="description-area" placeholder="{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.FIRST-STEP.FIELDS.DESCRIPTION' | translate}}" formControlName="description" required></textarea>
<mat-error *ngIf="formGroup.get('description').hasError('backendError')">{{formGroup.get('description').getError('backendError').message}}</mat-error>
<mat-error *ngIf="formGroup.get('description').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</mat-card-content>
</mat-card>
</form>
</div>

View File

@ -0,0 +1,146 @@
import { Component, OnInit, Input } from '@angular/core';
import { BaseComponent } from "../../../core/common/base/base.component";
import { BreadcrumbItem } from '../../misc/breadcrumb/definition/breadcrumb-item';
import { Observable } from 'rxjs';
import { IBreadCrumbComponent } from '../../misc/breadcrumb/definition/IBreadCrumbComponent';
import { ProjectEditorWizardModel } from './project-editor-wizard-model';
import { MatSnackBar } from '@angular/material';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { FormGroup, AbstractControl, FormControl, FormArray } from '@angular/forms';
import { takeUntil } from 'rxjs/operators';
import { ValidationErrorModel } from '../../../common/forms/validation/error-model/validation-error-model';
import { SnackBarNotificationLevel, UiNotificationService } from '../../../core/services/notification/ui-notification-service';
@Component({
selector: 'app-quick-wizard-project-editor-component',
templateUrl: 'project-editor-wizard.component.html',
styleUrls: ['./project-editor-wizard.component.scss']
})
export class ProjectEditorWizardComponent extends BaseComponent implements OnInit, IBreadCrumbComponent {
breadCrumbs: Observable<BreadcrumbItem[]> = Observable.of([]);
isNew = true;
project: ProjectEditorWizardModel;
@Input() formGroup: FormGroup;
//formGroup: FormGroup = null;
private uiNotificationService: UiNotificationService
constructor(
public snackBar: MatSnackBar,
private route: ActivatedRoute,
public router: Router,
public language: TranslateService,
) {
super();
}
ngOnInit() {
if (this.formGroup == null) {
this.project = new ProjectEditorWizardModel();
this.formGroup = this.project.buildForm();
}
this.breadCrumbs = Observable.of([
{
parentComponentName: 'QuickCreate',
label: 'Project',
url: '/quick-wizard/project'
}]
);
// this.route.params
// .pipe(takeUntil(this._destroyed))
// .subscribe((params: Params) => {
// const itemId = params['id'];
// if (itemId != null) {
// this.isNew = false;
// this.projectService.getSingle(itemId).map(data => data as ProjectListingModel)
// .pipe(takeUntil(this._destroyed))
// .subscribe(data => {
// this.project = new ProjectEditorModel().fromModel(data);
// this.formGroup = this.project.buildForm(null, this.project.type === ProjectType.External || !this.editMode);
// this.breadCrumbs = Observable.of([
// { parentComponentName: 'ProjectListingComponent', label: 'Projects', url: '/projects' },
// ]);
// });
// } else {
// this.breadCrumbs = Observable.of([
// { parentComponentName: 'QuickWizardComponent', label: 'Projects', url: '/projects' },
// ]);
// this.project = new ProjectEditorWizardModel();
// setTimeout(() => {
// this.formGroup = this.project.buildForm();
// });
// }
// });
}
formSubmit(): void {
this.touchAllFormFields(this.formGroup);
if (!this.isFormValid()) { return; }
this.onSubmit();
}
public isFormValid() {
return this.formGroup.valid;
}
public touchAllFormFields(formControl: AbstractControl) {
if (formControl instanceof FormControl) {
formControl.markAsTouched();
} else if (formControl instanceof FormGroup) {
Object.keys(formControl.controls).forEach(item => {
const control = formControl.get(item);
this.touchAllFormFields(control);
});
} else if (formControl instanceof FormArray) {
formControl.controls.forEach(item => {
this.touchAllFormFields(item);
});
}
}
onSubmit(): void {
// this.projectService.createProject(this.formGroup.value)
// .pipe(takeUntil(this._destroyed))
// .subscribe(
// complete => this.onCallbackSuccess(),
// error => this.onCallbackError(error)
// );
}
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.router.navigate(['/project']);
}
onCallbackError(errorResponse: any) {
this.setErrorModel(errorResponse.error.payload);
this.validateAllFormFields(this.formGroup);
}
public setErrorModel(validationErrorModel: ValidationErrorModel) {
Object.keys(validationErrorModel).forEach(item => {
(<any>this.project.validationErrorModel)[item] = (<any>validationErrorModel)[item];
});
}
public validateAllFormFields(formControl: AbstractControl) {
if (formControl instanceof FormControl) {
formControl.updateValueAndValidity({ emitEvent: false });
} else if (formControl instanceof FormGroup) {
Object.keys(formControl.controls).forEach(item => {
const control = formControl.get(item);
this.validateAllFormFields(control);
});
} else if (formControl instanceof FormArray) {
formControl.controls.forEach(item => {
this.validateAllFormFields(item);
});
}
}
}

View File

@ -0,0 +1,61 @@
<div class="quick-wizard-editor">
<form [formGroup]="formGroup">
<h3 *ngIf="isNew">{{ 'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.TITLE' | translate }}</h3>
<div class="row">
<mat-horizontal-stepper linear class="col-12" #stepper>
<mat-step [stepControl]="formGroup.get('project')">
<ng-template matStepLabel>
{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.FIRST-STEP.TITLE' | translate}}
</ng-template>
<div *ngIf="formGroup.get('project')">
<app-quick-wizard-project-editor-component class="col-12"
[formGroup]="formGroup.get('project')">
</app-quick-wizard-project-editor-component>
</div>
<div class="navigation-buttons-container">
<button style="float:right;" matStepperNext mat-raised-button
color="primary">{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.NEXT' | translate}}</button>
</div>
</mat-step>
<mat-step [stepControl]="formGroup.get('dmp')">
<ng-template matStepLabel>
{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.SECOND-STEP.TITLE' | translate}}
</ng-template>
<div *ngIf="formGroup.get('dmp')">
<app-quick-wizard-dmp-editor-component class="col-12" [formGroup]="formGroup.get('dmp')" [dmpLabel]="formGroup.get('project').get('label')">
</app-quick-wizard-dmp-editor-component>
</div>
<div class="navigation-buttons-container">
<button matStepperPrevious mat-raised-button
color="primary">{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.BACK' | translate}}</button>
<button style="float:right;" matStepperNext mat-raised-button color="primary">
{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.NEXT' | translate}}</button>
</div>
</mat-step>
<mat-step [stepControl]="formGroup.get('datasets')">
<ng-template matStepLabel>
{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.THIRD-STEP.TITLE' | translate}}
</ng-template>
<div *ngIf="formGroup.get('datasets')">
<!-- <div *ngIf="this.isActiveStep(3)" class="row"> -->
<app-dataset-editor-wizard-component class="col-12" [formGroup]="formGroup" [profile]="formGroup.get('dmp').get('profile')" [datasetLabel]="formGroup.get('dmp').get('label')">
</app-dataset-editor-wizard-component>
<!-- <app-dataset-description-form class="col-12" *ngIf="formGroup && datasetWizardModel && datasetWizardModel.datasetProfileDefinition"
[form]="this.formGroup.get('datasetProfileDefinition')" [visibilityRules]="datasetWizardModel.datasetProfileDefinition.rules"
[datasetProfileId]="formGroup.get('profile').value"></app-dataset-description-form>
<div class="col-12 description-action-row">
</app-dataset-description-form> -->
<!-- </div> -->
</div>
<div class="navigation-buttons-container">
<button matStepperPrevious mat-raised-button
color="primary">{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.BACK' | translate}}</button>
<button style="float:right;" matStepperNext mat-raised-button (click)='formSubmit()'
color="primary">{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.SAVE' | translate}}</button>
</div>
</mat-step>
</mat-horizontal-stepper>
</div>
</form>
</div>

View File

@ -0,0 +1,164 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms';
import { MatSnackBar, MatStepper } from '@angular/material';
import { ActivatedRoute, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { Observable } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { ValidationErrorModel } from '../../../common/forms/validation/error-model/validation-error-model';
import { BaseComponent } from "../../../core/common/base/base.component";
import { SnackBarNotificationLevel, UiNotificationService } from '../../../core/services/notification/ui-notification-service';
import { BreadcrumbItem } from '../../misc/breadcrumb/definition/breadcrumb-item';
import { IBreadCrumbComponent } from '../../misc/breadcrumb/definition/IBreadCrumbComponent';
import { DmpEditorWizardModel } from '../dmp-editor/dmp-editor-wizard-model';
import { ProjectEditorWizardModel } from '../project-editor/project-editor-wizard-model';
import { QuickWizardEditorWizardModel } from './quick-wizard-editor.model';
import { QuickWizardService } from '../../../core/services/quick-wizard/quick-wizard.service';
import { DatasetEditorWizardModel } from '../dataset-editor/dataset-editor-wizard-model';
@Component({
selector: 'app-quick-wizard-editor-component',
templateUrl: 'quick-wizard-editor.component.html',
styleUrls: ['./quick-wizard-editor.component.scss']
})
export class QuickWizardEditorComponent extends BaseComponent implements OnInit, IBreadCrumbComponent {
breadCrumbs: Observable<BreadcrumbItem[]> = Observable.of([]);
@ViewChild('stepper') stepper: MatStepper;
isNew = true;
quickWizard: QuickWizardEditorWizardModel
formGroup: FormGroup = null;
private uiNotificationService: UiNotificationService
isLinear = false;
firstStepFormGroup: FormGroup;
secondFormGroup: FormGroup;
constructor(
public snackBar: MatSnackBar,
private route: ActivatedRoute,
public router: Router,
public language: TranslateService,
public quickWizardService: QuickWizardService
) {
super();
}
ngOnInit(): void {
this.quickWizard = new QuickWizardEditorWizardModel();
// this.quickWizard.project = new ProjectEditorWizardModel();
// this.quickWizard.dmp = new DmpEditorWizardModel();
// this.quickWizard.datasets = new DatasetEditorWizardModel();
this.formGroup = this.quickWizard.buildForm();
this.breadCrumbs = Observable.of([
{
parentComponentName: 'Dashboard',
label: 'QuickCreate',
url: '/quick-wizard'
}]
);
// this.route.params
// .pipe(takeUntil(this._destroyed))
// .subscribe((params: Params) => {
// const itemId = params['id'];
// if (itemId != null) {
// this.isNew = false;
// this.projectService.getSingle(itemId).map(data => data as ProjectListingModel)
// .pipe(takeUntil(this._destroyed))
// .subscribe(data => {
// this.project = new ProjectEditorModel().fromModel(data);
// this.formGroup = this.project.buildForm(null, this.project.type === ProjectType.External || !this.editMode);
// this.breadCrumbs = Observable.of([
// { parentComponentName: 'ProjectListingComponent', label: 'Projects', url: '/projects' },
// ]);
// });
// } else {
// this.breadCrumbs = Observable.of([
// { parentComponentName: '/', label: 'QuickWizard', url: '/quickwizard' },
// ]);
// setTimeout(() => {
// this.formGroup = this.quickWizard.buildForm();
// });
// }
// });
}
formSubmit(): void {
this.touchAllFormFields(this.formGroup);
if (!this.isFormValid()) { return; }
this.onSubmit();
}
public isFormValid() {
return this.formGroup.valid;
}
public touchAllFormFields(formControl: AbstractControl) {
if (formControl instanceof FormControl) {
formControl.markAsTouched();
} else if (formControl instanceof FormGroup) {
Object.keys(formControl.controls).forEach(item => {
const control = formControl.get(item);
this.touchAllFormFields(control);
});
} else if (formControl instanceof FormArray) {
formControl.controls.forEach(item => {
this.touchAllFormFields(item);
});
}
}
onSubmit(): void {
if (!this.isFormValid()) { return; }
this.quickWizardService.createQuickWizard(this.formGroup.value)
.pipe(takeUntil(this._destroyed))
.subscribe(
complete => this.onCallbackSuccess(),
error => this.onCallbackError(error)
);
}
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.router.navigate(['/quickwizard']);
}
onCallbackError(errorResponse: any) {
// this.setErrorModel(errorResponse.error.payload);
this.validateAllFormFields(this.formGroup);
}
// public setErrorModel(validationErrorModel: ValidationErrorModel) {
// Object.keys(validationErrorModel).forEach(item => {
// (<any>this.quickWizard.validationErrorModel)[item] = (<any>validationErrorModel)[item];
// });
// }
public validateAllFormFields(formControl: AbstractControl) {
if (formControl instanceof FormControl) {
formControl.updateValueAndValidity({ emitEvent: false });
} else if (formControl instanceof FormGroup) {
Object.keys(formControl.controls).forEach(item => {
const control = formControl.get(item);
this.validateAllFormFields(control);
});
} else if (formControl instanceof FormArray) {
formControl.controls.forEach(item => {
this.validateAllFormFields(item);
});
}
}
isActiveStep(index: number) {
return this.stepper.selectedIndex === index;
}
}

View File

@ -0,0 +1,57 @@
import { ProjectEditorWizardModel } from "../project-editor/project-editor-wizard-model";
import { DmpEditorWizardModel } from "../dmp-editor/dmp-editor-wizard-model";
import { DmpModel } from "../../../core/model/dmp/dmp";
import { ProjectListingModel } from "../../../core/model/project/project-listing";
import { DatasetModel } from "../../../core/model/dataset/dataset";
import { ValidationContext } from "../../../common/forms/validation/validation-context";
import { FormGroup, FormBuilder, Validators } from "@angular/forms";
import { BackendErrorValidator } from "../../../common/forms/validation/custom-validator";
import { ValidationErrorModel } from "../../../common/forms/validation/error-model/validation-error-model";
import { DatasetEditorWizardModel } from "../dataset-editor/dataset-editor-wizard-model";
import { DatasetWizardEditorModel } from "../../dataset/dataset-wizard/dataset-wizard-editor.model";
export class QuickWizardEditorWizardModel {
public project: ProjectEditorWizardModel;
public dmp: DmpEditorWizardModel;
public datasets: DatasetEditorWizardModel;
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel();
fromModelProject(item: ProjectListingModel): QuickWizardEditorWizardModel {
this.project.fromModel(item);
return this;
}
fromModelDmp(item: DmpModel): QuickWizardEditorWizardModel {
this.dmp.fromModel(item);
return this;
}
fromModelDataset(item: DatasetWizardEditorModel[]): QuickWizardEditorWizardModel {
this.datasets.fromModel(item);
return this;
}
buildForm(context: ValidationContext = null, disabled: boolean = false): FormGroup {
if (context == null) { context = this.createValidationContext(); }
const formGroup = new FormBuilder().group({
project: new ProjectEditorWizardModel().buildForm(),
dmp: new DmpEditorWizardModel().buildForm(),
datasets: new DatasetEditorWizardModel().buildForm()
});
return formGroup;
}
createValidationContext(): ValidationContext {
const baseContext: ValidationContext = new ValidationContext();
baseContext.validation.push({ key: 'project', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'project')] });
baseContext.validation.push({ key: 'dmp', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'dmp')] });
baseContext.validation.push({ key: 'datasets', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'datasets')] });
return baseContext;
}
}

View File

@ -0,0 +1,32 @@
import { NgModule } from '@angular/core';
import { CommonFormsModule } from '../../common/forms/common-forms.module';
import { CommonUiModule } from '../../common/ui/common-ui.module';
import { ConfirmationDialogModule } from '../../library/confirmation-dialog/confirmation-dialog.module';
import { UrlListingModule } from '../../library/url-listing/url-listing.module';
import { QuickWizardRoutingModule } from './quick-wizard.rooting';
import { ProjectEditorWizardComponent } from './project-editor/project-editor-wizard.component';
import { DmpEditorWizardComponent } from './dmp-editor/dmp-editor-wizard.component';
import { QuickWizardEditorComponent } from './quick-wizard-editor/quick-wizard-editor.component';
import { AutoCompleteModule } from '../../library/auto-complete/auto-complete.module';
import { DatasetEditorWizardComponent } from './dataset-editor/dataset-editor-wizard.component';
import { DatasetDescriptionFormModule } from '../misc/dataset-description-form/dataset-description-form.module';
@NgModule({
imports: [
CommonUiModule,
CommonFormsModule,
UrlListingModule,
AutoCompleteModule,
ConfirmationDialogModule,
QuickWizardRoutingModule,
DatasetDescriptionFormModule
],
declarations: [
ProjectEditorWizardComponent,
DmpEditorWizardComponent,
QuickWizardEditorComponent,
DatasetEditorWizardComponent
]
})
export class OuickWizardModule { }

View File

@ -0,0 +1,42 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { DmpEditorWizardComponent } from './dmp-editor/dmp-editor-wizard.component';
import { ProjectEditorWizardComponent } from './project-editor/project-editor-wizard.component';
import { QuickWizardEditorComponent } from './quick-wizard-editor/quick-wizard-editor.component';
import { DatasetEditorWizardComponent } from './dataset-editor/dataset-editor-wizard.component';
const routes: Routes = [
{
path: '',
component: QuickWizardEditorComponent,
data: {
breadcrumb: true
},
},{
path: 'project',
component: ProjectEditorWizardComponent,
data: {
breadcrumb: true
},
},
{
path: 'dmp',
component: DmpEditorWizardComponent,
data: {
breadcrumb: true
},
},
{
path: 'dataset',
component: DatasetEditorWizardComponent,
data: {
breadcrumb: true
},
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class QuickWizardRoutingModule { }