3 fieldgroups, description, modelbuilder fixes

This commit is contained in:
annampak 2017-09-19 18:24:31 +03:00
parent 5c66c65bdf
commit d6a4ba6fec
5 changed files with 41 additions and 33 deletions

View File

@ -30,7 +30,8 @@
<div [ngClass]="{true:'show', false:'hide'}[field.visible]"> <div [ngClass]="{true:'show', false:'hide'}[field.visible]">
<label [attr.for]="field.key">{{field.label}}</label> <label [attr.for]="field.key">{{field.label}}</label>
<div>{{field.description}}</div>
<input *ngSwitchCase="'textbox'" class="form-control" [formControlName]="field.key" [id]="field.key" [type]="field.type" <input *ngSwitchCase="'textbox'" class="form-control" [formControlName]="field.key" [id]="field.key" [type]="field.type"
required="field.required" [(ngModel)]="field.value"> required="field.required" [(ngModel)]="field.value">
@ -41,7 +42,7 @@
<input *ngSwitchCase="'checkbox'" class="form-check" [formControlName]="field.key" [(ngModel)]="field.value" [id]="field.key" [type]="field.type" <input *ngSwitchCase="'checkbox'" class="form-check" [formControlName]="field.key" [(ngModel)]="field.value" [id]="field.key" [type]="field.type"
(change)="toggleVisibility($event, field, ckb)" #ckb> <!--(change)="field.value = ckb.checked"--> (change)="toggleVisibility($event, field, ckb)" #ckb> <!--(change)="field.value = ckb.checked"-->
<div *ngSwitchCase="'radiobox'"> <div *ngSwitchCase="'radiobox'">
<ng-container *ngFor="let answrBase of field.answers"> <ng-container *ngFor="let answrBase of field.answers">
@ -50,11 +51,9 @@
<input type="radio" [formControlName]="field.key" [id]= "answrBase.id" [value]= "answrBase" [(ngModel)]="field.value" (change) = "toggleVisibility($event, field)"/> <input type="radio" [formControlName]="field.key" [id]= "answrBase.id" [value]= "answrBase" [(ngModel)]="field.value" (change) = "toggleVisibility($event, field)"/>
</div> </div>
</ng-container> </ng-container>
</div> </div>
</div> </div>
</div> </div>

View File

@ -58,8 +58,7 @@ export class DynamicFormFieldComponent {
} }
} }
toggleVisibility(e, field, ckb){ toggleVisibility(e, field, ckb){ //ckb the checkbox only send this parameter, it's essential to change the field value
console.log(field);debugger;
if(ckb) if(ckb)
field.value = ckb.checked; field.value = ckb.checked;
field.rules.forEach(rule => { field.rules.forEach(rule => {

View File

@ -9,6 +9,7 @@ export class FieldBase<T>{
visible: boolean; visible: boolean;
controlType:string; controlType:string;
group:string; group:string;
description:string;
constructor(options: { constructor(options: {
value?: T, value?: T,
@ -20,6 +21,7 @@ export class FieldBase<T>{
visible?: boolean, visible?: boolean,
controlType?: string controlType?: string
group?: string group?: string
description?: string,
} = {}) { } = {}) {
this.value = options.value; this.value = options.value;
this.key = options.key || ''; this.key = options.key || '';
@ -30,5 +32,6 @@ export class FieldBase<T>{
this.visible = options.visible; this.visible = options.visible;
this.controlType = options.controlType || ''; this.controlType = options.controlType || '';
this.group = options.group || ''; this.group = options.group || '';
this.description = options.description || '';
} }
} }

View File

@ -19,11 +19,10 @@ export class dataModelBuilder {
if(this.dataModel != null) if(this.dataModel != null)
return this.dataModel; return this.dataModel;
let fldGroup = data.dataset.profile.viewstyle.definition.root.fieldGroups.fieldGroup;//one fieldgroup
this.dataModel = new DataModel(); this.dataModel = new DataModel();
//this.dataModel.fields = this.getFieldVisibility(data.dataset.profile.viewstyle.definition.root.fields.field); //this.dataModel.fields = this.getFieldVisibility(data.dataset.profile.viewstyle.definition.root.fields.field);
this.fields = this.buildFields(data.dataset.profile.viewstyle.definition.root.fields.field); this.fields = this.buildFields(data.dataset.profile.viewstyle.definition.root.fields.field);
this.dataModel.groups = this.getGroups(data.dataset.profile.viewstyle.definition.root.fieldGroups.fieldGroup, fldGroup, this.fields); this.dataModel.groups = this.getGroups(data.dataset.profile.viewstyle.definition.root.fieldGroups.fieldGroup, this.fields);
//this.getDummyGroups(); //this.getDummyGroups();
this.dataModel.buildIndex(); this.dataModel.buildIndex();
@ -41,7 +40,7 @@ export class dataModelBuilder {
newfield = new TextboxField({ newfield = new TextboxField({
label: element.title.__cdata, label: element.title.__cdata,
key:element._id, key:element._id,
value: 'DMP1', value: element.value,
required: true, required: true,
order:element._ordinal, order:element._ordinal,
rules: element.visible.rule != undefined ? element.visible.rule: rule, rules: element.visible.rule != undefined ? element.visible.rule: rule,
@ -57,7 +56,7 @@ export class dataModelBuilder {
newfield = new DropdownField({ newfield = new DropdownField({
label: element.title.__cdata, label: element.title.__cdata,
key:element._id, key:element._id,
value: 'DMP1', value: element.value,
required: true, required: true,
order:element._ordinal, order:element._ordinal,
rules: element.visible.rule != undefined ? element.visible.rule: rule, rules: element.visible.rule != undefined ? element.visible.rule: rule,
@ -95,6 +94,7 @@ export class dataModelBuilder {
visible: element._defaultVisibility, visible: element._defaultVisibility,
group : element._group, group : element._group,
type: "radio", type: "radio",
description: element.description.__cdata,
answers: [ answers: [
{ {
id: 1, id: 1,
@ -114,31 +114,38 @@ export class dataModelBuilder {
return fieldsVisible; return fieldsVisible;
} }
private getGroups(fieldGroups:any[], fldGroup, fields:any[]){ private getGroups(fieldGroups:any, fields:any[]){
let groups :GroupBase<any>[] =[]; let groups :GroupBase<any>[] =[];
let newfldGroup = new GroupBase();
newfldGroup.groupFields = new Array(); if(fieldGroups.length>1){
if(fieldGroups.length>1) fieldGroups.forEach(fieldGroup =>{ // each fiedgroup fills with its fields from json
fieldGroups.forEach(fieldGroup =>{ let newfldGroup = new GroupBase();
fields.forEach(field => { newfldGroup.groupFields = new Array();
if(fieldGroup._id == field.group){ fields.forEach(field => {
newfldGroup.groupFields.push(field); if(fieldGroup._id == field.group){
}else newfldGroup.groupFields.push(field);
this.dataModel.fields.push(field); }else{
}); //this.dataModel.fields.push(field);
newfldGroup.title = fieldGroup.title.__cdata; }
newfldGroup.key = fldGroup._id;
groups.push(newfldGroup) });
}); newfldGroup.title = fieldGroup.title.__cdata;
newfldGroup.key = fieldGroup._id;
groups.push(newfldGroup)
});
}
else{ else{
fields.forEach(field => { let newfldGroup = new GroupBase();
if(fldGroup._id == field.group){ newfldGroup.groupFields = new Array();
fields.forEach(field => { //for one fieldgroup, beacouse xml to json transformation doesn't create array of one fieldfroup
if(fieldGroups._id == field.group){
newfldGroup.groupFields.push(field); newfldGroup.groupFields.push(field);
}else }else
this.dataModel.fields.push(field); this.dataModel.fields.push(field);
}); });
newfldGroup.title = fldGroup.title.__cdata; newfldGroup.title = fieldGroups.title.__cdata;
newfldGroup.key = fldGroup._id; newfldGroup.key = fieldGroups._id;
groups.push(newfldGroup) groups.push(newfldGroup)
} }
return groups; return groups;

View File

@ -19,7 +19,7 @@ export class ServerService {
xml2jsonOBJ: any; xml2jsonOBJ: any;
//fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/a868dbbb-ee37-4ce6-81c8-27048e0599a9'; //fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/a868dbbb-ee37-4ce6-81c8-27048e0599a9';
//fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/a71a6a92-5c23-40d7-ab87-e30bc860f5a4';//include rules! //fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/a71a6a92-5c23-40d7-ab87-e30bc860f5a4';//include rules!
fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/d619d418-88be-4f2c-9dcc-db7ad4fc60b3';//include sections! fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/d597c26e-3d8b-416a-bc07-1734d68c79c9';//'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/d619d418-88be-4f2c-9dcc-db7ad4fc60b3';//include sections!
//fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/6c845c42-dc09-42ed-9959-cceb3b616364'; //fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/6c845c42-dc09-42ed-9959-cceb3b616364';
/* /*