node-red-contrib-mobius-flow-base 2.5.86-beta.23 → 2.5.86-beta.27

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.
@@ -661,4 +661,14 @@ module.exports = function (RED) {
661
661
  });
662
662
  }
663
663
  });
664
+
665
+ RED.httpAdmin.get('/mgethid', RED.auth.needsPermission('serial.read'), function (req, res) {
666
+ let conn = RED.nodes.getNode(req.query.mobius);
667
+ if (conn === null || !conn.service.connected) {
668
+ RED.log.error('Get hid failed - could not to connect to MOBiUS hub.');
669
+ throw new Error('Get hid failed - could not to connect to MOBiUS hub.');
670
+ } else {
671
+ res.json(conn.service.srvcAPI.status.hubId);
672
+ }
673
+ });
664
674
  };
@@ -29,18 +29,44 @@ 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-mobject"><i class="fa fa-tasks"></i> URI</label>
34
- <input type="text" id="node-input-mobject" placeholder="Object URI (hid/sid/pid/ins)">
32
+ <div id="instance-message-row" class="form-row hidden" style="color:#ff0000" align="center">
33
+ <p>To select a configured object from a drop-down list, <br/>
34
+ please create a MOBiUS connection, deploy the flow, and <br />
35
+ ensure that the node-red-connector service is running. <br />
36
+ Click the Confirm Deploy button if asked.</p>
35
37
  </div>
36
- <div class="form-row">
38
+ <div id="instance-row">
39
+ <div class="form-row">
40
+ <label for="node-input-instance"><i class="fa fa-tasks"></i> URI</label>
41
+ <input type="text" id="node-input-instance" style="width:61%;" placeholder="HID/SID/PID/INS (optional name)">
42
+ <a id="node-lookup-instance" class="searchbutton" style="vertical-align: middle"><i id="node-lookup-instance-icon" class="fa fa-search"></i></a>
43
+ </div>
44
+ </div>
45
+ <div id="instance-search-row">
46
+ <div class="form-row">
47
+ <label for="instance-search-sid"><i class="fa fa-tasks"></i> URI</label>
48
+ <input type="text" id="instance-search-hid" style="width:15%;" placeholder="HID">
49
+ <input type="text" id="instance-search-sid" style="width:10%;" placeholder="SID">
50
+ <input type="text" id="instance-search-pid" style="width:10%;" placeholder="PID">
51
+ <input type="text" id="instance-search-ins" style="width:10%;" placeholder="INS">
52
+ <a id="node-search-return" class="searchbutton" style="vertical-align: middle"><i id="node-search-return-icon" class="fa fa-arrow-left"></i></a>
53
+ <a id="node-search-accept" class="searchbutton" style="vertical-align: middle"><i id="node-search-accept-icon" class="fa fa-check"></i></a>
54
+ </div>
55
+ </div>
56
+ <div id="wildcard-alert-row" class="form-row hidden" style="color:#555555" align="center">
57
+ <p>Please note: The selection of wildcard '+'
58
+ means a search for a specific instance or resource
59
+ cannot be performed. As such, enter the
60
+ INS manually.</p>
61
+ </div>
62
+ <div id="node-input-format-row" class="form-row">
37
63
  <label for="node-input-format"><i class="fa fa-bars"></i> Format</label>
38
64
  <select type="text" id="node-input-format" style="display: inline-block; width: auto; vertical-align: center;">
39
65
  <option value="name">By Name</option>
40
66
  <option value="rid">By RID</option>
41
67
  </select>
42
68
  </div>
43
- <div class="form-row">
69
+ <div id="node-input-detailedOutput-row" class="form-row">
44
70
  <label>&nbsp;</label>
45
71
  <input type="checkbox" id="node-input-detailedOutput" style="display: inline-block; width: auto; vertical-align: top;">
46
72
  <label for="node-input-detailedOutput" style="width: 70%;"> Use detailed outputs</label>
@@ -60,7 +86,7 @@ POSSIBILITY OF SUCH DAMAGE.
60
86
  name: {value: ""},
61
87
  detailedOutput: {value:false},
62
88
  format: {value: "name", required: true},
63
- mobject: {value: "", validate:function(v) {
89
+ instance: {value: "", validate:function(v) {
64
90
  if(v === '') { return true; }
65
91
  let parts = v.split('/');
66
92
  for(let lp = 0; lp < parts.length; lp++) {
@@ -86,12 +112,260 @@ POSSIBILITY OF SUCH DAMAGE.
86
112
  if(this.name) {
87
113
  return this.name;
88
114
  } else {
89
- return this.mobject ? `Get - ${this.mobject}` : "get object";
115
+ return this.instance ? `Get - ${this.instance}` : "get object";
90
116
  }
91
117
  },
92
118
  labelStyle: function() {
93
119
  return this.name ? "node_label_italic":"";
94
120
  },
121
+ oneditprepare: function () {
122
+
123
+ var node = this;
124
+ let mobiusSrvc = $("#node-input-connection").val();
125
+
126
+ $("#instance-search-row").hide();
127
+
128
+ function doesMobiusServiceExist() {
129
+ let srvc = $("#node-input-mobius").val();
130
+ if (srvc === '_ADD_') {
131
+ $("#node-lookup-instance").hide();
132
+ $("#instance-message-row").show();
133
+ } else {
134
+ $("#instance-message-row").hide();
135
+ $("#node-lookup-instance").show();
136
+ }
137
+ }
138
+ doesMobiusServiceExist();
139
+
140
+ $("#node-search-return").addClass('disabled');
141
+
142
+ // *** MOBSEARCH *** //
143
+
144
+ //Inital setup
145
+ $("#instance-search-row").hide();
146
+ $("#wildcard-alert-row").hide();
147
+ $("#node-search-return").addClass('disabled');
148
+ $.getJSON(`mgethid?mobius=${mobiusSrvc}`, function (response) {
149
+ $("#instance-search-hid").val(response);
150
+ })
151
+ let readyToAccept = false;
152
+ let searchObject = {
153
+ hid: $("#instance-search-hid").val(),
154
+ sid: $("#instance-search-sid").val(),
155
+ pid: $("#instance-search-pid").val(),
156
+ ins: $("#instance-search-ins").val(),
157
+ objects: []
158
+ }
159
+
160
+ //Function to search for INSs
161
+ function insSearch (objects, pid) {
162
+ let inss = ['#'];
163
+ for (let i = 0; i < objects.length; i++) {
164
+ if (objects[i].pid === pid) {
165
+ const name = objects[i].resources[1].pv;
166
+ if (name === '') {
167
+ inss.push(objects[i].ins);
168
+ } else {
169
+ inss.push(`${objects[i].ins} - ${name}`);
170
+ }
171
+ }
172
+ }
173
+ $("#instance-search-ins").autocomplete({
174
+ source: inss,
175
+ minLength: 0,
176
+ close: function (event, ui) {
177
+ acceptCheck();
178
+ $("#instance-search-ins").autocomplete('destroy');
179
+ if ($("#instance-search-ins").val().length > 4) {
180
+ $("#instance-search-ins").val($("#instance-search-ins").val().substring(0, 4))
181
+ }
182
+ searchObject.ins = $("#instance-search-ins").val();
183
+ }
184
+ }).autocomplete('search', '');
185
+ }
186
+
187
+ //Function to search for PIDs
188
+ function pidsSearch(objects) {
189
+ searchObject.objects = objects;
190
+ let pids = ['#', '+'];
191
+ for (let i = 0; i < objects.length; i++) {
192
+ pids.push(`${objects[i].pid} - ${objects[i].profileName}`);
193
+ }
194
+ pids = [...new Set(pids)];
195
+ $("#instance-search-pid").autocomplete({
196
+ source: pids,
197
+ minLength: 0,
198
+ close: function (event, ui) {
199
+ acceptCheck();
200
+ $("#instance-search-pid").autocomplete('destroy');
201
+ if ($("#instance-search-pid").val().length > 4) {
202
+ $("#instance-search-pid").val($("#instance-search-pid").val().substring(0, 4))
203
+ }
204
+ searchObject.pid = $("#instance-search-pid").val();
205
+ }
206
+ }).autocomplete('search', '');
207
+ }
208
+
209
+ //Function to search for SIDs, and then fetch child objects based on selection
210
+ function serviceSearch(response) {
211
+ let services = ['#', '+'];
212
+ for (let i = 0; i < response.length; i++) {
213
+ if (response[i].sid !== '009') {
214
+ services.push(`${response[i].sid} - ${response[i].name}`);
215
+ }
216
+ }
217
+ $("#instance-search-sid").autocomplete({
218
+ source: services,
219
+ minLength: 0,
220
+ close: function (event, ui) {
221
+ acceptCheck();
222
+ $("#instance-search-sid").autocomplete('destroy');
223
+ if ($("#instance-search-sid").val().length > 3) {
224
+ $("#instance-search-sid").val($("#instance-search-sid").val().substring(0, 3))
225
+ }
226
+ searchObject.sid = $("#instance-search-sid").val();
227
+ if (searchObject.sid === '+') {
228
+ for (let i = 2; i < services.length; i++) {
229
+ $.getJSON(`mgetobjects?mobius=${mobiusSrvc}&hid=${searchObject.hid}&sid=${services[i].substring(0, 3)}`, (objects) => {
230
+ searchObject.objects = searchObject.objects.concat(objects);
231
+ })
232
+ }
233
+ } else {
234
+ $.getJSON(`mgetobjects?mobius=${mobiusSrvc}&hid=${searchObject.hid}&sid=${searchObject.sid}`, (objects) => {
235
+ searchObject.objects = objects;
236
+ })
237
+ }
238
+ }
239
+ }).autocomplete('search', '');
240
+ }
241
+
242
+ //Start a new search
243
+ function startSearch() {
244
+ $("#wildcard-alert-row").hide();
245
+ $("#instance-search-sid").val('');
246
+ $("#instance-search-pid").val('');
247
+ $("#instance-search-ins").val('');
248
+ searchObject.hid = $("#instance-search-hid").val()
249
+ searchObject.sid = '';
250
+ searchObject.pid = '';
251
+ searchObject.ins = '';
252
+ if (/((^([0-9A-F]){6}$)|^$)/.test(searchObject.hid)) {
253
+ $.getJSON(`mgetservices?mobius=${mobiusSrvc}&hid=${searchObject.hid}`, serviceSearch)
254
+ .fail((err) => {
255
+ console.log('Some kind of html failure message on service discovery');
256
+ });
257
+ }
258
+ }
259
+
260
+ //Finish a search
261
+ function finishSearch() {
262
+ $("#wildcard-alert-row").hide();
263
+ let uri = `${searchObject.hid}/${searchObject.sid}/${searchObject.pid}/${searchObject.ins}`
264
+ if (uri.includes('#')) {
265
+ uri = uri.substring(0,uri.indexOf('#') + 1)
266
+ }
267
+ $("#node-input-instance").val(uri);
268
+ $("#node-search-accept").css('color', '#CCCCCC');
269
+ readyToAccept = false;
270
+ $("#node-search-return").addClass('disabled');
271
+ $("#node-search-accept").addClass('disabled');
272
+ $("#node-lookup-instance").removeClass('disabled');
273
+ $("#instance-search-row").hide();
274
+ $("#instance-row").show();
275
+
276
+ $("#node-input-format-row").show();
277
+ $("#node-input-detailedOutput-row").show();
278
+ }
279
+
280
+ //Function to update if accept button is grade out and functions based on conditions of fields
281
+ function acceptCheck() {
282
+ if (($("#instance-search-hid").val() !== '' && $("#instance-search-sid").val() !== '' && $("#instance-search-pid").val() !== '' && $("#instance-search-ins").val() !== '') ||
283
+ $("#instance-search-sid").val() === '#' || $("#instance-search-pid").val() === '#' || $("#instance-search-ins").val() === '#') {
284
+ $("#node-search-accept").css('color', '#555555');
285
+ readyToAccept = true;
286
+ } else {
287
+ $("#node-search-accept").css('color', '#CCCCCC');
288
+ readyToAccept = false;
289
+ }
290
+ if ($("#instance-search-sid").val() !== '+' && $("#instance-search-pid").val() !== '+') {
291
+ $("#wildcard-alert-row").hide();
292
+ } else {
293
+ $("#wildcard-alert-row").show();
294
+ }
295
+ }
296
+
297
+ // Respond to clicks
298
+ $("#node-lookup-instance").click(function () { //When search button is clicked
299
+ $("#instance-search-sid").val('');
300
+ $("#instance-search-pid").val('');
301
+ $("#instance-search-ins").val('');
302
+ $("#node-lookup-instance").addClass('disabled');
303
+ $("#node-search-return").removeClass('disabled');
304
+ $("#node-search-accept").removeClass('disabled');
305
+ $("#instance-row").hide();
306
+ $("#instance-search-row").show();
307
+
308
+ $("#node-input-format-row").hide();
309
+ $("#node-input-detailedOutput-row").hide();
310
+ });
311
+ $("#instance-search-sid").click(function () { //SID field clicked
312
+ $("#instance-search-pid").val('')
313
+ $("#instance-search-ins").val('')
314
+ searchObject.pid = '';
315
+ searchObject.ins = '';
316
+ searchObject.objects = [];
317
+ startSearch();
318
+ })
319
+ $("#instance-search-pid").click(function () { //PID field clicked
320
+ $("#instance-search-ins").val('')
321
+ searchObject.ins = '';
322
+ if (searchObject.sid !== '') {
323
+ pidsSearch(searchObject.objects);
324
+ }
325
+ })
326
+ $("#instance-search-ins").click(function () { //INS field clicked
327
+ if (searchObject.pid !== '' && searchObject.pid !== '+' && searchObject.sid !== '+') {
328
+ insSearch(searchObject.objects, searchObject.pid);
329
+ }
330
+ })
331
+ $("#node-search-return").click(function () { //Return/Back button clicked
332
+ $("#node-search-return").addClass('disabled');
333
+ $("#node-search-accept").addClass('disabled');
334
+ $("#node-lookup-instance").removeClass('disabled');
335
+ $("#instance-search-row").hide();
336
+ $("#instance-row").show();
337
+
338
+ $("#node-input-format-row").show();
339
+ $("#node-input-detailedOutput-row").show();
340
+ });
341
+ $("#node-search-accept").click(function () { //Accept button clicked
342
+ if (readyToAccept) {
343
+ finishSearch();
344
+ }
345
+ });
346
+
347
+ // Respond to search field changes
348
+ $("#instance-search-hid").change(function () {
349
+ acceptCheck();
350
+ $("#instance-search-sid").val('');
351
+ $("#instance-search-pid").val('');
352
+ $("#instance-search-ins").val('');
353
+ });
354
+ $("#instance-search-sid").change(function () {
355
+ searchObject.sid = $("#instance-search-sid").val()
356
+ acceptCheck();
357
+ });
358
+ $("#instance-search-pid").change(function () {
359
+ searchObject.pid = $("#instance-search-pid").val()
360
+ acceptCheck();
361
+ });
362
+ $("#instance-search-ins").change(function () {
363
+ searchObject.ins = $("#instance-search-ins").val()
364
+ acceptCheck();
365
+ });
366
+
367
+ // *** MOBSEARCH *** //
368
+ },
95
369
  oneditsave: function() {
96
370
  if($("#node-input-detailedOutput").prop('checked')) {
97
371
  this.outputs = 3;
@@ -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 });
@@ -213,23 +213,15 @@ module.exports = {
213
213
  let objectList = [];
214
214
  const serviceResponse = await this.discover(connection, `${hid}/${sid}`);
215
215
  const pids = [...new Set(serviceResponse.value)];
216
- console.log(`pid list is:`);
217
- console.log(pids);
218
- console.log('-.----.-');
219
216
  for (let i = 0; i < pids.length; i++) {
220
217
  const inssResponse = await this.discover(connection, `${hid}/${sid}/${pids[i]}`);
221
218
  const inss = inssResponse.value;
222
- console.log(`inss list for pid ${pids[i]}:`);
223
- console.log(inss);
224
- console.log('-');
225
219
  for (let j = 0; j < inss.length; j++) {
226
- console.log(`Discovering ins ${inss[j]}`);
227
- console.log('.');
228
220
  const objResponse = await this.discover(
229
221
  connection,
230
222
  `${hid}/${sid}/${pids[i]}/${inss[j]}`
231
223
  );
232
- objectList.push(objResponse.value);
224
+ objectList.push(objResponse.value[0]);
233
225
  }
234
226
  }
235
227
  resolve(objectList);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-mobius-flow-base",
3
- "version": "2.5.86-beta.23",
3
+ "version": "2.5.86-beta.27",
4
4
  "description": "Node-RED base nodes for Mobius Flow",
5
5
  "main": "index.js",
6
6
  "types": "dist/index.d.ts",