@gregoriusrippenstein/node-red-contrib-introspection 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -79,9 +79,16 @@ The context in which the code is exected includes:
79
79
 
80
80
  - `payload` which is the the `msg.payload` value
81
81
  - `topic` which is the `msg.topic` value
82
+ - `msg.payload` contains the payload sent to the node.
83
+ - `node.id` and `nodeid` are the id of the current node
84
+
85
+ Functionality which interacts with the flow:
86
+
82
87
  - `node.send(payload)` where `payload` becomes the output the node on the server side
83
88
  - `node.error("msg")` where msg is shown as a notification within the editor
84
- - `msg.payload` contains the payload sent to the node.
89
+ - `node.status({fill: 'red', shape: 'dot', text: 'hello world'})` - generate a status for the node.
90
+
91
+ An example if the client code node is this [flow](https://flowhub.org/f/01920991a09b7e95) where the node generates an in browser notification.
85
92
 
86
93
  ## Deprecated Nodes
87
94
 
@@ -15,7 +15,7 @@
15
15
  url: "ClientCode/" + nodeid,
16
16
  type: "POST",
17
17
  contentType: "application/json; charset=utf-8",
18
- data: JSON.stringify(data),
18
+ data: JSON.stringify(data),
19
19
 
20
20
  success: function (resp) {
21
21
  },
@@ -31,6 +31,27 @@
31
31
  });
32
32
  };
33
33
 
34
+ var doStatus = (sts, nodeid, _msg) => {
35
+ $.ajax({
36
+ url: "ClientCode/" + nodeid + "/status",
37
+ type: "POST",
38
+ contentType: "application/json; charset=utf-8",
39
+ data: JSON.stringify(sts),
40
+
41
+ success: function (resp) {
42
+ },
43
+
44
+ error: function (jqXHR, textStatus, errorThrown) {
45
+ RED.notify("ClientCode Communcation Failure: " +
46
+ nodeid + ": " + textStatus, {
47
+ type: "error",
48
+ id: nodeid,
49
+ timeout: 3000
50
+ });
51
+ }
52
+ });
53
+ }
54
+
34
55
  var doError = (msg, nodeid, _msg) => {
35
56
  RED.notify("ClientCode Failed: " + nodeid + ": " + msg, {
36
57
  type: "error",
@@ -46,13 +67,10 @@
46
67
  var msg = data._msg;
47
68
 
48
69
  var node = {
49
- send: (dt) => {
50
- doSend(dt, nodeid, _msg)
51
- },
52
- error: (mg) => {
53
- doError(mg, nodeid, _msg)
54
- },
55
- id: data.nodeid
70
+ id: data.nodeid,
71
+ send: (dt) => { doSend(dt, nodeid, _msg) },
72
+ error: (mg) => { doError(mg, nodeid, _msg) },
73
+ status: (sts) => { doStatus(sts, nodeid, _msg) }
56
74
  };
57
75
 
58
76
  var payload = data.payload;
@@ -106,8 +124,19 @@
106
124
 
107
125
  this.editor = RED.editor.createEditor({
108
126
  id: 'node-input-clientcode-editor',
109
- mode: 'ace/mode/javascript',
127
+ mode: 'ace/mode/nrjavascript',
110
128
  stateId: stateId,
129
+ globals: {
130
+ msg:true,
131
+ RED: true,
132
+ node: true,
133
+ console: true,
134
+ Buffer: true,
135
+ setTimeout: true,
136
+ clearTimeout: true,
137
+ setInterval: true,
138
+ clearInterval: true
139
+ },
111
140
  value: $("#node-input-clientcode").val()
112
141
  });
113
142
 
@@ -218,6 +247,7 @@ Variables:
218
247
  Functionality:
219
248
  node.send({..}) - send data to the output port of this node
220
249
  node.error("msg") - generate an error for the node
250
+ node.status( { fill: 'red', shape: 'dot', text: 'hello world'}) - generate a status for the node.
221
251
  </code>
222
252
  </pre>
223
253
 
@@ -47,4 +47,27 @@ module.exports = function(RED) {
47
47
  }
48
48
  });
49
49
 
50
+
51
+ RED.httpAdmin.post("/ClientCode/:id/status",
52
+ RED.auth.needsPermission("ClientCode.write"),
53
+ (req, res) => {
54
+ var node = RED.nodes.getNode(req.params.id);
55
+ if (node != null) {
56
+ try {
57
+ if (req.body && node.type == "ClientCode") {
58
+ node.status(req.body);
59
+ res.sendStatus(200);
60
+ } else {
61
+ res.sendStatus(404);
62
+ }
63
+ } catch (err) {
64
+ res.sendStatus(500);
65
+ node.error("ClientCode: Submission failed: " +
66
+ err.toString())
67
+ }
68
+ } else {
69
+ res.sendStatus(404);
70
+ }
71
+ });
72
+
50
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gregoriusrippenstein/node-red-contrib-introspection",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "dependencies": {
5
5
  "got": "latest"
6
6
  },