-
Notifications
You must be signed in to change notification settings - Fork 4
/
ui-load.js
88 lines (65 loc) · 2.11 KB
/
ui-load.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
'use strict';
module.exports = function (RED) {
var ui = undefined;
var utils = require('./ui');
function model(_node, _config) {
return function (_msg, _value) {
return {
msg: {
payload: { }
}
};
};
}
function view(node, config) {
var id = "load" + node.id.replace(/[^\w]/g, "");
return `<div id="${id}"></div>`;
}
function controller(node, _config) {
var id = node.id.replace(/[^\w]/g, "");
var fn = String.raw`
${utils.literals.observeDOM("const observeDOM")}
const attemptUpdate = () => {
const elem = document.getElementById('load${id}');
if (elem) {
$scope.send();
} else {
observeDOM(document, (change) => attemptUpdate());
}
};
attemptUpdate();
`;
return Function("$scope", "events", fn);
};
function UiLoad(config) {
RED.nodes.createNode(this, config);
var node = this;
if (ui === undefined) {
ui = RED.require("node-red-dashboard")(RED);
}
var node = this;
var done = ui.addWidget({
node: node,
templateScope: "local",
group: config.group,
order: config.order,
width: -1, height: -1, //https://discourse.nodered.org/t/custom-dashboard-node-without-md-card-possible/14919/20
emitOnlyNewValues: false,
forwardInputMessages: false,
storeFrontEndInputAsState: false,
format: view(node, config),
beforeEmit: model(node, config),
initController: controller(node, config),
beforeSend: function (_msg, orig) { // callback to prepare the message that is sent to the output
if (orig) {
return orig.msg;
}
}
});
node.on("close",function() {
node.status({});
done();
});
};
RED.nodes.registerType("hidden-ui-load", UiLoad);
};