forked from urbiworx/node-red-contrib-freeboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatasource.template
41 lines (39 loc) · 1.09 KB
/
datasource.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//https://github.com/Freeboard/plugins/blob/master/datasources/plugin_example.js
(function(){
var dsid="{{id}}";
freeboard.loadDatasourcePlugin({
"type_name": "{{name}}",
"display_name": "{{display_name}}",
"description": "{{description}}",
"settings": [
],
newInstance: function(settings, newInstanceCallback, updateCallback) {
newInstanceCallback(new myDatasourcePlugin(settings, updateCallback));
}
});
var myDatasourcePlugin = function(settings, updateCallback) {
var self = this;
var currentSettings = settings;
self.id=dsid;
ux.freeboard.addDatasource(self);
self.update = function(data){
updateCallback(data);
}
self.onSettingsChanged = function(newSettings) {
currentSettings = newSettings;
}
self.updateNow = function() {
$.ajax({
url: "../freeboard_api/datasourceupdate?direct=true"
}).done(function(data) {
var pdata=JSON.parse(data);
if (typeof(pdata[dsid])!=="undefined"){
updateCallback(pdata[dsid]);
}
});
}
self.onDispose = function() {
ux.freeboard.removeDatasource(self);
}
}
})();