Skip to content

Commit 70e6a5d

Browse files
committed
fixed get/set value issues and exported parseXmlPromise function
1 parent 75a6bef commit 70e6a5d

File tree

7 files changed

+34
-37
lines changed

7 files changed

+34
-37
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-dynamic-components",
3-
"version": "0.2.3",
3+
"version": "0.2.5",
44
"description": "NGX Dynamic Components is a configuration based dynamic components library for Angular. That allows you to rapidly create dynamic forms or any other mobile-friendly web layouts.",
55
"author": "FalconSoft Ltd",
66
"repository": {

projects/bootstrap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ngx-dynamic-components/bootstrap",
3-
"version": "0.2.3",
3+
"version": "0.2.5",
44
"private": false,
55
"description": "@ngx-dynamic-components/bootstrap is Angular 7+ library what contains a bootstrap interfaces to build a configuration driven web pages and workflows.",
66
"author": "FalconSoft Ltd <[email protected]>",

projects/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ngx-dynamic-components/core",
3-
"version": "0.2.3",
3+
"version": "0.2.5",
44
"private": false,
55
"description": "@ngx-dynamic-components/core is Angular 7+ library what contains a core interfaces to build a configuration driven web pages and workflows.",
66
"author": "FalconSoft Ltd <[email protected]>",

projects/core/src/lib/services/core.service.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Injectable } from '@angular/core';
22
import { ComponentDescriptor, UIModel, AttributesMap, XMLResult } from '../models';
3-
import { BaseUIComponentConstructor, toXMLResult, BaseHTMLElementConstructor } from '../utils';
3+
import { BaseUIComponentConstructor, toXMLResult, BaseHTMLElementConstructor, parseXmlStringPromise } from '../utils';
44
import { ControlProperties, UIModelProperty } from '../properties';
5-
import * as iXml from 'isomorphic-xml2js';
65

76
/**
87
* Child Elements directives within Containers
@@ -57,32 +56,8 @@ export class CoreService {
5756
}
5857

5958
public static async parseXMLModel(uiModelXml: string): Promise<UIModel> {
60-
61-
function parseStringPromise(xmlString: string): Promise<any> {
62-
return new Promise((s, e) => {
63-
const ops = {
64-
explicitChildren: true,
65-
preserveChildrenOrder: true
66-
};
67-
68-
iXml.parseString(xmlString, ops, (err, res) => {
69-
if (res) {
70-
// need to clone result as it would mutate instance
71-
return s(JSON.parse(JSON.stringify(res)));
72-
}
73-
if (err) {
74-
// quite dirty way to get meaningful error message
75-
let msg = err.message.substring(err.message.indexOf('12px">') + 6);
76-
msg = msg.substring(0, msg.indexOf('</div>'));
77-
return e(msg);
78-
}
79-
return null;
80-
});
81-
});
82-
}
83-
8459
try {
85-
const res = await parseStringPromise(uiModelXml);
60+
const res = await parseXmlStringPromise(uiModelXml);
8661

8762
if (res) {
8863
const type = Object.keys(res)[0];

projects/core/src/lib/utils/index.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { BaseUIComponent } from '../components/base-ui-component';
22
import { BaseHTMLElement } from '../components/base-html-element';
33
import { BaseDynamicComponent } from '../components/base-dynamic-component';
44
import { UIModel } from '../models';
5+
import * as iXml from 'isomorphic-xml2js';
56

67
export * from './helpers';
78
export type BaseUIComponentConstructor = new () => BaseUIComponent;
@@ -57,11 +58,10 @@ export function setValue(objectValue: object, path: string, value: any): void {
5758
let res: any = objectValue;
5859

5960
for (let i = 0; i < props.length - 1; i++) {
60-
res = objectValue[props[i]];
61-
if (typeof res !== 'object') {
62-
objectValue[props[i]] = {};
63-
res = objectValue[props[i]];
61+
if (typeof res[props[i]] !== 'object') {
62+
res[props[i]] = {};
6463
}
64+
res = res[props[i]];
6565
}
6666

6767
res[props[props.length - 1]] = value;
@@ -83,11 +83,34 @@ export function queryValue(obj: any, path: string, defaultValue: any = null): an
8383

8484
let res = obj;
8585
for (const p of props) {
86-
res = obj[p];
86+
res = res[p];
8787
if (!res && res !== 0) {
8888
return res || defaultValue;
8989
}
9090
}
9191

9292
return res;
93+
}
94+
95+
export function parseXmlStringPromise(xmlString: string): Promise<any> {
96+
return new Promise((s, e) => {
97+
const ops = {
98+
explicitChildren: true,
99+
preserveChildrenOrder: true
100+
};
101+
102+
iXml.parseString(xmlString, ops, (err, res) => {
103+
if (res) {
104+
// need to clone result as it would mutate instance
105+
return s(JSON.parse(JSON.stringify(res)));
106+
}
107+
if (err) {
108+
// quite dirty way to get meaningful error message
109+
let msg = err.message.substring(err.message.indexOf('12px">') + 6);
110+
msg = msg.substring(0, msg.indexOf('</div>'));
111+
return e(msg);
112+
}
113+
return null;
114+
});
115+
});
93116
}

projects/tools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ngx-dynamic-components/tools",
3-
"version": "0.2.3",
3+
"version": "0.2.5",
44
"private": false,
55
"description": "@ngx-dynamic-components/tools is Angular 7+ library what contains a core interfaces to build a configuration driven web pages.",
66
"author": "FalconSoft Ltd <[email protected]>",

projects/tools/src/lib/components/preview-editor/preview-editor.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { map } from 'rxjs/operators';
77
import { Observable, fromEvent } from 'rxjs';
88
import { Ace, edit } from 'ace-builds';
99
import { jsPython, Interpreter } from 'jspython-interpreter';
10-
import { JSONUtils } from '@ngx-dynamic-components/core/public_api';
1110

1211
enum Layout {
1312
horizontal = 'horizontal',

0 commit comments

Comments
 (0)