-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75ad207
commit 0cdb65d
Showing
6 changed files
with
152 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
local extension = ... | ||
|
||
local webBaseAddons = extension:require('web-base.addons', true) | ||
|
||
webBaseAddons.register(extension, 'init.js') |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
define(function() { | ||
|
||
function getPropertyValue(things, properties, path) { | ||
var parts = path.split('/', 2); | ||
var thingId = parts[0]; | ||
var propName = parts[1]; | ||
var props = properties[thingId]; | ||
if (props) { | ||
var value = props[propName]; | ||
if (value !== undefined) { | ||
return value; | ||
} | ||
} | ||
var thing = things[thingId]; | ||
if (thing) { | ||
var thgProp = thing.properties[propName]; | ||
if (thgProp) { | ||
var propType = thgProp['@type']; | ||
switch (propType) { | ||
case 'integer': | ||
case 'number': | ||
return 0; | ||
case 'string': | ||
return ''; | ||
case 'boolean': | ||
return false; | ||
} | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
function load(config, viewXml) { | ||
var script = ''; | ||
for(;;) { | ||
// type="text/javascript" | ||
var i = viewXml.indexOf('<script>'); | ||
if (i < 0) { | ||
break; | ||
} | ||
var j = viewXml.indexOf('</script>', i); | ||
if (j < 0) { | ||
break; | ||
} | ||
script += '\n' + viewXml.substring(i + 8, j); | ||
viewXml = viewXml.substring(0, i) + viewXml.substring(j + 9); | ||
} | ||
var options = { | ||
template: [ | ||
'<app-page id="' + config.id + '" title="' + config.title + '">', | ||
viewXml, | ||
'</app-page>' | ||
].join('\n') | ||
}; | ||
if (config.properties && config.properties.length > 0) { | ||
assignMap(options, { | ||
data: { | ||
property: {} | ||
}, | ||
methods: { | ||
onShow: function() { | ||
this.onDataChange(); | ||
}, | ||
onDataChange: function() { | ||
Promise.all([ | ||
app.getThings(), | ||
app.getPropertiesByThingId() | ||
]).then(apply(this, function(things, properties) { | ||
var propertyMap = {}; | ||
for (var i = 0; i < config.properties.length; i++) { | ||
var cfgProp = config.properties[i]; | ||
propertyMap[cfgProp.name] = getPropertyValue(things, properties, cfgProp.path); | ||
} | ||
this.property = propertyMap; | ||
})); | ||
}, | ||
getPropertyByPath: function(path) { | ||
return Promise.all([ | ||
app.getThings(), | ||
app.getPropertiesByThingId() | ||
]).then(apply(this, function(things, properties) { | ||
return getPropertyValue(things, properties, path); | ||
})); | ||
}, | ||
setPropertyByPath: function(path, value) { | ||
var parts = path.split('/', 2); | ||
var thingId = parts[0]; | ||
var propName = parts[1]; | ||
var valueByName = {}; | ||
valueByName[propName] = value; | ||
return fetch('/things/' + thingId + '/properties', { | ||
method: 'PUT', | ||
body: JSON.stringify(valueByName) | ||
}).then(rejectIfNotOk); | ||
}, | ||
setProperty: function(name, value) { | ||
for (var i = 0; i < config.properties.length; i++) { | ||
var cfgProp = config.properties[i]; | ||
if (cfgProp.name === name) { | ||
return this.setPropertyByPath(cfgProp.path, value); | ||
} | ||
} | ||
return Promise.reject('not found'); | ||
} | ||
} | ||
}); | ||
} | ||
if (script.length > 0) { | ||
var fn = Function('options', 'config', '"use strict";' + script); | ||
fn.call(this, options, config); | ||
} | ||
var vue = new Vue(options); | ||
addPageComponent(vue, config.icon); | ||
} | ||
|
||
return { | ||
load: load | ||
}; | ||
|
||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters