no message

This commit is contained in:
Diamantis Tziotzios 2017-12-11 15:47:52 +02:00
parent 869d69bc0d
commit cde1596c35
10 changed files with 175 additions and 80 deletions

View File

@ -18,5 +18,5 @@ app-root {
} }
html { html {
overflow-y: hidden /* overflow-y: hidden */
} }

View File

@ -6,7 +6,16 @@
<i>{{group.extendedDescription}}</i> <i>{{group.extendedDescription}}</i>
</h5> --> </h5> -->
<div *ngFor="let compositeField of group.compositeFields; let i = index;"> <div *ngFor="let compositeField of group.compositeFields; let i = index;">
<div *ngIf="(compositeField?.multiplicity?.max - 1) > (compositeField?.multiplicityItems?.length)">
<a (click)="addMultipleField(i)" style="cursor: pointer">
Add one more field +
</a>
</div>
<df-composite-field [compositeField]="compositeField" [form]="form.get('compositeFields').get(''+i)" [path]="path" [pathName]="pathName+'.compositeFields.'+i"></df-composite-field> <df-composite-field [compositeField]="compositeField" [form]="form.get('compositeFields').get(''+i)" [path]="path" [pathName]="pathName+'.compositeFields.'+i"></df-composite-field>
<div *ngFor="let multipleCompositeField of compositeField.multiplicityItems; let j = index;">
<df-composite-field [compositeField]="multipleCompositeField" [form]="form.get('compositeFields').get(''+i).get('multiplicityItems').get(''+j)"
[path]="path" [pathName]="pathName+'.compositeFields.'+i+'.multiplicityItems.'+j"></df-composite-field>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,9 +1,10 @@
import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service'; import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service';
import { FieldGroup } from '../../models/FieldGroup'; import { FieldGroup } from '../../models/FieldGroup';
import { Component, Input, OnInit, ViewEncapsulation } from '@angular/core'; import { Component, Input, OnInit, ViewEncapsulation } from '@angular/core';
import { FormGroup, Validators, FormControl } from '@angular/forms'; import { FormGroup, Validators, FormControl, FormArray } from '@angular/forms';
import { NgForm } from '@angular/forms'; import { NgForm } from '@angular/forms';
import { Rule } from '../../entities/common/rule'; import { Rule } from '../../entities/common/rule';
import { CompositeField } from '../../models/CompositeField';
@ -43,6 +44,12 @@ export class DynamicFormGroupComponent implements OnInit {
} }
addMultipleField(fieldsetIndex: number) {
let compositeField: CompositeField = this.group.compositeFields[fieldsetIndex].cloneForMultiplicity();
this.group.compositeFields[fieldsetIndex].multiplicityItems.push(compositeField);
(<FormArray>(this.form.get("compositeFields").get('' + fieldsetIndex).get('multiplicityItems'))).push(compositeField.buildForm());
}
addFieldSet() { addFieldSet() {
/* debugger; /* debugger;
let subgroup: any = {}; let subgroup: any = {};

View File

@ -17,3 +17,11 @@
.ui-steps .ui-steps-item { .ui-steps .ui-steps-item {
min-width: 10%; min-width: 10%;
} }
ng-sidebar-container {
overflow: inherit !important;
}
/* .ng-sidebar__content {
overflow: inherit !important;
} */

View File

@ -19,8 +19,8 @@
<form *ngIf="form" novalidate [formGroup]="form" (ngSubmit)="onSubmit()"> <form *ngIf="form" novalidate [formGroup]="form" (ngSubmit)="onSubmit()">
<div *ngFor="let section of dataModel.sections; let i = index;"> <div *ngFor="let section of dataModel.sections; let i = index;">
<df-section *ngIf='this.shouldDisplaySection(section)' [section]="section" [form]="form.get('sections').get(''+i)" <df-section *ngIf='this.shouldDisplaySection(section)' [section]="section" [form]="form.get('sections').get(''+i)" [path]="i+1"
[path]="i+1" [pathName]="'sections.'+i"></df-section> [pathName]="'sections.'+i"></df-section>
</div> </div>
</form> </form>
</div> </div>

View File

@ -3,15 +3,23 @@ import { JsonSerializer } from '../utilities/JsonSerializer';
import { Serializable } from './interfaces/Serializable'; import { Serializable } from './interfaces/Serializable';
import { BaseModel } from './BaseModel'; import { BaseModel } from './BaseModel';
import { Field } from './Field' import { Field } from './Field'
import { Multiplicity } from './Multiplicity';
export class CompositeField extends BaseModel implements Serializable<CompositeField> { export class CompositeField extends BaseModel implements Serializable<CompositeField> {
public fields: Array<Field> = new Array<Field>(); public fields: Array<Field> = new Array<Field>();
public ordinal: number public ordinal: number
public id: number public id: number
public multiplicity: Multiplicity;
public multiplicityItems: Array<CompositeField> = new Array<CompositeField>();
fromJSONObject(item: any): CompositeField { fromJSONObject(item: any): CompositeField {
this.fields = new JsonSerializer<Field>().fromJSONArray(item.fields, Field); this.fields = new JsonSerializer<Field>().fromJSONArray(item.fields, Field);
this.ordinal = item.ordinal; this.ordinal = item.ordinal;
this.id = item.id; this.id = item.id;
//this.multiplicity = new JsonSerializer<Multiplicity>().fromJSONObject(item.multiplicity, Multiplicity);
this.multiplicity = new Multiplicity();
this.multiplicity.max = 2;
this.multiplicityItems = new JsonSerializer<CompositeField>().fromJSONArray(item.multiplicityItems, CompositeField);
return this; return this;
} }
@ -26,6 +34,24 @@ export class CompositeField extends BaseModel implements Serializable<CompositeF
fieldsFormArray.push(form) fieldsFormArray.push(form)
}) })
formGroup.addControl('fields', this.formBuilder.array(fieldsFormArray)); formGroup.addControl('fields', this.formBuilder.array(fieldsFormArray));
let multiplicityItemsFormArray = new Array<FormGroup>();
this.multiplicityItems.forEach(item => {
let form: FormGroup = item.buildForm();
multiplicityItemsFormArray.push(form)
})
formGroup.addControl('multiplicityItems', this.formBuilder.array(multiplicityItemsFormArray));
return formGroup; return formGroup;
} }
cloneForMultiplicity(): CompositeField {
let newItem: CompositeField = new CompositeField();
this.fields.forEach(field => {
newItem.fields.push(field.cloneForMultiplicity());
});
newItem.ordinal = this.ordinal;
return newItem;
}
} }

View File

@ -3,6 +3,7 @@ import { FormGroup } from '@angular/forms';
import { FormGenerator } from './interfaces/FormGenerator'; import { FormGenerator } from './interfaces/FormGenerator';
import { JsonSerializer } from '../utilities/JsonSerializer'; import { JsonSerializer } from '../utilities/JsonSerializer';
import { Serializable } from './interfaces/Serializable'; import { Serializable } from './interfaces/Serializable';
import { Multiplicity } from './Multiplicity';
export class Field extends BaseModel implements Serializable<Field>, FormGenerator<FormGroup>{ export class Field extends BaseModel implements Serializable<Field>, FormGenerator<FormGroup>{
public id: string; public id: string;
@ -13,6 +14,7 @@ export class Field extends BaseModel implements Serializable<Field>,FormGenerato
public viewStyle: string; public viewStyle: string;
public defaultVisibility: boolean; public defaultVisibility: boolean;
public page: number; public page: number;
public multiplicity: Multiplicity;
public data: any; public data: any;
fromJSONObject(item: any): Field { fromJSONObject(item: any): Field {
this.id = item.id; this.id = item.id;
@ -23,6 +25,7 @@ export class Field extends BaseModel implements Serializable<Field>,FormGenerato
this.viewStyle = item.viewStyle; this.viewStyle = item.viewStyle;
this.defaultVisibility = item.defaultVisibility; this.defaultVisibility = item.defaultVisibility;
this.page = item.page; this.page = item.page;
this.multiplicity = new JsonSerializer<Multiplicity>().fromJSONObject(item.multiplicity, Multiplicity);
this.data = item.data; this.data = item.data;
return this; return this;
} }
@ -41,4 +44,20 @@ export class Field extends BaseModel implements Serializable<Field>,FormGenerato
}); });
return formGroup; return formGroup;
} }
cloneForMultiplicity(): Field {
let newItem: Field = new Field();
newItem.id = this.id;
newItem.title = this.title;
newItem.description = this.description;
newItem.extendedDescription = this.extendedDescription;
newItem.viewStyle = this.viewStyle;
newItem.defaultVisibility = this.defaultVisibility;
newItem.page = this.page;
newItem.multiplicity = null;
newItem.data = this.data;
return newItem;
}
} }

View File

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

View File

@ -2,7 +2,7 @@ import { Serializable } from '../models/interfaces/Serializable';
export class JsonSerializer<T extends Serializable<T>>{ export class JsonSerializer<T extends Serializable<T>>{
public fromJSONArray(items: any[], type: { new(): T; }): T[] { public fromJSONArray(items: any[], type: { new(): T; }): T[] {
if(!items)return null; if(!items)return new Array<T>();
const objectList: T[] = new Array<T>(); const objectList: T[] = new Array<T>();
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {
objectList.push(new type().fromJSONObject(items[i])) objectList.push(new type().fromJSONObject(items[i]))

View File

@ -15,7 +15,8 @@
<!-- <!--
<script src="https://apis.google.com/js/platform.js" ></script> <script src="https://apis.google.com/js/platform.js" ></script>
--> -->
<link rel="stylesheet" href="https://cdn.rawgit.com/afeld/bootstrap-toc/v0.4.1/dist/bootstrap-toc.min.css"><!--bootstrap plugin for ToC--> <link rel="stylesheet" href="https://cdn.rawgit.com/afeld/bootstrap-toc/v0.4.1/dist/bootstrap-toc.min.css">
<!--bootstrap plugin for ToC-->
<script src="https://cdn.rawgit.com/afeld/bootstrap-toc/v0.4.1/dist/bootstrap-toc.min.js"></script> <script src="https://cdn.rawgit.com/afeld/bootstrap-toc/v0.4.1/dist/bootstrap-toc.min.js"></script>
@ -50,7 +51,9 @@
</head> </head>
<body> <body>
<app-root class="full-height full-width"></app-root> <app-root ></app-root>
</body> </body>
</html> </html>