This commit is contained in:
annabakouli 2017-12-12 10:37:07 +02:00
commit 7e07448770
6 changed files with 81 additions and 31 deletions

View File

@ -1,17 +1,17 @@
<div>
<div [formGroup]="form">
<div class="form-row">
<div class="form-group col-md-4">
<div class="form-group col-md-6">
<label>Rule Type</label>
<select class="form-control" formControlName="ruleType">
<option>field value</option>
</select>
</div>
<div class="form-group col-md-4">
<div class="form-group col-md-6">
<label>Target</label>
<input type="text" class="form-control" placeholder="field id" formControlName="target" (change)="TargetValidation()">
</div>
<div class="form-group col-md-4">
<!-- <div class="form-group col-md-4">
<label>Rule style</label>
<select class="form-control">
<option>boolean</option>
@ -19,12 +19,12 @@
<option>unchecked</option>
<option>dropdown value</option>
</select>
</div>
<div class="form-group col-md-6">
</div> -->
<!-- <div class="form-group col-md-6">
<label>Value Type</label>
<input type="text" class="form-control" formControlName="valueType">
</div>
<div class="form-group col-md-6">
</div> -->
<div class="form-group col-md-12">
<label>Value</label>
<input type="text" class="form-control" formControlName="value">
</div>

View File

@ -1,5 +1,5 @@
<div class="ui-g dynamic-formc full-width full-height">
<ng-sidebar-container>
<ng-sidebar-container contentClass="scrollableContent">
<ng-sidebar mode="push" position="right" [(opened)]="visibleSidebar">
<table-of-content class="toc-container full-height" [model]="dataModel"></table-of-content>
</ng-sidebar>
@ -7,9 +7,8 @@
<div class="ui-g" ng-sidebar-content>
<button type="button" style="margin: 15px;" class="btn btn-primary" (click)="toggleSidebar()" icon="fa-arrow-left">Table Of Contents</button>
<button type="button" style="margin-top: 15px;margin-bottom: 15px;margin-right: 15px;" class="btn btn-primary" (click)="submit();">Save and Finalize</button>
<progress-bar class="ui-g" *ngIf="progressbar" [formGroup]=form></progress-bar>
<div class="ui-g-12">
<p-steps [model]="stepperItems" [(activeIndex)]="this.currentPage" [readonly]="false"></p-steps>
<p-steps [model]="stepperItems" [activeIndex]="this.currentPageIndex" (activeIndexChange)="changePageIndex($event)" [readonly]="false"></p-steps>
</div>
<div class="ui-g-12">
<progress-bar *ngIf="form" [formGroup]="form"></progress-bar>

View File

@ -61,13 +61,13 @@ export class DynamicFormComponent implements OnInit {
id: string;
datasetId: string;
pathName: string;
pages: Set<number>;
pages: Array<number>;
stepperItems: MenuItem[] = new Array<MenuItem>();
activeStepperIndex: number = 1;
visibleSidebar: boolean = false;
private progressbar: boolean = false;
private currentPage: number = 0;
private currentPageIndex: number = 0;
private fragment: string;
constructor(private serverService: ServerService, private router: Router, private pdfService: PDFService,
@ -86,8 +86,8 @@ export class DynamicFormComponent implements OnInit {
this.serverService.getSingleDataset(this.datasetId).subscribe(
response => {
this.dataModel = new JsonSerializer<DatasetModel>().fromJSONObject(response, DatasetModel);
this.pages = this.getPages(this.dataModel);
this.dataModel = new JsonSerializer<DatasetModel>().fromJSONObject(response, DatasetModel);
this.pages = this.getPages(this.dataModel);
this.createPagination();
this.form = this.dataModel.buildForm();
this.visibilityRulesService.formGroup = this.form;
@ -96,16 +96,13 @@ export class DynamicFormComponent implements OnInit {
this.progressbar = true;
this.route.fragment.subscribe((fragment: string) => {
if (fragment && document.querySelector('#' + fragment)) {
document.querySelector('#' + fragment).scrollIntoView();
this.visibleSidebar = true;
}
//if (fragment)
this.scrollTo(fragment);
});
this.route.queryParams.subscribe((params) => {
if (params && "page" in params && !isNaN(params["page"]))
this.currentPage = Number.parseInt(params["page"]);
//this.visibleSidebar = true;
if (params && "page" in params)
this.changeCurrentPage(params["page"]);
});
},
error => {
@ -132,16 +129,18 @@ export class DynamicFormComponent implements OnInit {
this.visibleSidebar = !this.visibleSidebar;
}
getPages(model: DatasetModel): Set<number> {
let pageSet = new Set<number>();
model.sections.forEach(section => {
pageSet.add(section.page);
})
return pageSet;
getPages(model: DatasetModel): Array<number> {
let pageSet = new Set<number>();
model.sections.forEach(section => {
pageSet.add(section.page);
});
return Array.from(pageSet).sort((a, b) => a - b);
}
shouldDisplaySection(section: Section): Boolean {
return (section.page - 1) == this.currentPage;
return (section.page) == this.pages[this.currentPageIndex];
}
createPagination() {
@ -151,6 +150,29 @@ export class DynamicFormComponent implements OnInit {
})
});
}
changePageIndex(index: any) {
this.router.navigate([this.route.snapshot.url[0] + "/" + this.route.snapshot.url[1]], { queryParams: { page: this.pages[index] } });
}
scrollTo(sectionID: string) {
if (!sectionID) return;
var element = document.querySelector('#' + sectionID);
if (!element) return;
element.scrollIntoView();
// this.visibleSidebar = true;
//var scrollElement = document.querySelector('.scrollableContent');
//scrollElement.scrollTop = topElement.offsetTop;
}
changeCurrentPage(pageString: string) {
if (!pageString) return;
var page = parseInt(pageString);
if (isNaN(page)) return;
var pageIndex = this.pages.indexOf(page);
if (pageIndex === -1) return;
this.currentPageIndex = pageIndex;
}
/* scrollToElemID(elemID) {
scroll("#" + elemID);
}

View File

@ -1 +1 @@
<p-progressBar [value]="value" [style]="{'height': '30px'}"></p-progressBar>
<p-progressBar [value]="value" [style]="{'height': '30px'}"></p-progressBar>

View File

@ -0,0 +1,24 @@
import { BaseModel } from './BaseModel';
import { FormGroup } from '@angular/forms';
import { FormGenerator } from './interfaces/FormGenerator';
import { Serializable } from './interfaces/Serializable';
export class DefaultValue extends BaseModel implements Serializable<DefaultValue>, FormGenerator<FormGroup>{
public type: string;
public value: string;
fromJSONObject(item: any): DefaultValue {
this.type = item.type;
this.value = item.value;
return this;
}
buildForm(): FormGroup {
let formGroup = this.formBuilder.group({
type: [this.type],
value: [this.value]
});
return formGroup;
}
}

View File

@ -4,11 +4,13 @@ import { FormGenerator } from './interfaces/FormGenerator';
import { JsonSerializer } from '../utilities/JsonSerializer';
import { Serializable } from './interfaces/Serializable';
import { Multiplicity } from './Multiplicity';
import { DefaultValue } from './DefaultValue';
export class Field extends BaseModel implements Serializable<Field>, FormGenerator<FormGroup>{
public id: string;
public title: string;
public value: string;
public defaultValue: DefaultValue;
public description: string;
public extendedDescription: string;
public viewStyle: string;
@ -17,16 +19,19 @@ export class Field extends BaseModel implements Serializable<Field>, FormGenerat
public multiplicity: Multiplicity;
public multiplicityItems: Array<Field> = new Array<Field>();
public data: any;
fromJSONObject(item: any): Field {
this.id = item.id;
this.title = item.title;
this.value = item.value;
//this.value = item.value;
this.description = item.description;
this.extendedDescription = item.extendedDescription;
this.viewStyle = item.viewStyle;
this.defaultVisibility = item.defaultVisibility;
this.page = item.page;
//this.multiplicity = new JsonSerializer<Multiplicity>().fromJSONObject(item.multiplicity, Multiplicity);
this.defaultValue = new JsonSerializer<DefaultValue>().fromJSONObject(item.defaultValue, DefaultValue);
this.value = this.defaultValue.value && !item.value? this.defaultValue.value: item.value;
this.multiplicity = new Multiplicity();
this.multiplicity.max = 2;
this.multiplicityItems = new JsonSerializer<Field>().fromJSONArray(item.multiplicityItems, Field);