radio button, index code in model
This commit is contained in:
parent
8ed421ccfc
commit
abd360f2c8
|
@ -3,17 +3,49 @@ import { FieldBase } from '../form/fields/field-base';
|
|||
import { Attribute } from './model/attribute';
|
||||
|
||||
export class DataModel {
|
||||
|
||||
groups: GroupBase<any>[] = [];
|
||||
fields: FieldBase<any>[] = [];
|
||||
semanticAttr: Attribute[];
|
||||
|
||||
//need to add more class fields to describe the remaining elements of the json object fetched from the service.
|
||||
//e.g. the current dataset's metadata information, the DataRepository description information, etc
|
||||
|
||||
|
||||
constructor(){
|
||||
}
|
||||
|
||||
|
||||
|
||||
private fIndex : Map<string, FieldBase<any>>;
|
||||
|
||||
groups: GroupBase<any>[] = [];
|
||||
fields: FieldBase<any>[] = [];
|
||||
semanticAttr: Attribute[];
|
||||
|
||||
//need to add more class fields to describe the remaining elements of the json object fetched from the service.
|
||||
//e.g. the current dataset's metadata information, the DataRepository description information, etc
|
||||
|
||||
constructor(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public buildIndex(){
|
||||
|
||||
|
||||
this.fIndex = new Map<string, FieldBase<any>>();
|
||||
|
||||
this.fields.forEach((field) => {
|
||||
console.log("fieldid:" +field.key);
|
||||
this.fIndex.set(field.key, field);
|
||||
});
|
||||
|
||||
this.groups.forEach((group) => {
|
||||
group.groupFields.forEach((field) => {
|
||||
console.log("groupid: "+group.key + "fieldid:" +field.key);
|
||||
this.fIndex.set(field.key, field);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public getFieldByKey(key){
|
||||
return this.fIndex.get(key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,22 @@
|
|||
|
||||
<input *ngSwitchCase="'checkbox'" [formControlName]="field.key" [(ngModel)]="field.value" [id]="field.key" [type]="field.type"
|
||||
(change)="toggleVisibility($event, field)" #ckb> <!--(change)="field.value = ckb.checked"-->
|
||||
|
||||
|
||||
|
||||
<div *ngSwitchCase="'radiobox'">
|
||||
<ng-container *ngFor="let answrBase of field.answers">
|
||||
<div style="display: inline-block;margin-right:10px;">
|
||||
<label for="{{answrBase.id}}" style="padding: 8px 10px; padding-right:5px;">{{answrBase.answer}}</label>
|
||||
<input type="radio" [formControlName]="field.key"
|
||||
[id] = "answrBase.id"
|
||||
[value]= "answrBase"/>
|
||||
</div>
|
||||
</ng-container>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -3,6 +3,8 @@ import { Component, Input } from '@angular/core';
|
|||
import { FormGroup } from '@angular/forms';
|
||||
|
||||
import { FieldBase } from './field-base';
|
||||
import { GroupBase } from '../../form/dynamic-form-group/group-base';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'df-field',
|
||||
|
@ -43,9 +45,20 @@ export class DynamicFormFieldComponent {
|
|||
return false;
|
||||
}
|
||||
|
||||
toggleVisibility(e, field){
|
||||
console.log(this.dataModel.groups.find(x => x.order === field.group));
|
||||
console.log(this.dataModel);
|
||||
toggleVisibility(e, field){
|
||||
// let group:GroupBase<any>;
|
||||
// group = this.dataModel.groups.find(x => x.key === field.group);
|
||||
// group.groupFields.forEach(element => {debugger;
|
||||
// if (element.order == (field.order + 1)){
|
||||
// element.rules.forEach(element => {
|
||||
// if (element.target == field.id){
|
||||
// console.log (element);
|
||||
// }
|
||||
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// console.log(this.dataModel);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
@CHARSET "UTF-8";
|
|
@ -0,0 +1 @@
|
|||
<input [formControlName]="field.key" [(ngModel)]="field.value" [type]="field.type" >
|
|
@ -0,0 +1,13 @@
|
|||
import {FieldBase} from '../field-base';
|
||||
|
||||
export class RadioBoxField extends FieldBase<boolean>{
|
||||
controlType = 'radiobox';
|
||||
type: "radio";
|
||||
answers: Array<any>;
|
||||
|
||||
constructor(options: {} = {}){
|
||||
super(options);
|
||||
this.type = options['type'] || [];
|
||||
this.answers = options['answers'] || []
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ import { DropdownField } from '../../app/form/fields/dropdown/field-dropdown';
|
|||
import { FieldBase } from '../../app/form/fields/field-base';
|
||||
import { TextboxField } from '../../app/form/fields/textbox/field-textbox';
|
||||
import { CheckBoxField } from '../../app/form/fields/checkbox/field-checkbox';
|
||||
import { RadioBoxField } from '../../app/form/fields/radiobox/field-radiobox';
|
||||
import { DataModel } from '../entities/DataModel';
|
||||
import {Rule} from '../entities/common/rule';
|
||||
import { GroupBase } from '../form/dynamic-form-group/group-base';
|
||||
|
@ -42,19 +43,10 @@ export class dataModelBuilder {
|
|||
value: 'DMP1',
|
||||
required: true,
|
||||
order:element._ordinal,
|
||||
rules: new Array(),
|
||||
rules: element.visible.rule != undefined ? element.visible.rule: rule,
|
||||
visible: element._defaultVisibility,
|
||||
group : element._group
|
||||
});
|
||||
if (element.visible.rule)
|
||||
if(element.visible.rule.length){
|
||||
element.visible.rule.forEach(rule => {
|
||||
newfield.rules.push(rule)
|
||||
});
|
||||
}
|
||||
else {
|
||||
newfield.rules.push(element.visible.rule)
|
||||
}
|
||||
|
||||
fieldsVisible.push(newfield);
|
||||
}
|
||||
|
@ -67,7 +59,7 @@ export class dataModelBuilder {
|
|||
value: 'DMP1',
|
||||
required: true,
|
||||
order:element._ordinal,
|
||||
rule: element.visible.rule,
|
||||
rules: element.visible.rule != undefined ? element.visible.rule: rule,
|
||||
visible: element._defaultVisibility,
|
||||
group : element._group
|
||||
});
|
||||
|
@ -82,13 +74,38 @@ export class dataModelBuilder {
|
|||
value: true,
|
||||
required: true,
|
||||
order:element._ordinal,
|
||||
rule: element.visible.rule != undefined ? element.visible.rule: rule,
|
||||
rules: element.visible.rule != undefined ? element.visible.rule: rule,
|
||||
visible: element._defaultVisibility,
|
||||
group : element._group,
|
||||
type: "checkbox"
|
||||
});
|
||||
fieldsVisible.push(newfield);
|
||||
}
|
||||
}
|
||||
else if (element.viewStyle._renderstyle == "booleanDesicion"){
|
||||
let newfield:RadioBoxField;
|
||||
let rule = new Array<Rule>();
|
||||
newfield = new RadioBoxField({
|
||||
label: element.title.__cdata,
|
||||
key:element._id,
|
||||
value: true,
|
||||
required: true,
|
||||
order:element._ordinal,
|
||||
rules: element.visible.rule != undefined ? element.visible.rule: rule,
|
||||
visible: element._defaultVisibility,
|
||||
group : element._group,
|
||||
type: "radio",
|
||||
answers: [
|
||||
{
|
||||
id: 1,
|
||||
answer: "Yes"
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
answer: "No"
|
||||
}]
|
||||
});
|
||||
fieldsVisible.push(newfield);
|
||||
}
|
||||
});
|
||||
fieldsVisible.sort((a, b) => a.order - b.order);
|
||||
return fieldsVisible;
|
||||
|
@ -98,7 +115,6 @@ export class dataModelBuilder {
|
|||
let groups :GroupBase<any>[] =[];
|
||||
let newfldGroup = new GroupBase();
|
||||
newfldGroup.groupFields = new Array();
|
||||
|
||||
if(fieldGroups.length>1)
|
||||
fieldGroups.forEach(fieldGroup =>{
|
||||
fields.forEach(field => {
|
||||
|
@ -108,6 +124,7 @@ export class dataModelBuilder {
|
|||
this.dataModel.fields.push(field);
|
||||
});
|
||||
newfldGroup.title = fieldGroup.title.__cdata;
|
||||
newfldGroup.key = fldGroup._id;
|
||||
groups.push(newfldGroup)
|
||||
});
|
||||
else{
|
||||
|
@ -118,6 +135,7 @@ export class dataModelBuilder {
|
|||
this.dataModel.fields.push(field);
|
||||
});
|
||||
newfldGroup.title = fldGroup.title.__cdata;
|
||||
newfldGroup.key = fldGroup._id;
|
||||
groups.push(newfldGroup)
|
||||
}
|
||||
return groups;
|
||||
|
|
|
@ -19,7 +19,7 @@ export class ServerService {
|
|||
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/a71a6a92-5c23-40d7-ab87-e30bc860f5a4';//include rules!
|
||||
fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/ccae5e6b-61e5-42b2-ac46-b720770c8148';//include sections!
|
||||
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/6c845c42-dc09-42ed-9959-cceb3b616364';
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue