Implemented Preview Step in Admin Dataset Profile Definition

This commit is contained in:
Ioannis Kalyvas 2018-10-19 10:35:35 +03:00
parent 5094dca494
commit b7193d2dda
9 changed files with 113 additions and 61 deletions

View File

@ -61,7 +61,6 @@ public class Admin extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/admin/preview"}, consumes = "application/json",produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/admin/preview"}, consumes = "application/json",produces = "application/json")
public ResponseEntity<ResponseItem<PagedDatasetProfile>> getPreview(@RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { public ResponseEntity<ResponseItem<PagedDatasetProfile>> getPreview(@RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) {
//this.getLoggerService().info(principal, "Admin Previewed Dataset Profile");
eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext()); eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext());
eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = UserManager.generateDatasetProfileModel(modelDefinition); eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = UserManager.generateDatasetProfileModel(modelDefinition);
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile(); PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();

View File

@ -88,7 +88,6 @@ public class FieldSet implements Comparable, ViewStyleDefinition<eu.eudat.models
@Override @Override
public eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.FieldSet toDatabaseDefinition(eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.FieldSet item) { public eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.FieldSet toDatabaseDefinition(eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.FieldSet item) {
if (this.id == null || this.id.isEmpty()) this.id = "fieldSet_" + RandomStringUtils.random(5, true, true); if (this.id == null || this.id.isEmpty()) this.id = "fieldSet_" + RandomStringUtils.random(5, true, true);
List<eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field> viewStylefields = new ModelBuilder().toViewStyleDefinition(this.fields, eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field.class); List<eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field> viewStylefields = new ModelBuilder().toViewStyleDefinition(this.fields, eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field.class);
item.setFields(viewStylefields); item.setFields(viewStylefields);
item.setId(this.id); item.setId(this.id);

View File

@ -1,10 +1,13 @@
<div class="container" [formGroup]='form'> <div class="container" *ngIf="form" [formGroup]='form'>
<mat-form-field class="full-width"> <mat-form-field class="full-width">
<input matInput formControlName="label" placeholder="{{'DYNAMIC-FORM.FIELDS.LABEL' | translate}}" required> <input matInput formControlName="label" placeholder="{{'DYNAMIC-FORM.FIELDS.LABEL' | translate}}" required>
<mat-error *ngIf="form.get('label').errors?.required">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error> <mat-error *ngIf="form.get('label').errors?.required">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field> </mat-form-field>
<mat-horizontal-stepper [linear]="true" #stepper> <mat-horizontal-stepper [linear]="true" #stepper>
<mat-step> <mat-step>
<ng-template matStepLabel>{{'DATASET-PROFILE.PAGES-DESCRIPTION' | translate}}</ng-template>
<div>
<div class="panel-group"> <div class="panel-group">
<mat-expansion-panel *ngFor="let page of dataModel.pages; let i=index;" #panel> <mat-expansion-panel *ngFor="let page of dataModel.pages; let i=index;" #panel>
<mat-expansion-panel-header> <mat-expansion-panel-header>
@ -28,8 +31,11 @@
{{'DYNAMIC-FORM.ACTIONS.ADD-PAGE' | translate}} {{'DYNAMIC-FORM.ACTIONS.ADD-PAGE' | translate}}
</button> </button>
</div> </div>
</div>
</mat-step> </mat-step>
<mat-step> <mat-step>
<ng-template matStepLabel>{{'DATASET-PROFILE.FORM-DESCRIPTION' | translate}}</ng-template>
<div>
<div> <div>
<mat-expansion-panel *ngFor="let section of dataModel.sections; let i=index;" #panel> <mat-expansion-panel *ngFor="let section of dataModel.sections; let i=index;" #panel>
<mat-expansion-panel-header> <mat-expansion-panel-header>
@ -53,8 +59,14 @@
{{'DYNAMIC-FORM.ACTIONS.ADD-SECTION' | translate}} {{'DYNAMIC-FORM.ACTIONS.ADD-SECTION' | translate}}
</button> </button>
</div> </div>
</div>
</mat-step>
<mat-step>
<ng-template matStepLabel>{{'DATASET-PROFILE.PREVIEW' | translate}}</ng-template>
<div *ngIf='this.isStepActive(2)'>
<app-dynamic-form *ngIf="dataWizardModel && previewerFormGroup" [form]="this.previewerFormGroup" [dataModel]="dataWizardModel"></app-dynamic-form>
</div>
</mat-step> </mat-step>
</mat-horizontal-stepper> </mat-horizontal-stepper>
<button mat-button (click)="preview()">{{'DYNAMIC-FORM.ACTIONS.PREVIEW' | translate}}</button>
<button mat-raised-button color="primary" type="button" (click)='onSubmit()' [disabled]="!form.valid">Save</button> <button mat-raised-button color="primary" type="button" (click)='onSubmit()' [disabled]="!form.valid">Save</button>
</div> </div>

View File

@ -2,14 +2,17 @@
import { DatasetProfileService } from '../../services/dataset-profile.service'; import { DatasetProfileService } from '../../services/dataset-profile.service';
import { DatasetProfileModelAdmin } from '../../models/datasetProfileAdmin/DatasetProfileModelAdmin'; import { DatasetProfileModelAdmin } from '../../models/datasetProfileAdmin/DatasetProfileModelAdmin';
import { Page } from '../../models/datasetProfileAdmin/Page'; import { Page } from '../../models/datasetProfileAdmin/Page';
import { Component, OnInit } from '@angular/core'; import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms'; import { FormGroup, FormControl } from '@angular/forms';
import { FormArray } from '@angular/forms'; import { FormArray } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import { DatasetProfileAdmin } from '../../services/datasetProfileAdmin/datasetProfileAfmin.service'; import { DatasetProfileAdmin } from '../../services/datasetProfileAdmin/datasetProfileAfmin.service';
import { Section } from '../../models/datasetProfileAdmin/Section'; import { Section } from '../../models/datasetProfileAdmin/Section';
import { MatDialog } from '@angular/material'; import { MatDialog, MatHorizontalStepper, MatStepper } from '@angular/material';
import { DatasetProfilePreviewerComponent } from '../previewer/dataset-profile-previewer.component'; import { DatasetProfilePreviewerComponent } from '../previewer/dataset-profile-previewer.component';
import { Observable } from 'rxjs';
import { DatasetWizardModel } from '../../models/datasets/DatasetWizardModel';
import { DatasetProfileDefinitionModel } from '../../models/DatasetProfileDefinitionModel';
@Component({ @Component({
selector: 'app-form-component', selector: 'app-form-component',
@ -18,16 +21,20 @@ import { DatasetProfilePreviewerComponent } from '../previewer/dataset-profile-p
styleUrls: ['./form.component.scss'] styleUrls: ['./form.component.scss']
}) })
export class FormComponent implements OnInit { export class FormComponent implements OnInit, AfterViewInit {
dataModel: DatasetProfileModelAdmin; dataModel: DatasetProfileModelAdmin;
form: FormGroup; form: FormGroup;
previewerFormGroup: FormGroup;
private profileID: string; private profileID: string;
private cloneId: string; private cloneId: string;
dataWizardModel: DatasetWizardModel;
@ViewChild('stepper') stepper: MatHorizontalStepper;
constructor( constructor(
public datasetprofileAdmin: DatasetProfileAdmin, public datasetprofileAdmin: DatasetProfileAdmin,
private datasetProfileService: DatasetProfileService, private datasetProfileService: DatasetProfileService,
private datasetProfileAdminService: DatasetProfileAdmin,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router, private router: Router,
public dialog: MatDialog, public dialog: MatDialog,
@ -36,19 +43,40 @@ export class FormComponent implements OnInit {
this.cloneId = route.snapshot.params['cloneid']; this.cloneId = route.snapshot.params['cloneid'];
} }
ngAfterViewInit(): void {
console.log(this.stepper);
}
ngOnInit() { ngOnInit() {
this.dataModel = JsonSerializer.fromJSONObject(new DatasetProfileModelAdmin(), DatasetProfileModelAdmin); this.dataModel = JsonSerializer.fromJSONObject(new DatasetProfileModelAdmin(), DatasetProfileModelAdmin);
this.form = this.dataModel.buildForm();
if (this.profileID) { if (this.profileID) {
this.datasetProfileService.getDatasetProfileById(this.profileID).subscribe((data) => { this.datasetProfileService.getDatasetProfileById(this.profileID).subscribe((data) => {
this.dataModel = JsonSerializer.fromJSONObject(data, DatasetProfileModelAdmin); this.dataModel = JsonSerializer.fromJSONObject(data, DatasetProfileModelAdmin);
this.form = this.dataModel.buildForm(); this.form = this.dataModel.buildForm();
this.form.valueChanges.subscribe(change => {
this.datasetProfileAdminService.preview(this.dataModel).subscribe(dataset => {
const datasetModel = new DatasetWizardModel();
datasetModel.datasetProfileDefinition = JsonSerializer.fromJSONObject(dataset, DatasetProfileDefinitionModel);
this.dataWizardModel = datasetModel;
this.previewerFormGroup = <FormGroup>this.dataWizardModel.buildForm().get('datasetProfileDefinition');
});
});
this.form.updateValueAndValidity();
}); });
} else if (this.cloneId) { } else if (this.cloneId) {
this.datasetprofileAdmin.clone(this.cloneId).subscribe((data) => { this.datasetprofileAdmin.clone(this.cloneId).subscribe((data) => {
this.dataModel = JsonSerializer.fromJSONObject(data, DatasetProfileModelAdmin); this.dataModel = JsonSerializer.fromJSONObject(data, DatasetProfileModelAdmin);
this.form = this.dataModel.buildForm(); this.form = this.dataModel.buildForm();
this.form.valueChanges.subscribe(change => {
this.datasetProfileAdminService.preview(this.dataModel).subscribe(dataset => {
const datasetModel = new DatasetWizardModel();
datasetModel.datasetProfileDefinition = JsonSerializer.fromJSONObject(dataset, DatasetProfileDefinitionModel);
this.dataWizardModel = datasetModel;
this.previewerFormGroup = <FormGroup>this.dataWizardModel.buildForm().get('datasetProfileDefinition');
});
});
this.form.updateValueAndValidity();
}); });
} else { } else {
this.addSection(); this.addSection();
@ -106,14 +134,7 @@ export class FormComponent implements OnInit {
} }
} }
preview() { isStepActive(step: number) {
const dialogRef = this.dialog.open(DatasetProfilePreviewerComponent, { return this.stepper && this.stepper.selectedIndex === step;
height: '355px',
width: '700px',
data: {
model: this.dataModel
} }
});
}
} }

View File

@ -34,6 +34,9 @@
<button mat-menu-item (click)="downloadXml(this.dataManagementPlan.id)"> <button mat-menu-item (click)="downloadXml(this.dataManagementPlan.id)">
<mat-icon>save_alt</mat-icon>{{'DMP-LISTING.ACTIONS.DOWNLOAD-XML' | translate}} <mat-icon>save_alt</mat-icon>{{'DMP-LISTING.ACTIONS.DOWNLOAD-XML' | translate}}
</button> </button>
<button mat-menu-item (click)="downloadDocx(this.dataManagementPlan.id)">
<mat-icon>save_alt</mat-icon>{{'DMP-LISTING.ACTIONS.DOWNLOAD-DOCX' | translate}}
</button>
</mat-menu> </mat-menu>
<div> <div>
<button mat-icon-button type="button" [matMenuTriggerFor]="actionsMenu"> <button mat-icon-button type="button" [matMenuTriggerFor]="actionsMenu">
@ -133,8 +136,8 @@
translate}}</button> translate}}</button>
<button *ngIf="this.formGroup.enabled" mat-raised-button color="primary" type="submit">{{'DMP-EDITOR.ACTIONS.SAVE' <button *ngIf="this.formGroup.enabled" mat-raised-button color="primary" type="submit">{{'DMP-EDITOR.ACTIONS.SAVE'
| translate}}</button> | translate}}</button>
<button *ngIf="dataManagementPlan.lockable && this.formGroup.enabled" type="button" mat-raised-button <button *ngIf="dataManagementPlan.lockable && this.formGroup.enabled" type="button" mat-raised-button color="primary"
color="primary" (click)="saveAndFinalize()">{{'DMP-EDITOR.ACTIONS.FINALISE' (click)="saveAndFinalize()">{{'DMP-EDITOR.ACTIONS.FINALISE'
| translate}}</button> | translate}}</button>
<button *ngIf="!isNew && this.formGroup.enabled" mat-raised-button color="primary" type="button" (click)="openConfirm(formGroup.get('label').value, formGroup.get('id').value)">{{'DMP-EDITOR.ACTIONS.DELETE' <button *ngIf="!isNew && this.formGroup.enabled" mat-raised-button color="primary" type="button" (click)="openConfirm(formGroup.get('label').value, formGroup.get('id').value)">{{'DMP-EDITOR.ACTIONS.DELETE'
| translate}}</button> | translate}}</button>

View File

@ -343,6 +343,15 @@ export class DataManagementPlanEditorComponent implements AfterViewInit, IBreadC
}); });
} }
downloadDocx(id: string) {
this.dataManagementPlanService.downloadDocx(id).subscribe(response => {
const blob = new Blob([response.body], { type: 'application/octet-stream' });
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
FileSaver.saveAs(blob, filename);
});
}
getFilenameFromContentDispositionHeader(header: string): string { getFilenameFromContentDispositionHeader(header: string): string {
const regex: RegExp = new RegExp(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g); const regex: RegExp = new RegExp(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g);

View File

@ -14,7 +14,7 @@
<div> <div>
<div class="alignment-center"> <div class="alignment-center">
<!-- <ngb-pagination *ngIf="pages" [collectionSize]="pages.length*10" [page]="currentPageIndex" (pageChange)="changePageIndex($event)" aria-label="Default pagination"></ngb-pagination> --> <!-- <ngb-pagination *ngIf="pages" [collectionSize]="pages.length*10" [page]="currentPageIndex" (pageChange)="changePageIndex($event)" aria-label="Default pagination"></ngb-pagination> -->
<app-progress-bar *ngIf="form" [formGroup]="form"></app-progress-bar> <!-- <app-progress-bar *ngIf="form" [formGroup]="form"></app-progress-bar> -->
</div> </div>
</div> </div>

View File

@ -75,4 +75,8 @@ export class DataManagementPlanService {
public downloadXML(id: string): Observable<HttpResponse<Blob>> { public downloadXML(id: string): Observable<HttpResponse<Blob>> {
return this.httpClient.get(this.actionUrl + 'getXml/' + id, { responseType: 'blob', observe: 'response' }); return this.httpClient.get(this.actionUrl + 'getXml/' + id, { responseType: 'blob', observe: 'response' });
} }
public downloadDocx(id: string): Observable<HttpResponse<Blob>> {
return this.httpClient.get(this.actionUrl + 'getWord/' + id, { responseType: 'blob', observe: 'response' });
}
} }

View File

@ -360,6 +360,11 @@
"SAVE": "Save" "SAVE": "Save"
} }
}, },
"DATASET-PROFILE": {
"PREVIEW": "Preview",
"FORM-DESCRIPTION": "Form Description",
"PAGES-DESCRIPTION": "Pages Description"
},
"RECENT-ACTIVITY": { "RECENT-ACTIVITY": {
"MY-TITLE-PROJECT": "My Recent Project Activity", "MY-TITLE-PROJECT": "My Recent Project Activity",
"MY-TITLE-DMP": "My Recent DMP Activity", "MY-TITLE-DMP": "My Recent DMP Activity",