Skip to content

Commit

Permalink
#156 updated loadfunction code and fixed dialog names and error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
qial committed Aug 31, 2020
1 parent 725c805 commit 39a908d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"}}} */
Expand Down
2 changes: 1 addition & 1 deletion fragments/datalist/model.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 26 additions & 2 deletions fragments/datalist/template.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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
Expand Down

0 comments on commit 39a908d

Please sign in to comment.