@mschaeffler/node-red-logic 3.4.0 → 3.5.0

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.
@@ -12,6 +12,7 @@
12
12
  minData:{value:"1", required:true, validate:function(v){
13
13
  return v!=='' && !isNaN(v) && Number(v)>0;}
14
14
  },
15
+ contextStore:{value:"",required:true},
15
16
  showState:{value:false}
16
17
  },
17
18
  inputs:1,
@@ -26,11 +27,25 @@
26
27
  inputLabels: 'input',
27
28
  outputLabels: 'output',
28
29
  oneditprepare: function() {
30
+ const node = this;
29
31
  $("#node-input-property").typedInput({
30
32
  type:"msg",
31
33
  types:["msg","jsonata"],
32
34
  typeField: "#node-input-propertyType"
33
35
  });
36
+ // populate store names
37
+ $("#node-input-contextStore").empty();
38
+ $("#node-input-contextStore").append(`<option value="none">None</option>`);
39
+ const defaultStore = RED.settings.hasOwnProperty('context') ? RED.settings.context.default : ''
40
+ RED.settings.context.stores.forEach(function(item){
41
+ if( item ) {
42
+ const opt = $(`<option value="${item}">${item}${item===defaultStore?" (default)":""}</option>`);
43
+ $("#node-input-contextStore").append(opt);
44
+ }
45
+ });
46
+ const currentStore = node.contextStore || '';
47
+ // select the current option
48
+ $("#node-input-contextStore").val(currentStore);
34
49
  }
35
50
  });
36
51
  </script>
@@ -53,6 +68,10 @@
53
68
  <label for="node-input-minData"><i class="fa fa-check-square-o "></i> min. Data</label>
54
69
  <input type="text" id="node-input-minData">
55
70
  </div>
71
+ <div class="form-row">
72
+ <label for="node-input-contextStore"><i class="fa fa-database"></i> Contextstore</label>
73
+ <select type="text" id="node-input-contextStore"></select>
74
+ </div>
56
75
  <div class="form-row">
57
76
  <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
58
77
  <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
@@ -109,6 +128,8 @@
109
128
  <dd> time frame to collect the data for the analysis.</dd>
110
129
  <dt>min. Data <span class="property-type">number</span></dt>
111
130
  <dd> min. amount of data points to generate an output.</dd>
131
+ <dt>Contextstore <span class="property-type">context store</span></dt>
132
+ <dd> context store for storing the values; <code>none</code> is no storage.</dd>
112
133
  <dt>Status <span class="property-type">boolean</span></dt>
113
134
  <dd> shows the actual value as a node status.</dd>
114
135
  </dl>
@@ -9,6 +9,7 @@ module.exports = function(RED) {
9
9
  this.propertyType = config.propertyType ?? "msg";
10
10
  this.deltaTime = Number( config.deltaTime ?? 60 )*1000;
11
11
  this.minData = Number( config.minData ?? 1 );
12
+ this.contextStore = config.contextStore ?? "none";
12
13
  this.showState = Boolean( config.showState );
13
14
  if( this.propertyType === "jsonata" )
14
15
  {
@@ -61,7 +62,7 @@ module.exports = function(RED) {
61
62
  const payload = Number( value );
62
63
  if( ! isNaN( payload ) )
63
64
  {
64
- let data = context.get( "data" ) ?? {};
65
+ let data = context.get( "data", node.contextStore ) ?? {};
65
66
  let item = data[msg.topic] ?? [];
66
67
  item.push( { time:now, value:payload } );
67
68
  while( item[0].time < now - node.deltaTime )
@@ -69,7 +70,7 @@ module.exports = function(RED) {
69
70
  item.shift();
70
71
  }
71
72
  data[msg.topic] = item;
72
- context.set( "data", data );
73
+ context.set( "data", data, node.contextStore );
73
74
 
74
75
  if( item.length >= node.minData )
75
76
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-logic",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
4
4
  "description": "nodes for simple operations.",
5
5
  "license": "LGPL-2.1",
6
6
  "homepage": "https://github.com/m-schaeffler/node-red-my-nodes/tree/main/node-red-logic",