From 39a908d51f07936140ff6484dcbd670e4340b672 Mon Sep 17 00:00:00 2001 From: Kyle Watson Date: Mon, 31 Aug 2020 10:57:39 -0700 Subject: [PATCH] #156 updated loadfunction code and fixed dialog names and error logging --- .../themecleanflex/models/DatalistModel.java | 8 +++--- fragments/datalist/model.json | 2 +- fragments/datalist/template.vue | 28 +++++++++++++++++-- .../components/datalist/dialog.json | 4 +-- .../components/datalist/template.vue | 28 +++++++++++++++++-- 5 files changed, 59 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/com/themecleanflex/models/DatalistModel.java b/core/src/main/java/com/themecleanflex/models/DatalistModel.java index 02c2777f3..d60512012 100644 --- a/core/src/main/java/com/themecleanflex/models/DatalistModel.java +++ b/core/src/main/java/com/themecleanflex/models/DatalistModel.java @@ -28,7 +28,7 @@ "x-form-type": "text", "x-default": "" }, - "loadFunction": { + "loadfunction": { "type": "string", "x-source": "inject", "x-form-label": "Javascript function to call to load data", @@ -484,7 +484,7 @@ public class DatalistModel extends AbstractComponent { /* {"type":"string","x-source":"inject","x-form-label":"Javascript function to call to load data","x-form-hint":"Function must accept (name)","x-form-type":"text"} */ @Inject - private String loadFunction; + private String loadfunction; /* {"type":"string","x-source":"inject","x-form-label":"Table Configuration","x-form-fieldLabel":"header","x-form-type":"collection","properties":{"header":{"type":"string","x-source":"inject","x-form-label":"Column Header","x-form-type":"text"},"value":{"type":"string","x-source":"inject","x-form-label":"Data Value","x-form-type":"text"}}} */ @Inject @@ -653,8 +653,8 @@ public String getEndpointurl() { } /* {"type":"string","x-source":"inject","x-form-label":"Javascript function to call to load data","x-form-hint":"Function must accept (name)","x-form-type":"text"} */ - public String getLoadFunction() { - return loadFunction; + public String getLoadfunction() { + return loadfunction; } /* {"type":"string","x-source":"inject","x-form-label":"Table Configuration","x-form-fieldLabel":"header","x-form-type":"collection","properties":{"header":{"type":"string","x-source":"inject","x-form-label":"Column Header","x-form-type":"text"},"value":{"type":"string","x-source":"inject","x-form-label":"Data Value","x-form-type":"text"}}} */ diff --git a/fragments/datalist/model.json b/fragments/datalist/model.json index d412a0b94..e494c140b 100644 --- a/fragments/datalist/model.json +++ b/fragments/datalist/model.json @@ -11,7 +11,7 @@ "x-form-type": "text", "x-default": "" }, - "loadFunction": { + "loadfunction": { "type": "string", "x-source": "inject", "x-form-label": "Javascript function to call to load data", diff --git a/fragments/datalist/template.vue b/fragments/datalist/template.vue index 8cd5a28e7..80cf40428 100644 --- a/fragments/datalist/template.vue +++ b/fragments/datalist/template.vue @@ -120,7 +120,30 @@ } }, mounted() { - if(this.model.endpointurl && this.model.endpointurl !== '') { + if(this.model.loadfunction && this.model.loadfunction !== '') { + const objs = this.model.loadfunction.split('.') + let parent = window + let obj = objs.shift() + while(obj && parent[obj]) { + if(objs.length === 0) { + try { + const result = parent[obj](this.model.endpointurl) + if(result === false) { + console.error('Failed to load data from ''+this.model.endpointurl) + } + Vue.set(this, 'storageData', result) + } catch(err) { + console.error(err) + } + return + } + parent = parent[obj] + obj = objs.shift() + } + console.log('window.' + this.model.loadfunction + ' not found') + return + } + else if(this.model.endpointurl && this.model.endpointurl !== '') { // load data from URL axios.get(this.model.endpointurl) .then( (response) => { @@ -130,7 +153,8 @@ .catch( (error) => { console.log(error) }) - } else { + } + else { // use local storage if nothing else is configured // interesting aspect :-) if another tab on the same computer // has the same page open it actually updates diff --git a/ui.apps/src/main/content/jcr_root/apps/themecleanflex/components/datalist/dialog.json b/ui.apps/src/main/content/jcr_root/apps/themecleanflex/components/datalist/dialog.json index 5b294e5b0..615f76381 100644 --- a/ui.apps/src/main/content/jcr_root/apps/themecleanflex/components/datalist/dialog.json +++ b/ui.apps/src/main/content/jcr_root/apps/themecleanflex/components/datalist/dialog.json @@ -10,9 +10,9 @@ { "type": "input", "inputType": "text", - "placeholder": "loadFunction", + "placeholder": "loadfunction", "label": "Javascript function to call to load data", - "model": "loadFunction", + "model": "loadfunction", "hint": "Function must accept (name)" }, { diff --git a/ui.apps/src/main/content/jcr_root/apps/themecleanflex/components/datalist/template.vue b/ui.apps/src/main/content/jcr_root/apps/themecleanflex/components/datalist/template.vue index 8cd5a28e7..80cf40428 100644 --- a/ui.apps/src/main/content/jcr_root/apps/themecleanflex/components/datalist/template.vue +++ b/ui.apps/src/main/content/jcr_root/apps/themecleanflex/components/datalist/template.vue @@ -120,7 +120,30 @@ } }, mounted() { - if(this.model.endpointurl && this.model.endpointurl !== '') { + if(this.model.loadfunction && this.model.loadfunction !== '') { + const objs = this.model.loadfunction.split('.') + let parent = window + let obj = objs.shift() + while(obj && parent[obj]) { + if(objs.length === 0) { + try { + const result = parent[obj](this.model.endpointurl) + if(result === false) { + console.error('Failed to load data from ''+this.model.endpointurl) + } + Vue.set(this, 'storageData', result) + } catch(err) { + console.error(err) + } + return + } + parent = parent[obj] + obj = objs.shift() + } + console.log('window.' + this.model.loadfunction + ' not found') + return + } + else if(this.model.endpointurl && this.model.endpointurl !== '') { // load data from URL axios.get(this.model.endpointurl) .then( (response) => { @@ -130,7 +153,8 @@ .catch( (error) => { console.log(error) }) - } else { + } + else { // use local storage if nothing else is configured // interesting aspect :-) if another tab on the same computer // has the same page open it actually updates