From b8128bdbfa4016fe1a4b4c0990568ec61da8354d Mon Sep 17 00:00:00 2001 From: danloa Date: Tue, 17 Sep 2024 13:59:20 -0400 Subject: [PATCH] Support {{data.xyz}} and {{xyz}} in PMQL mustach syntax --- src/components/FormSelectList.vue | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/FormSelectList.vue b/src/components/FormSelectList.vue index 8584ab0..3c63df6 100644 --- a/src/components/FormSelectList.vue +++ b/src/components/FormSelectList.vue @@ -241,10 +241,18 @@ export default { isMultiSelectDisabled() { return this.options.allowMultiSelect === false; }, + hasNestedProperty(obj, path) { + return path.split(".").reduce((acc, part) => acc && acc[part], obj); + }, renderPmql(pmql) { if (typeof pmql !== "undefined" && pmql !== "" && pmql !== null) { const data = this.makeProxyData(); - return Mustache.render(pmql, data); + const preprocessedTemplate = pmql.replace(/{{\s*([\w.]+)\s*}}/g, (match, key) => { + return this.hasNestedProperty(data, key) ? match : `[[[${key}]]]`; + }); + const output = Mustache.render(preprocessedTemplate, data); + const last = Mustache.render(output.replace("[[[", "{{").replace("]]]", "}}"), { data }); + return last; } return ""; },