Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting json prop #496

Merged
merged 5 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions www/js/vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -2702,6 +2702,18 @@ var vis = {
case 'ceil':
value = Math.ceil(parseFloat(value));
break;
case 'json':
if (value && typeof value === 'string') {
try {
value = JSON.parse(value);
} catch (e) {
console.warn('Cannot parse JSON string: ' + value);
}
}
if (value && typeof value === 'object') {
value = getObjPropValue(value, oids[t].operations[k].arg);
}
break;
} //switch
}
} //if for
Expand Down
26 changes: 23 additions & 3 deletions www/js/visUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@
return null;
}

// get valeue of Obj property PropPath. PropPath is string like "Prop1" or "Prop1.Prop2" ...
function getObjPropValue(obj, propPath) {

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused function getObjPropValue.
if (!obj) {
return undefined;
}
const parts = propPath.split('.');
for (const part of parts) {
obj = obj[part];
if (!obj) {
return undefined;
}
}
return obj;
}

function extractBinding(format) {
var oid = format.match(/{(.+?)}/g);
var result = null;
Expand Down Expand Up @@ -213,9 +228,14 @@
operations.push({op: parse[1], arg: parse[2]});
}
}
} else
// operators without parameter
{
} else if (parse[1] === 'json') {
// json(objPropPath) ex: json(prop1); json(prop1.propA)
operations = operations || [];
parse[2] = (parse[2] || '').trim();
parse[2] = parse[2].substring(1, parse[2].length - 1);
operations.push({op: parse[1], arg: parse[2]});
} else {
// operators without parameter
operations = operations || [];
operations.push({op: parse[1]});
}
Expand Down
Loading