node-red-contrib-mobius-flow-base 2.5.86-beta.5 → 2.5.86-beta.53

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.
@@ -30,11 +30,11 @@
30
30
  const _ = require('lodash');
31
31
 
32
32
  module.exports = function (RED) {
33
- function MobiusGetObjectNode (n) {
33
+ function MobiusGetObjectNode(n) {
34
34
  RED.nodes.createNode(this, n);
35
35
  this.detailedOutput = n.detailedOutput;
36
36
  this.format = n.format;
37
- this.mobject = n.mobject;
37
+ this.instance = n.instance;
38
38
  this.serviceConn = RED.nodes.getNode(n.connection);
39
39
  var node = this;
40
40
 
@@ -42,11 +42,11 @@ module.exports = function (RED) {
42
42
  node.status({
43
43
  fill: 'red',
44
44
  shape: 'ring',
45
- text: 'Disconnected'
45
+ text: 'Disconnected',
46
46
  });
47
47
 
48
48
  node.on('input', function (msg) {
49
- let uri = node.mobject;
49
+ let uri = node.instance;
50
50
  if (msg.hasOwnProperty('topic') && require('./validateURI')(msg.topic, 4)) {
51
51
  uri = msg.topic;
52
52
  }
@@ -54,32 +54,35 @@ module.exports = function (RED) {
54
54
  node.status({
55
55
  fill: 'green',
56
56
  shape: 'ring',
57
- text: 'Busy'
57
+ text: 'Busy',
58
58
  });
59
59
  node.serviceConn.readObject(uri, (err, response) => {
60
60
  if (err) {
61
61
  node.status({
62
62
  fill: 'yellow',
63
63
  shape: 'dot',
64
- text: 'Error: ' + JSON.stringify(err.code)
64
+ text: 'Error: ' + JSON.stringify(err.code),
65
65
  });
66
66
  node.error('Mobius error reading object ' + JSON.stringify(err));
67
67
  if (node.detailedOutput === true) {
68
- node.send([null, null, {topic: uri, payload: { error: true, response: err }}]);
68
+ node.send([null, null, { topic: uri, payload: { error: true, response: err } }]);
69
69
  }
70
70
  } else {
71
71
  node.status({
72
72
  fill: 'green',
73
73
  shape: 'dot',
74
- text: JSON.stringify(response.uri)
74
+ text: JSON.stringify(response.uri),
75
75
  });
76
76
 
77
- let allResources = _.keyBy(response.value.resources, node.format === 'name' ? 'name' : 'rid');
77
+ let allResources = _.keyBy(
78
+ response.value.resources,
79
+ node.format === 'name' ? 'name' : 'rid'
80
+ );
78
81
  if (node.detailedOutput === true) {
79
82
  node.send([
80
83
  { topic: uri, payload: allResources },
81
84
  { topic: uri, payload: response.value },
82
- { topic: uri, payload: { error: false, response: response } }
85
+ { topic: uri, payload: { error: false, response: response } },
83
86
  ]);
84
87
  } else {
85
88
  node.send({ topic: uri, payload: allResources });
@@ -29,10 +29,18 @@ POSSIBILITY OF SUCH DAMAGE.
29
29
  <label for="node-input-connection"><i class="fa fa-globe"></i> MOBiUS</label>
30
30
  <input type="text" id="node-input-connection">
31
31
  </div>
32
- <div class="form-row">
33
- <label for="node-input-resource"><i class="fa fa-tasks"></i> URI</label>
34
- <input type="text" id="node-input-resource" placeholder="Resource URI (hid/sid/pid/ins/rid)">
32
+
33
+ <hr>
34
+
35
+ <div id="instance-row">
36
+ <div class="form-row" id="input-row">
37
+ <label for="node-input-resource"><i class="fa fa-tasks"></i> URI</label>
38
+ <input type="text" id="node-input-resource" style="width:61%;" placeholder="HID/SID/PID/INS/RID">
39
+ </div>
35
40
  </div>
41
+
42
+ <div id="mobsearch"></div>
43
+
36
44
  <div class="form-row">
37
45
  <label>&nbsp;</label>
38
46
  <input type="checkbox" id="node-input-detailedOutput" style="display: inline-block; width: auto; vertical-align: top;">
@@ -45,6 +53,8 @@ POSSIBILITY OF SUCH DAMAGE.
45
53
  </div>
46
54
  </script>
47
55
 
56
+ <script src="common/mobsearch.js"></script>
57
+
48
58
  <script type="text/javascript">
49
59
  RED.nodes.registerType('mobius get resource',{
50
60
  category: 'mobius',
@@ -85,6 +95,11 @@ POSSIBILITY OF SUCH DAMAGE.
85
95
  labelStyle: function() {
86
96
  return this.name ? "node_label_italic":"";
87
97
  },
98
+ oneditprepare: function () {
99
+ var node = this;
100
+ let mobiusSrvc = $("#node-input-connection").val();
101
+ getMobsearch(mobiusSrvc, 'rid', 'node-input-resource');
102
+ },
88
103
  oneditsave: function() {
89
104
  if($("#node-input-detailedOutput").prop('checked')) {
90
105
  this.outputs = 4;
@@ -28,7 +28,7 @@
28
28
  'use strict';
29
29
 
30
30
  module.exports = function (RED) {
31
- function MobiusGetResourceNode (n) {
31
+ function MobiusGetResourceNode(n) {
32
32
  RED.nodes.createNode(this, n);
33
33
  this.detailedOutput = n.detailedOutput;
34
34
  this.resource = n.resource;
@@ -39,7 +39,7 @@ module.exports = function (RED) {
39
39
  node.status({
40
40
  fill: 'red',
41
41
  shape: 'ring',
42
- text: 'Disconnected'
42
+ text: 'Disconnected',
43
43
  });
44
44
 
45
45
  node.on('input', function (msg) {
@@ -51,36 +51,41 @@ module.exports = function (RED) {
51
51
  node.status({
52
52
  fill: 'green',
53
53
  shape: 'ring',
54
- text: 'Busy'
54
+ text: 'Busy',
55
55
  });
56
56
  node.serviceConn.readResource(uri, (err, response) => {
57
57
  if (err) {
58
58
  node.status({
59
59
  fill: 'yellow',
60
60
  shape: 'dot',
61
- text: 'Error: ' + JSON.stringify(err.code)
61
+ text: 'Error: ' + JSON.stringify(err.code),
62
62
  });
63
63
  node.error('Mobius error reading resource ' + JSON.stringify(err));
64
64
  if (node.detailedOutput === true) {
65
- node.send([null, null, null, {topic: uri, payload: {error: true, response: err}}]);
65
+ node.send([
66
+ null,
67
+ null,
68
+ null,
69
+ { topic: uri, payload: { error: true, response: err } },
70
+ ]);
66
71
  }
67
72
  } else {
68
73
  node.status({
69
74
  fill: 'green',
70
75
  shape: 'dot',
71
- text: JSON.stringify(response.value.pv)
76
+ text: JSON.stringify(response.value.pv),
72
77
  });
73
78
  if (node.detailedOutput === true) {
74
79
  node.send([
75
80
  { topic: uri, payload: response.value.pv },
76
81
  { topic: uri, payload: { pv: response.value.pv, name: response.value.name } },
77
82
  { topic: uri, payload: response.value },
78
- { topic: uri, payload: { error: false, response: response } }
83
+ { topic: uri, payload: { error: false, response: response } },
79
84
  ]);
80
85
  } else {
81
86
  node.send([
82
87
  { topic: uri, payload: response.value.pv },
83
- { topic: uri, payload: { pv: response.value.pv, name: response.value.name } }
88
+ { topic: uri, payload: { pv: response.value.pv, name: response.value.name } },
84
89
  ]);
85
90
  }
86
91
  }
@@ -98,4 +103,12 @@ module.exports = function (RED) {
98
103
  }
99
104
 
100
105
  RED.nodes.registerType('mobius get resource', MobiusGetResourceNode);
106
+
107
+ RED.httpAdmin.get('/common/*', function (req, res) {
108
+ var options = {
109
+ root: __dirname + '/common/',
110
+ dotfiles: 'deny',
111
+ };
112
+ res.sendFile(req.params[0], options);
113
+ });
101
114
  };
@@ -29,10 +29,34 @@ POSSIBILITY OF SUCH DAMAGE.
29
29
  <label for="node-input-connection"><i class="fa fa-globe"></i> MOBiUS</label>
30
30
  <input type="text" id="node-input-connection">
31
31
  </div>
32
- <div class="form-row">
33
- <label for="node-input-object"><i class="fa fa-tasks"></i> URI</label>
34
- <input type="text" id="node-input-object" placeholder="Object URI (hid/sid/pid/ins)">
32
+
33
+ <hr>
34
+
35
+ <div id="instance-row">
36
+ <div class="form-row">
37
+ <label for="node-input-instance"><i class="fa fa-tasks"></i> URI</label>
38
+ <input type="text" id="node-input-instance" style="width:61%;" placeholder="HID/SID/PID/INS (optional name)">
39
+ <a id="node-lookup-instance" class="searchbutton" style="vertical-align: middle"><i id="node-lookup-instance-icon" class="fa fa-search"></i></a>
40
+ </div>
41
+ </div>
42
+ <div id="instance-search-row">
43
+ <div class="form-row">
44
+ <label for="instance-search-sid"><i class="fa fa-tasks"></i> URI</label>
45
+ <input type="text" id="instance-search-hid" style="width:15%;" placeholder="HID">
46
+ <input type="text" id="instance-search-sid" style="width:10%;" placeholder="SID">
47
+ <input type="text" id="instance-search-pid" style="width:10%;" placeholder="PID">
48
+ <input type="text" id="instance-search-ins" style="width:10%;" placeholder="INS">
49
+ <a id="node-search-return" class="searchbutton" style="vertical-align: middle"><i id="node-search-return-icon" class="fa fa-arrow-left"></i></a>
50
+ <a id="node-search-accept" class="searchbutton" style="vertical-align: middle"><i id="node-search-accept-icon" class="fa fa-check"></i></a>
51
+ </div>
35
52
  </div>
53
+ <div id="wildcard-alert-row" class="form-row hidden" style="color:#555555" align="center">
54
+ <p>Please note: The selection of wildcard '+'
55
+ means a search for a specific instance or resource
56
+ cannot be performed. As such, enter the
57
+ INS manually.</p>
58
+ </div>
59
+
36
60
  <div class="form-row">
37
61
  <label for="node-input-include"><i class="fa fa-bars"></i> Include</label>
38
62
  <select type="text" id="node-input-include" style="display: inline-block; width: auto; vertical-align: center;">
@@ -67,7 +91,7 @@ POSSIBILITY OF SUCH DAMAGE.
67
91
  detailedOutput: {value:false},
68
92
  format: {value: "name", required: true},
69
93
  include: {value: "changed", required: true},
70
- object: {value:"", validate:function(v) {
94
+ instance: {value:"", validate:function(v) {
71
95
  if(v === '') { return true; }
72
96
  let parts = v.split('/');
73
97
  for(let lp = 0; lp < parts.length; lp++) {
@@ -94,12 +118,239 @@ POSSIBILITY OF SUCH DAMAGE.
94
118
  if(this.name) {
95
119
  return this.name;
96
120
  } else {
97
- return this.object ? `ObjCOV - ${this.object}` : "object cov";
121
+ return this.instance ? `ObjCOV - ${this.instance}` : "object cov";
98
122
  }
99
123
  },
100
124
  labelStyle: function() {
101
125
  return this.name ? "node_label_italic":"";
102
126
  },
127
+ oneditprepare: function () {
128
+
129
+ var node = this;
130
+ let mobiusSrvc = $("#node-input-connection").val();
131
+
132
+ $("#instance-search-row").hide();
133
+
134
+ $("#node-search-return").addClass('disabled');
135
+
136
+ // *** MOBSEARCH *** //
137
+
138
+ //Inital setup
139
+ $("#instance-search-row").hide();
140
+ $("#wildcard-alert-row").hide();
141
+ $("#node-search-return").addClass('disabled');
142
+ $.getJSON(`mgethid?mobius=${mobiusSrvc}`, function (response) {
143
+ $("#instance-search-hid").val(response);
144
+ })
145
+ let readyToAccept = false;
146
+ let searchObject = {
147
+ hid: $("#instance-search-hid").val(),
148
+ sid: $("#instance-search-sid").val(),
149
+ pid: $("#instance-search-pid").val(),
150
+ ins: $("#instance-search-ins").val(),
151
+ objects: []
152
+ }
153
+
154
+ //Function to search for INSs
155
+ function insSearch (objects, pid) {
156
+ let inss = ['#'];
157
+ for (let i = 0; i < objects.length; i++) {
158
+ if (objects[i].pid === pid) {
159
+ const name = objects[i].resources[1].pv;
160
+ if (name === '') {
161
+ inss.push(objects[i].ins);
162
+ } else {
163
+ inss.push(`${objects[i].ins} - ${name}`);
164
+ }
165
+ }
166
+ }
167
+ $("#instance-search-ins").autocomplete({
168
+ source: inss,
169
+ minLength: 0,
170
+ close: function (event, ui) {
171
+ acceptCheck();
172
+ $("#instance-search-ins").autocomplete('destroy');
173
+ if ($("#instance-search-ins").val().length > 4) {
174
+ $("#instance-search-ins").val($("#instance-search-ins").val().substring(0, 4))
175
+ }
176
+ searchObject.ins = $("#instance-search-ins").val();
177
+ }
178
+ }).autocomplete('search', '');
179
+ }
180
+
181
+ //Function to search for PIDs
182
+ function pidsSearch(objects) {
183
+ searchObject.objects = objects;
184
+ let pids = ['#', '+'];
185
+ for (let i = 0; i < objects.length; i++) {
186
+ pids.push(`${objects[i].pid} - ${objects[i].profileName}`);
187
+ }
188
+ pids = [...new Set(pids)];
189
+ $("#instance-search-pid").autocomplete({
190
+ source: pids,
191
+ minLength: 0,
192
+ close: function (event, ui) {
193
+ acceptCheck();
194
+ $("#instance-search-pid").autocomplete('destroy');
195
+ if ($("#instance-search-pid").val().length > 4) {
196
+ $("#instance-search-pid").val($("#instance-search-pid").val().substring(0, 4))
197
+ }
198
+ searchObject.pid = $("#instance-search-pid").val();
199
+ }
200
+ }).autocomplete('search', '');
201
+ }
202
+
203
+ //Function to search for SIDs, and then fetch child objects based on selection
204
+ function serviceSearch(response) {
205
+ let services = ['#', '+'];
206
+ for (let i = 0; i < response.length; i++) {
207
+ if (response[i].sid !== '009') {
208
+ services.push(`${response[i].sid} - ${response[i].name}`);
209
+ }
210
+ }
211
+ $("#instance-search-sid").autocomplete({
212
+ source: services,
213
+ minLength: 0,
214
+ close: function (event, ui) {
215
+ acceptCheck();
216
+ $("#instance-search-sid").autocomplete('destroy');
217
+ if ($("#instance-search-sid").val().length > 3) {
218
+ $("#instance-search-sid").val($("#instance-search-sid").val().substring(0, 3))
219
+ }
220
+ searchObject.sid = $("#instance-search-sid").val();
221
+ if (searchObject.sid === '+') {
222
+ for (let i = 2; i < services.length; i++) {
223
+ $.getJSON(`mgetobjects?mobius=${mobiusSrvc}&hid=${searchObject.hid}&sid=${services[i].substring(0, 3)}`, (objects) => {
224
+ searchObject.objects = searchObject.objects.concat(objects);
225
+ })
226
+ }
227
+ } else {
228
+ $.getJSON(`mgetobjects?mobius=${mobiusSrvc}&hid=${searchObject.hid}&sid=${searchObject.sid}`, (objects) => {
229
+ searchObject.objects = objects;
230
+ })
231
+ }
232
+ }
233
+ }).autocomplete('search', '');
234
+ }
235
+
236
+ //Start a new search
237
+ function startSearch() {
238
+ $("#wildcard-alert-row").hide();
239
+ $("#instance-search-sid").val('');
240
+ $("#instance-search-pid").val('');
241
+ $("#instance-search-ins").val('');
242
+ searchObject.hid = $("#instance-search-hid").val()
243
+ searchObject.sid = '';
244
+ searchObject.pid = '';
245
+ searchObject.ins = '';
246
+ if (/((^([0-9A-F]){6}$)|^$)/.test(searchObject.hid)) {
247
+ $.getJSON(`mgetservices?mobius=${mobiusSrvc}&hid=${searchObject.hid}`, serviceSearch)
248
+ .fail((err) => {
249
+ console.log('Some kind of html failure message on service discovery');
250
+ });
251
+ }
252
+ }
253
+
254
+ //Finish a search
255
+ function finishSearch() {
256
+ $("#wildcard-alert-row").hide();
257
+ let uri = `${searchObject.hid}/${searchObject.sid}/${searchObject.pid}/${searchObject.ins}`
258
+ if (uri.includes('#')) {
259
+ uri = uri.substring(0,uri.indexOf('#') + 1)
260
+ }
261
+ $("#node-input-instance").val(uri);
262
+ $("#node-search-accept").css('color', '#CCCCCC');
263
+ readyToAccept = false;
264
+ $("#node-search-return").addClass('disabled');
265
+ $("#node-search-accept").addClass('disabled');
266
+ $("#node-lookup-instance").removeClass('disabled');
267
+ $("#instance-search-row").hide();
268
+ $("#instance-row").show();
269
+ }
270
+
271
+ //Function to update if accept button is grade out and functions based on conditions of fields
272
+ function acceptCheck() {
273
+ if (($("#instance-search-hid").val() !== '' && $("#instance-search-sid").val() !== '' && $("#instance-search-pid").val() !== '' && $("#instance-search-ins").val() !== '') ||
274
+ $("#instance-search-sid").val() === '#' || $("#instance-search-pid").val() === '#' || $("#instance-search-ins").val() === '#') {
275
+ $("#node-search-accept").css('color', '#555555');
276
+ readyToAccept = true;
277
+ } else {
278
+ $("#node-search-accept").css('color', '#CCCCCC');
279
+ readyToAccept = false;
280
+ }
281
+ if ($("#instance-search-sid").val() !== '+' && $("#instance-search-pid").val() !== '+') {
282
+ $("#wildcard-alert-row").hide();
283
+ } else {
284
+ $("#wildcard-alert-row").show();
285
+ }
286
+ }
287
+
288
+ // Respond to clicks
289
+ $("#node-lookup-instance").click(function () { //When search button is clicked
290
+ $("#instance-search-sid").val('');
291
+ $("#instance-search-pid").val('');
292
+ $("#instance-search-ins").val('');
293
+ $("#node-lookup-instance").addClass('disabled');
294
+ $("#node-search-return").removeClass('disabled');
295
+ $("#node-search-accept").removeClass('disabled');
296
+ $("#instance-row").hide();
297
+ $("#instance-search-row").show();
298
+ });
299
+ $("#instance-search-sid").click(function () { //SID field clicked
300
+ $("#instance-search-pid").val('')
301
+ $("#instance-search-ins").val('')
302
+ searchObject.pid = '';
303
+ searchObject.ins = '';
304
+ searchObject.objects = [];
305
+ startSearch();
306
+ })
307
+ $("#instance-search-pid").click(function () { //PID field clicked
308
+ $("#instance-search-ins").val('')
309
+ searchObject.ins = '';
310
+ if (searchObject.sid !== '') {
311
+ pidsSearch(searchObject.objects);
312
+ }
313
+ })
314
+ $("#instance-search-ins").click(function () { //INS field clicked
315
+ if (searchObject.pid !== '' && searchObject.pid !== '+' && searchObject.sid !== '+') {
316
+ insSearch(searchObject.objects, searchObject.pid);
317
+ }
318
+ })
319
+ $("#node-search-return").click(function () { //Return/Back button clicked
320
+ $("#node-search-return").addClass('disabled');
321
+ $("#node-search-accept").addClass('disabled');
322
+ $("#node-lookup-instance").removeClass('disabled');
323
+ $("#instance-search-row").hide();
324
+ $("#instance-row").show();
325
+ });
326
+ $("#node-search-accept").click(function () { //Accept button clicked
327
+ if (readyToAccept) {
328
+ finishSearch();
329
+ }
330
+ });
331
+
332
+ // Respond to search field changes
333
+ $("#instance-search-hid").change(function () {
334
+ acceptCheck();
335
+ $("#instance-search-sid").val('');
336
+ $("#instance-search-pid").val('');
337
+ $("#instance-search-ins").val('');
338
+ });
339
+ $("#instance-search-sid").change(function () {
340
+ searchObject.sid = $("#instance-search-sid").val()
341
+ acceptCheck();
342
+ });
343
+ $("#instance-search-pid").change(function () {
344
+ searchObject.pid = $("#instance-search-pid").val()
345
+ acceptCheck();
346
+ });
347
+ $("#instance-search-ins").change(function () {
348
+ searchObject.ins = $("#instance-search-ins").val()
349
+ acceptCheck();
350
+ });
351
+
352
+ // *** MOBSEARCH *** //
353
+ },
103
354
  oneditsave: function() {
104
355
  if($("#node-input-detailedOutput").prop('checked')) {
105
356
  this.outputs = 3;
@@ -29,10 +29,10 @@
29
29
  var _ = require('lodash');
30
30
 
31
31
  module.exports = function (RED) {
32
- function MobiusObjectCovNode (n) {
32
+ function MobiusObjectCovNode(n) {
33
33
  RED.nodes.createNode(this, n);
34
34
  this.detailedOutput = n.detailedOutput;
35
- this.object = n.object;
35
+ this.instance = n.instance;
36
36
  this.format = n.format;
37
37
  this.include = n.include;
38
38
  this.serviceConn = RED.nodes.getNode(n.connection);
@@ -42,16 +42,19 @@ module.exports = function (RED) {
42
42
  node.status({
43
43
  fill: 'red',
44
44
  shape: 'ring',
45
- text: 'Disconnected'
45
+ text: 'Disconnected',
46
46
  });
47
47
 
48
- node.serviceConn.subscribeToObjectCOV(node.object, this.id, (response) => {
48
+ node.serviceConn.subscribeToObjectCOV(node.instance, this.id, (response) => {
49
49
  node.status({
50
50
  fill: 'green',
51
51
  shape: 'dot',
52
- text: JSON.stringify(response.uri)
52
+ text: JSON.stringify(response.uri),
53
53
  });
54
- let allResources = _.keyBy(response.value.resources, node.format === 'name' ? 'name' : 'rid');
54
+ let allResources = _.keyBy(
55
+ response.value.resources,
56
+ node.format === 'name' ? 'name' : 'rid'
57
+ );
55
58
  if (node.include === 'changed') {
56
59
  allResources = _.pickBy(allResources, (res) => {
57
60
  return response.changed.includes(res.rid);
@@ -61,7 +64,7 @@ module.exports = function (RED) {
61
64
  node.send([
62
65
  { topic: response.uri, payload: allResources },
63
66
  { topic: response.uri, payload: response.value },
64
- { topic: response.uri, payload: { response: response } }
67
+ { topic: response.uri, payload: { response: response } },
65
68
  ]);
66
69
  } else {
67
70
  node.send({ topic: response.uri, payload: allResources });