-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStatusbarWidgetTemplate.js
127 lines (104 loc) · 3.45 KB
/
StatusbarWidgetTemplate.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// Node-Red Contribution
//
// see also
// https://nodered.org/docs/
// https://nodered.org/docs/creating-nodes/
//
// generated 2018-04-20 10:31:38.388
//
module.exports = function(RED) {
//
// see also
// https://nodered.org/docs/
// https://nodered.org/docs/creating-nodes/
// https://github.com/node-red/node-red/wiki/API-Reference#server-Node-input
//
function StatusbarWidgetTemplateNode(config) {
RED.nodes.createNode(this, config);
var node = this;
node.name = config.name;
var sbwUtility = require('./sbwUtility');
var sbw = {
Type: config.sbwType,
Id: config.sbwId,
Options: config.sbwOptions
};
//node.log('created ' + JSON.stringify(sbw));
// const fs = require('fs')
// const process = require('process');
// // this need the full path when deplyoing
// var cwd = process.cwd();
// var singeltonFilename = 'nrStatusBarSingelton_0.4.html';
//node.log("nrStatusBarSingelton cwd is:\"" + cwd + "\"");
// in testing mode
// try {
// if (fs.existsSync(cwd + '/include/' + singeltonFilename)) {
// filepath = cwd;
// } else if (fs.existsSync(cwd + '/.node-red/node_modules/include/' + singeltonFilename)) {
// filepath = cwd + '/.node-red/node_modules';
// }
// } catch(err) {
// console.error(err)
// node.error("nrStatusBarSingelton file nof found:\"" + cwd + "\"");
// }
// may be there is a better way to include the scripts
const data = "<script id=\"sbManager\" type=\"text/javascript\" src=\"ui_statusbarwidget/js/sbManager.js\"></script>"+
"<script id=\"sbLed\" type=\"text/javascript\" src=\"ui_statusbarwidget/js/sbLed.js\"></script>"+
"<script id=\"sbLed\" type=\"text/javascript\" src=\"ui_statusbarwidget/js/sbText.js\"></script>"+
"<script id=\"sbIcon\" type=\"text/javascript\" src=\"ui_statusbarwidget/js/sbIcon.js\"></script>";
//
// event input
//
node.on('input',function(msg) {
// set the configured parameters
if ( typeof msg.sbw === "undefined" ) {
msg.sbw = sbw;
}
if (msg.payload === "connect") { // msg from ui_control, when the client browser reloads
msg.template = data;
node.send(msg);
setTimeout(function(){
msg.topic = "create";
if ( typeof msg.sbw === "undefined" ) {
msg.sbw = sbw;
}
msg.template = sbwUtility.createTemplate(msg,node,RED);
node.send(msg);
},750);
return;
}
if (msg.topic === "init") {
//msg.template = data;
node.send(msg);
return;
}
msg.template = sbwUtility.createTemplate(msg,node,RED);
node.send(msg);
});
//
// event close
//
node.on('close',function(done) {
node.log('close');
done();
});
}
RED.nodes.registerType("StatusbarWidgetTemplate",StatusbarWidgetTemplateNode);
var path = require('path');
var uipath = 'ui';
if (RED.settings.ui) {
uipath = RED.settings.ui.path;
}
var fullPath = path.join('/', uipath, '/ui_statusbarwidget/*').replace(/\\/g, '/');
//console.log("ui_statusbarwidget: fullpath: " + fullPath);
RED.httpNode.get(fullPath, function (req, res) {
var options = {
root: __dirname + '/include/',
dotfiles: 'deny'
};
//console.log("ui_statusbarwidget: fullpath: " + fullPath);
//console.log("ui_statusbarwidget: req.params[0]: " + req.params[0] + " options:" + JSON.stringify(options));
res.sendFile(req.params[0], options)
});
}