@ralphwetzel/node-red-context-monitor 1.1.0 → 1.2.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
@@ -1,7 +1,7 @@
1
1
  # @ralphwetzel/node-red-context-monitor
2
2
 
3
3
  <img alt="flow" src="https://raw.githubusercontent.com/ralphwetzel/node-red-context-monitor/main/resources/preview.png"
4
- style="min-width: 250px; width: 250px; align: center; border: 1px solid lightgray;"/>
4
+ style="min-width: 212px; width: 212px; align: center; border: 1px solid lightgray;"/>
5
5
 
6
6
  A [Node-RED](https://www.nodered.org) node to monitor a [context](https://nodered.org/docs/user-guide/context).
7
7
 
package/lib/monitor.js CHANGED
@@ -76,13 +76,13 @@ let create_wrapper = function(node_id, flow_id, ctx, root_id) {
76
76
  }
77
77
  return create_wrapper('global', undefined, global_context, node_id);
78
78
  }
79
- return Reflect.get(context, propertyKey, receiver);
79
+ return Reflect.get(context, propertyKey);
80
80
  },
81
81
  getOwnPropertyDescriptor: function (target, propertyKey) {
82
82
  return Reflect.getOwnPropertyDescriptor(context, propertyKey);
83
83
  },
84
84
  getPrototypeOf: function (target){
85
- Reflect.getPrototypeOf(context);
85
+ return Reflect.getPrototypeOf(context);
86
86
  },
87
87
  has: function (target, propertyKey){
88
88
  return Reflect.has(context, propertyKey);
@@ -97,7 +97,7 @@ let create_wrapper = function(node_id, flow_id, ctx, root_id) {
97
97
  return Reflect.preventExtensions(context);
98
98
  },
99
99
  set: function (target, propertyKey, value, receiver) {
100
- return Reflect.set(context, propertyKey, value, receiver);
100
+ return Reflect.set(context, propertyKey, value);
101
101
  },
102
102
  setPrototypeOf: function (target, prototype) {
103
103
  return Reflect.setPrototypeOf(context, prototype)
@@ -112,7 +112,7 @@ let create_wrapper = function(node_id, flow_id, ctx, root_id) {
112
112
 
113
113
  let handler = {
114
114
  get: (target, property, receiver) => {
115
- let getted = Reflect.get(target, property, receiver);
115
+ let getted = Reflect.get(object, property);
116
116
 
117
117
  // if getted is an object, wrap this (again)
118
118
  // to ensure monitoring in case of direct reference access
@@ -131,8 +131,8 @@ let create_wrapper = function(node_id, flow_id, ctx, root_id) {
131
131
  },
132
132
  set: function(target, propertyKey, value, receiver) {
133
133
  // this is the monitoring function!
134
- let previous_value = Reflect.get(target, propertyKey, receiver);
135
- res = Reflect.set(target, propertyKey, value, receiver);
134
+ let previous_value = Reflect.get(object, propertyKey);
135
+ res = Reflect.set(object, propertyKey, value);
136
136
 
137
137
  let prop_chain = propertyKey;
138
138
  if (getter_key?.length) {
@@ -152,7 +152,7 @@ let create_wrapper = function(node_id, flow_id, ctx, root_id) {
152
152
 
153
153
  let handler = {
154
154
  get: (target, property, receiver) => {
155
- let getted = Reflect.get(target, property, receiver);
155
+ let getted = Reflect.get(object, property);
156
156
 
157
157
  if (
158
158
  typeof getted === 'object' &&
@@ -168,8 +168,8 @@ let create_wrapper = function(node_id, flow_id, ctx, root_id) {
168
168
  },
169
169
  set: function(target, propertyKey, value, receiver) {
170
170
  // this is the monitoring function!
171
- let previous_value = Reflect.get(target, propertyKey, receiver);
172
- res = Reflect.set(target, propertyKey, value, receiver);
171
+ let previous_value = Reflect.get(object, propertyKey);
172
+ res = Reflect.set(object, propertyKey, value);
173
173
 
174
174
  let prop_chain = propertyKey;
175
175
  if (getter_key?.length) {
package/monitor.html CHANGED
@@ -45,27 +45,30 @@
45
45
  }
46
46
  return true;
47
47
  }
48
+ },
49
+ tostatus: {
50
+ value: false
48
51
  }
49
52
  },
50
53
  inputs: 0,
51
54
  outputs: 2,
52
55
  outputLabels: ["context set", "context changed"],
53
- icon: "font-awesome/fa-dot-circle-o",
56
+ icon: "font-awesome/fa-copyright",
54
57
  label: function() {
55
58
  if (this.name) {
56
59
  return this.name;
57
60
  }
58
61
  let l = this.monitoring.length;
59
62
  if (l > 1) {
60
- return `${l} context keys`;
63
+ return `context: ${l}`;
61
64
  }
62
65
  let key = this.monitoring[0]?.key;
63
66
  if (key && key.length > 0) {
64
67
  return key;
65
68
  }
66
- return "ctx monitor";
69
+ return "context: 0";
67
70
  },
68
- paletteLabel: "ctx monitor",
71
+ paletteLabel: "context",
69
72
  oneditprepare: function() {
70
73
 
71
74
  let node = this;
@@ -127,7 +130,7 @@
127
130
  $(`<input type="text" id="context-scope-nodes-${index}" placeholder="Nodes">`).appendTo(line_node);
128
131
  line_node.appendTo(fragment);
129
132
 
130
- let line_key = $('<div class="form-row" style="margin-bottom: 0px">');
133
+ let line_key = $('<div class="form-row" style="margin-bottom: 6px">');
131
134
  // $(`<label for="context-scope-key-${index}"" style="margin-left:10px; width: 90px"><i class="fa fa-tag"></i> Key</label>`).appendTo(line_key);
132
135
  $(`<label for="context-scope-key-${index}" style="margin-left:10px; width: 90px">Key: </label>`).appendTo(line_key);
133
136
  $(`<input type="text" id="context-scope-key-${index}" placeholder="Context Variable Key">`).appendTo(line_key);
@@ -390,6 +393,9 @@
390
393
  let top = el.position().top;
391
394
  el.height(size.height - top);
392
395
 
396
+ let bottom = top + el.height();
397
+ let right = el.position().left + el.width();
398
+
393
399
  let ti = $('[id*=context-scope-flows]:first');
394
400
  let width;
395
401
  if (ti.length > 0) {
@@ -398,6 +404,13 @@
398
404
  if (width) {
399
405
  $('[id*=context-scope-key]').outerWidth(width);
400
406
  }
407
+
408
+ el = $('#tostatus-row');
409
+ let list = el.prev();
410
+ let add = list.find('.red-ui-editableList-addButton');
411
+ el.css("top" , add.position().top);
412
+ el.css("left", right - el.width());
413
+
401
414
  },
402
415
  oneditsave: function () {
403
416
  let node = this;
@@ -445,11 +458,17 @@
445
458
  <input type="text" id="node-input-monitoring" placeholder="Context">
446
459
  </div> -->
447
460
  <div class="form-row" style="margin-bottom:0;">
448
- <label style="min-width:200px;"><i class="fa fa-dot-circle-o"></i> <span>Monitoring context definition</span></label>
461
+ <label style="min-width:200px;"><i class="fa fa-copyright"></i> <span>Monitoring context definition</span></label>
449
462
  </div>
450
463
  <div class="form-row node-input-context-def-row">
451
464
  <ol id="node-input-context-container"></ol>
452
465
  </div>
466
+ <div id ="tostatus-row" style="position: absolute">
467
+ <label for="node-input-tostatus" style="margin-top: 4px">
468
+ <input type="checkbox" id="node-input-tostatus" style="display:inline-block; width:22px; vertical-align:top;" autocomplete="off">
469
+ <span>Show incoming data in node status</span>
470
+ </label>
471
+ </div>
453
472
  </script>
454
473
 
455
474
  <script type="text/markdown" data-help-name="context-monitor">
package/monitor.js CHANGED
@@ -25,7 +25,7 @@ function scan_for_require_path(req_path) {
25
25
 
26
26
  if (process.env.NODE_RED_HOME) {
27
27
  found = path.join(process.env.NODE_RED_HOME, "..", req_path);
28
- console.log("@f", found);
28
+ // console.log("@f", found);
29
29
  if (fs.existsSync(found)) {
30
30
  return found;
31
31
  }
@@ -64,7 +64,7 @@ function scan_for_require_path(req_path) {
64
64
  }
65
65
  }
66
66
 
67
- console.log(found);
67
+ // console.log(found);
68
68
  return found;
69
69
  }
70
70
 
@@ -175,6 +175,9 @@ module.exports = function(RED) {
175
175
 
176
176
  node.on("input", function(msg, send, done) {
177
177
 
178
+ let node = this;
179
+ let timeout;
180
+
178
181
  // unfold & check if changed
179
182
  let prev = msg.previous;
180
183
  let changed = msg.changed;
@@ -192,6 +195,24 @@ module.exports = function(RED) {
192
195
  send([msg, null]);
193
196
  }
194
197
 
198
+ if (config.tostatus) {
199
+
200
+ if (timeout) {
201
+ clearTimeout(timeout);
202
+ }
203
+
204
+ node.status({
205
+ fill: "blue",
206
+ shape: changed ? "dot" : "ring",
207
+ text: msg.topic + ": " + JSON.stringify(msg.payload)
208
+ });
209
+
210
+ timeout = setTimeout(function() {
211
+ node.status({});
212
+ timeout = undefined;
213
+ }, 2500);
214
+ }
215
+
195
216
  done();
196
217
  });
197
218
  node.on("close",function() {
@@ -207,6 +228,11 @@ module.exports = function(RED) {
207
228
  }
208
229
  }
209
230
  })
231
+
232
+ if (timeout) {
233
+ clearTimeout(timeout);
234
+ timeout = undefined;
235
+ }
210
236
  });
211
237
  }
212
238
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ralphwetzel/node-red-context-monitor",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "A Node-RED node to monitor a context.",
5
5
  "main": "monitor.js",
6
6
  "scripts": {
@@ -27,15 +27,15 @@
27
27
  },
28
28
  "homepage": "https://github.com/ralphwetzel/node-red-context-monitor#readme",
29
29
  "dependencies": {
30
- "fs-extra": "^11.1.1",
31
- "node-red": "^3.1.0"
30
+ "fs-extra": "^11.1.1"
32
31
  },
33
32
  "engines": {
34
33
  "node": ">=14.0.0"
35
34
  },
36
35
  "devDependencies": {
37
36
  "mocha": "^10.2.0",
38
- "node-red-node-test-helper": "^0.3.2"
37
+ "node-red-node-test-helper": "^0.3.2",
38
+ "node-red": "^3.1.0"
39
39
  },
40
40
  "files": [
41
41
  "/examples",
Binary file