-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathweek-schedule.js
89 lines (80 loc) · 2.38 KB
/
week-schedule.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
module.exports = function(RED) {
'use strict';
var utils = require('./utils');
// Week Schedule Node constructor
function WeekScheduleNode(config) {
try {
var ui = undefined;
if(ui === undefined) {
ui = RED.require("node-red-dashboard")(RED);
}
var node = this;
var date = new Date();
var day = date.getDay();
if ( typeof node.days == 'undefined' ) node.days=day;
if ( typeof node.selector == 'undefined' ) node.selector=0;
if ( typeof node.saving == 'undefined' ) node.saving=0;
if ( typeof node.timing == 'undefined' )
{
node.timing=[
0,0,0,0,0,0,0,23,23,23,23,23,23,23,23,23,23,23,23,0,0,0,0,0,
0,0,0,0,0,0,0,23,23,23,23,23,23,23,23,23,23,23,23,0,0,0,0,0,
0,0,0,0,0,0,0,23,23,23,23,23,23,23,23,23,23,23,23,0,0,0,0,0,
0,0,0,0,0,0,0,23,23,23,23,23,23,23,23,23,23,23,23,0,0,0,0,0,
0,0,0,0,0,0,0,23,23,23,23,23,23,23,23,23,23,23,23,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
4,22
];
node.saving=0;
}
RED.nodes.createNode(this, config);
if (utils.checkConfig(config, node)) {
var done = ui.addWidget({
node: node,
format: utils.HTML(),
group: config.group,
templateScope: "local",
order: config.order,
beforeEmit: utils.beforeEmit(node, RED),
beforeSend: function (msg, orig) {
/********************
* THIS IS SERVER SIDE
********************/
// filter current node messages
// if (msg.topic !== config.name) {
// msg
// }
if (msg.timing) {
// console.log("msg", msg._msgid);
// update server side node timing
node.timing = msg.timing;
// set topic
msg.topic = config.name;
// set controls
utils.controls(node, msg, RED);
return msg;
}
if (orig) {
if (orig.msg) {
// console.log("orig.msg", orig.msg);
// setup msg timing
orig.msg.timing = node.timing;
// set topic
orig.msg.topic = config.name;
// set controls
utils.controls(node, orig.msg, RED);
return orig.msg;
}
}
},
initController: utils.initController
});
node.on("close", done);
}
} catch(error) {
console.log("While constructing WeekScheduleNode widget:", error);
}
}
RED.nodes.registerType("ui_week_schedule", WeekScheduleNode);
}