autocomplete field in describe form. label field
This commit is contained in:
parent
83007b7166
commit
264977c72e
|
@ -13,5 +13,5 @@ export class Attribute {
|
||||||
validationType: any;
|
validationType: any;
|
||||||
validation : Rule[];
|
validation : Rule[];
|
||||||
sources: Source[];
|
sources: Source[];
|
||||||
|
url: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,9 +36,14 @@
|
||||||
[required]="field.required" [pattern] = "field.regex" (ngModelChange) = "toggleVisibility($event, field,false)"> <!--input or change event
|
[required]="field.required" [pattern] = "field.regex" (ngModelChange) = "toggleVisibility($event, field,false)"> <!--input or change event
|
||||||
on change event the listener is triggered on blur -->
|
on change event the listener is triggered on blur -->
|
||||||
|
|
||||||
<select *ngSwitchCase="'dropdown'" class="form-control" [id]="field.key" [formControlName]="field.key" [required]="field.required" (change)="toggleVisibility($event, field, false)">
|
<div *ngSwitchCase="'dropdown'">
|
||||||
|
{{field.url}}
|
||||||
|
<autocomplete-remote *ngIf="field.url" [form]="form" [formCtrlName]="field.key" [label]="'Please select a datarepo'" [url]="field.url" ></autocomplete-remote>
|
||||||
|
<select *ngIf="!field.url" class="form-control" [id]="field.key" [formControlName]="field.key" [required]="field.required" (change)="toggleVisibility($event, field, false)">
|
||||||
<option *ngFor="let opt of field.options" [value]="opt.key" >{{opt.value}}</option>
|
<option *ngFor="let opt of field.options" [value]="opt.key" >{{opt.value}}</option>
|
||||||
</select>
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div *ngSwitchCase="'checkbox'" class="checkbox">
|
<div *ngSwitchCase="'checkbox'" class="checkbox">
|
||||||
<label class="checkBoxLabelCustom">
|
<label class="checkBoxLabelCustom">
|
||||||
|
@ -62,6 +67,9 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div *ngSwitchCase="'label'"> </div>
|
||||||
|
|
||||||
|
|
||||||
<div [hidden]="isValid">
|
<div [hidden]="isValid">
|
||||||
<div class="invalid-feedbackCustom" *ngIf="isValidRequired">The field "{{field.label}}" is required</div>
|
<div class="invalid-feedbackCustom" *ngIf="isValidRequired">The field "{{field.label}}" is required</div>
|
||||||
<div class="invalid-feedbackCustom" *ngIf="isValidPattern">The field {{field.label}} must match a regular expression {{field.regex}}</div>
|
<div class="invalid-feedbackCustom" *ngIf="isValidPattern">The field {{field.label}} must match a regular expression {{field.regex}}</div>
|
||||||
|
|
|
@ -14,7 +14,7 @@ export class FieldBase<T>{
|
||||||
description:string;
|
description:string;
|
||||||
attributes: Attribute;
|
attributes: Attribute;
|
||||||
regex:string;
|
regex:string;
|
||||||
url: any;
|
url: string;
|
||||||
|
|
||||||
constructor(options: {
|
constructor(options: {
|
||||||
value?: T,
|
value?: T,
|
||||||
|
@ -29,7 +29,7 @@ export class FieldBase<T>{
|
||||||
description?: string,
|
description?: string,
|
||||||
attributes?: Attribute,
|
attributes?: Attribute,
|
||||||
regex?:string,
|
regex?:string,
|
||||||
url?: any
|
url?: string
|
||||||
} = {}) {
|
} = {}) {
|
||||||
this.value = options.value;
|
this.value = options.value;
|
||||||
this.key = options.key || '';
|
this.key = options.key || '';
|
||||||
|
@ -43,6 +43,6 @@ export class FieldBase<T>{
|
||||||
this.description = options.description || '';
|
this.description = options.description || '';
|
||||||
this.attributes = options.attributes || new Attribute();
|
this.attributes = options.attributes || new Attribute();
|
||||||
this.regex = options.regex || '';
|
this.regex = options.regex || '';
|
||||||
this.url = options.url || {"url":null, "fieldpath":null, "data":null};
|
this.url = options.url || "";
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
import {FieldBase} from '../field-base';
|
||||||
|
|
||||||
|
export class LabelField extends FieldBase<string> {
|
||||||
|
controlType = 'label';
|
||||||
|
type: string;
|
||||||
|
|
||||||
|
constructor (options: {} = {}) {
|
||||||
|
super(options);
|
||||||
|
this.type = options['type'] || '';
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import { TextboxField } from '../../app/form/fields/textbox/field-textbox';
|
||||||
import { CheckBoxField } from '../../app/form/fields/checkbox/field-checkbox';
|
import { CheckBoxField } from '../../app/form/fields/checkbox/field-checkbox';
|
||||||
import { RadioBoxField } from '../../app/form/fields/radiobox/field-radiobox';
|
import { RadioBoxField } from '../../app/form/fields/radiobox/field-radiobox';
|
||||||
import { TextAreaField } from '../../app/form/fields/textarea/textarea';
|
import { TextAreaField } from '../../app/form/fields/textarea/textarea';
|
||||||
|
import { LabelField } from '../../app/form/fields/label/label';
|
||||||
import { DataModel } from '../entities/DataModel';
|
import { DataModel } from '../entities/DataModel';
|
||||||
import { Rule } from '../entities/common/rule';
|
import { Rule } from '../entities/common/rule';
|
||||||
import { GroupBase } from '../form/dynamic-form-group/group-base';
|
import { GroupBase } from '../form/dynamic-form-group/group-base';
|
||||||
|
@ -29,6 +30,7 @@ export class dataModelBuilder {
|
||||||
this.dataModel = new DataModel();
|
this.dataModel = new DataModel();
|
||||||
this.fields = this.buildFields(data.viewstyle.definition.root.fields.field);
|
this.fields = this.buildFields(data.viewstyle.definition.root.fields.field);
|
||||||
this.dataModel.groups = this.getGroups(data.viewstyle.definition.root.fieldGroups.fieldGroup, this.fields, dataValues);
|
this.dataModel.groups = this.getGroups(data.viewstyle.definition.root.fieldGroups.fieldGroup, this.fields, dataValues);
|
||||||
|
this.checkDuplicateInObject('order', this.dataModel.groups[13].groupFields);
|
||||||
this.dataModel.semanticAttr = new Array(new Attribute);
|
this.dataModel.semanticAttr = new Array(new Attribute);
|
||||||
//this.dataModel.semanticAttr = data.dataset.profile.definition.root.fields.field;
|
//this.dataModel.semanticAttr = data.dataset.profile.definition.root.fields.field;
|
||||||
this.dataModel.semanticAttr = this.getFieldsAttributes(data.definition.root.fields.field, data.ruleset.definition.root.functions.function, this.fields);
|
this.dataModel.semanticAttr = this.getFieldsAttributes(data.definition.root.fields.field, data.ruleset.definition.root.functions.function, this.fields);
|
||||||
|
@ -131,6 +133,23 @@ export class dataModelBuilder {
|
||||||
|
|
||||||
fieldsVisible.push(newfield);
|
fieldsVisible.push(newfield);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (element.viewStyle._renderstyle == "label") {
|
||||||
|
let newfield: FieldBase<any>;
|
||||||
|
let rule = new Rule();
|
||||||
|
newfield = new LabelField({
|
||||||
|
label: element.title.__cdata,
|
||||||
|
key: element._id,
|
||||||
|
value: element.value,
|
||||||
|
order: element._ordinal,
|
||||||
|
rules: element.visible.rule != undefined ? element.visible.rule : rule,
|
||||||
|
visible: element._defaultVisibility,
|
||||||
|
group: element._group,
|
||||||
|
description: element.description.__cdata
|
||||||
|
});
|
||||||
|
|
||||||
|
fieldsVisible.push(newfield);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
fieldsVisible.sort((a, b) => a.order - b.order);
|
fieldsVisible.sort((a, b) => a.order - b.order);
|
||||||
return fieldsVisible;
|
return fieldsVisible;
|
||||||
|
@ -200,21 +219,8 @@ export class dataModelBuilder {
|
||||||
newAttribute.sources.push(attr.sources.source);
|
newAttribute.sources.push(attr.sources.source);
|
||||||
if (attr.sources.source.length != undefined) {
|
if (attr.sources.source.length != undefined) {
|
||||||
for (var i = 0; i < attr.sources.source.length; i++) {
|
for (var i = 0; i < attr.sources.source.length; i++) {
|
||||||
if (attr.sources.source[i].url !== undefined) {
|
if (attr.sources.source[i]._type == "url") {
|
||||||
fields.find(x => x.key == newAttribute.id).url.url = attr.sources.source[i].url._value;
|
newAttribute.url = attr.sources.source[i].value._value;
|
||||||
this.restBase.proxy_get(attr.sources.source[i].url._value).subscribe((data) => {
|
|
||||||
console.log(data);
|
|
||||||
newAttribute.sources.forEach(src => {
|
|
||||||
src.params = new Array();
|
|
||||||
data.data.forEach(data => {
|
|
||||||
let prm = new Param();
|
|
||||||
prm.key = data.id;
|
|
||||||
prm.value = data.attributes.name;
|
|
||||||
src.params.push(prm);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
newAttribute.sources.forEach(src => {
|
newAttribute.sources.forEach(src => {
|
||||||
|
@ -233,21 +239,8 @@ export class dataModelBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attr.sources.source.url !== undefined) {
|
if (attr.sources.source._type == "url") {
|
||||||
fields.find(x => x.key == newAttribute.id).url.url = attr.sources.source.url._value;
|
newAttribute.url = attr.sources.source.value._value;
|
||||||
this.restBase.proxy_get(attr.sources.source.url._value).subscribe((data) => {
|
|
||||||
console.log(data);
|
|
||||||
newAttribute.sources.forEach(src => {
|
|
||||||
src.params = new Array();
|
|
||||||
data.data.forEach(data => {
|
|
||||||
let prm = new Param();
|
|
||||||
prm.key = data.id;
|
|
||||||
prm.value = data.attributes.name;
|
|
||||||
src.params.push(prm);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
newAttribute.sources.forEach(src => {
|
newAttribute.sources.forEach(src => {
|
||||||
|
|
||||||
|
@ -301,7 +294,8 @@ export class dataModelBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
attribute.push(newAttribute);
|
attribute.push(newAttribute);
|
||||||
//if (fields.find(x => x.key == newAttribute.id).url.url == null)
|
if (newAttribute.url !== undefined)
|
||||||
|
fields.find(x => x.key == newAttribute.id).url = newAttribute.url;
|
||||||
fields.find(x => x.key == newAttribute.id).attributes.sources = newAttribute.sources;
|
fields.find(x => x.key == newAttribute.id).attributes.sources = newAttribute.sources;
|
||||||
fields.find(x => x.key == newAttribute.id).attributes.validation = newAttribute.validation;
|
fields.find(x => x.key == newAttribute.id).attributes.validation = newAttribute.validation;
|
||||||
});
|
});
|
||||||
|
@ -341,4 +335,18 @@ export class dataModelBuilder {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkDuplicateInObject(propertyName, inputArray) {
|
||||||
|
let DuplicateArray = [];
|
||||||
|
inputArray.forEach(item => {
|
||||||
|
for(var i=0; i<inputArray.length; i++){
|
||||||
|
if(item[propertyName] == inputArray[i][propertyName] && item['key'] != inputArray[i]['key']){
|
||||||
|
DuplicateArray.push(inputArray[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log(DuplicateArray);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue