node-red-contrib-mobius-flow-base 2.5.86-beta.69 → 2.5.86-beta.72

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.
@@ -3,24 +3,32 @@
3
3
  * @param mobiusSrvc - Connection to Mobius
4
4
  * @param {object} opts - Options object, field explained below
5
5
 
6
- OPTS OBJECT (opts.)
7
- ALL CASES
8
- htmlElementId - The id of the HTML element that mobsearch will inject into
9
- NON-LISTED ONLY
10
- uriFieldName - The id of the URI HTML field, mobsearch will set the value of this field to be the result
11
- LISTED ONLY (Uses editable list)
12
- containerRowName - The id of the row containing the HTML container
13
- containerName - The id of the HTML container
14
- containerSecondFieldName - The id of the secondary field (Not URI field) within HTML container
15
-
16
- EXAMPLE OPTS OBJECT - context of getMultiResource
6
+ OPTS OBJECT (opts.)
7
+ ALL CASES
8
+ htmlElementId - The id of the HTML element that mobsearch will inject into
9
+ NON-LISTED ONLY
10
+ uriFieldName - The id of the URI HTML field, mobsearch will set the value of this field to be the result
11
+ inputRowId - The id of the main input, mobsearch will add the search button to this row
12
+ LISTED ONLY (Uses editable list)
13
+ list - Array containing current list items in object form
14
+ containerRowName - The id of the row containing the HTML container
15
+ containerName - The id of the HTML container
16
+ containerSecondFieldName - The id of the secondary field (Not URI field) within HTML container
17
+
18
+ EXAMPLE OPTS OBJECT - context of getMultiResource (node using editable list)
17
19
  opts = {
18
20
  htmlElementId: 'mobsearch',
19
21
  list: node.resources,
20
22
  containerRowName: 'node-input-resources-container-row',
21
23
  containerName: 'node-input-resources-container',
22
24
  containerSecondFieldName: 'node-input-resources-comment',
23
- }
25
+ };
26
+ EXAMPLE OPTS OBJECT - context of getResource (standard node, not using editable list)
27
+ opts = {
28
+ htmlElementId: 'mobsearch',
29
+ uriFieldName: 'node-input-resource',
30
+ inputRowId: 'input-row',
31
+ };
24
32
  *
25
33
  *
26
34
  *
@@ -51,9 +59,9 @@ if (typeof selectionIndex === undefined) {
51
59
 
52
60
  /**
53
61
  * function to add search button functionality to list rows
54
- * @param {*} field - The search field within a given list row
55
- * @param {*} rowIndex - The list row index
56
- * @param {*} opts - Mobsearch options object
62
+ * @param {object} field - The search field within a given list row
63
+ * @param {number} rowIndex - The list row index
64
+ * @param {object} opts - Mobsearch options object
57
65
  */
58
66
  function addMobsearchListButton(field, rowIndex, opts) {
59
67
  field.click(function () {
@@ -84,6 +92,8 @@ function getMobsearch(mobiusSrvc, useRid, listed, opts) {
84
92
  uriFieldValue = $(`#${opts.uriFieldName}`).val();
85
93
  }
86
94
 
95
+ console.log(opts.htmlElementId);
96
+
87
97
  // * HTML INJECTION * //
88
98
 
89
99
  const resourceHtml = `
@@ -125,7 +135,7 @@ function getMobsearch(mobiusSrvc, useRid, listed, opts) {
125
135
 
126
136
  if (!listed) {
127
137
  //Add search button
128
- document.getElementById('input-row').innerHTML += `
138
+ document.getElementById(opts.inputRowId).innerHTML += `
129
139
  <a id="node-lookup-instance" class="searchbutton" style="vertical-align: middle"><i id="node-lookup-instance-icon" class="fa fa-search"></i></a>
130
140
  `;
131
141
  }
@@ -33,30 +33,13 @@ POSSIBILITY OF SUCH DAMAGE.
33
33
  <hr>
34
34
 
35
35
  <div id="instance-row">
36
- <div class="form-row">
36
+ <div class="form-row" id="input-row">
37
37
  <label for="node-input-resource"><i class="fa fa-tasks"></i> URI</label>
38
38
  <input type="text" id="node-input-resource" style="width:61%;" placeholder="HID/SID/PID/INS/RID">
39
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
40
  </div>
41
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:13%;" placeholder="HID">
46
- <input type="text" id="instance-search-sid" style="width:8%;" 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
- <input type="text" id="instance-search-rid" style="width:8%;" placeholder="RID">
50
- <a id="node-search-return" class="searchbutton" style="vertical-align: middle"><i id="node-search-return-icon" class="fa fa-arrow-left"></i></a>
51
- <a id="node-search-accept" class="searchbutton" style="vertical-align: middle; color: #CCCCCC"><i id="node-search-accept-icon" class="fa fa-check"></i></a>
52
- </div>
53
- </div>
54
- <div id="wildcard-alert-row" class="form-row hidden" style="color:#555555" align="center">
55
- <p>Please note: The selection of wildcard '+'
56
- means a search for a specific instance or resource
57
- cannot be performed. As such, enter the
58
- INS and/or RID manually.</p>
59
- </div>
42
+ <div id="mobsearch"></div>
60
43
 
61
44
  <div class="form-row">
62
45
  <label for="node-input-priority"><i class="fa fa-exclamation-triangle"></i> Priority</label>
@@ -74,6 +57,8 @@ POSSIBILITY OF SUCH DAMAGE.
74
57
  </div>
75
58
  </script>
76
59
 
60
+ <script src="common/mobsearch.js"></script>
61
+
77
62
  <script type="text/javascript">
78
63
  RED.nodes.registerType('mobius clear resource',{
79
64
  category: 'mobius',
@@ -119,261 +104,12 @@ POSSIBILITY OF SUCH DAMAGE.
119
104
  var node = this;
120
105
  let mobiusSrvc = $("#node-input-connection").val();
121
106
 
122
- // *** MOBSEARCH *** //
123
-
124
- //Inital setup
125
- $("#instance-search-row").hide();
126
- $("#wildcard-alert-row").hide();
127
- $("#node-search-return").addClass('disabled');
128
- $.getJSON(`mgethid?mobius=${mobiusSrvc}`, function (response) {
129
- $("#instance-search-hid").val(response);
130
- })
131
- let readyToAccept = false;
132
- let searchObject = {
133
- hid: $("#instance-search-hid").val(),
134
- sid: $("#instance-search-sid").val(),
135
- pid: $("#instance-search-pid").val(),
136
- ins: $("#instance-search-ins").val(),
137
- rid: $("#instance-search-rid").val(),
138
- objects: []
139
- }
140
-
141
- //Function to search for RIDs
142
- function ridSearch (objects, ins) {
143
- $.getJSON(`mdiscover?mobius=${mobiusSrvc}&uri=${searchObject.hid}/${searchObject.sid}/${searchObject.pid}/${searchObject.ins}`, (response) => {
144
- resList = response.value[0].resources
145
- ress = ['#'];
146
- for (let j = 0; j < resList.length; j++) {
147
- ress.push(`${resList[j].rid} - ${resList[j].name}`)
148
- }
149
- $("#instance-search-rid").autocomplete({
150
- source: ress,
151
- minLength: 0,
152
- close: function (event, ui) {
153
- acceptCheck();
154
- $("#instance-search-rid").autocomplete('destroy');
155
- $("#instance-search-rid").val($("#instance-search-rid").val().substring(0, 2));
156
- searchObject.rid = $("#instance-search-rid").val();
157
- }
158
- }).autocomplete('search', '');
159
- })
160
- }
161
-
162
- //Function to search for INSs
163
- function insSearch (objects, pid) {
164
- let inss = ['#', '+'];
165
- for (let i = 0; i < objects.length; i++) {
166
- if (objects[i].pid === pid) {
167
- const name = objects[i].resources[1].pv;
168
- if (name === '') {
169
- inss.push(objects[i].ins);
170
- } else {
171
- inss.push(`${objects[i].ins} - ${name}`);
172
- }
173
- }
174
- }
175
- $("#instance-search-ins").autocomplete({
176
- source: inss,
177
- minLength: 0,
178
- close: function (event, ui) {
179
- acceptCheck();
180
- $("#instance-search-ins").autocomplete('destroy');
181
- if ($("#instance-search-ins").val().length > 4) {
182
- $("#instance-search-ins").val($("#instance-search-ins").val().substring(0, 4))
183
- }
184
- searchObject.ins = $("#instance-search-ins").val();
185
- }
186
- }).autocomplete('search', '');
187
- }
188
-
189
- //Function to search for PIDs
190
- function pidsSearch(objects) {
191
- searchObject.objects = objects;
192
- let pids = ['#', '+'];
193
- for (let i = 0; i < objects.length; i++) {
194
- pids.push(`${objects[i].pid} - ${objects[i].profileName}`);
195
- }
196
- pids = [...new Set(pids)];
197
- $("#instance-search-pid").autocomplete({
198
- source: pids,
199
- minLength: 0,
200
- close: function (event, ui) {
201
- acceptCheck();
202
- $("#instance-search-pid").autocomplete('destroy');
203
- if ($("#instance-search-pid").val().length > 4) {
204
- $("#instance-search-pid").val($("#instance-search-pid").val().substring(0, 4))
205
- }
206
- searchObject.pid = $("#instance-search-pid").val();
207
- }
208
- }).autocomplete('search', '');
209
- }
210
-
211
- //Function to search for SIDs, and then fetch child objects based on selection
212
- function serviceSearch(response) {
213
- let services = ['#', '+'];
214
- for (let i = 0; i < response.length; i++) {
215
- if (response[i].sid !== '009') {
216
- services.push(`${response[i].sid} - ${response[i].name}`);
217
- }
218
- }
219
- $("#instance-search-sid").autocomplete({
220
- source: services,
221
- minLength: 0,
222
- close: function (event, ui) {
223
- acceptCheck();
224
- $("#instance-search-sid").autocomplete('destroy');
225
- if ($("#instance-search-sid").val().length > 3) {
226
- $("#instance-search-sid").val($("#instance-search-sid").val().substring(0, 3))
227
- }
228
- searchObject.sid = $("#instance-search-sid").val();
229
- if (searchObject.sid === '+') {
230
- for (let i = 2; i < services.length; i++) {
231
- $.getJSON(`mgetobjects?mobius=${mobiusSrvc}&hid=${searchObject.hid}&sid=${services[i].substring(0, 3)}`, (objects) => {
232
- searchObject.objects = searchObject.objects.concat(objects);
233
- })
234
- }
235
- } else {
236
- $.getJSON(`mgetobjects?mobius=${mobiusSrvc}&hid=${searchObject.hid}&sid=${searchObject.sid}`, (objects) => {
237
- searchObject.objects = objects;
238
- })
239
- }
240
- }
241
- }).autocomplete('search', '');
242
- }
243
-
244
- //Start a new search
245
- function startSearch() {
246
- $("#wildcard-alert-row").hide();
247
- $("#instance-search-sid").val('');
248
- $("#instance-search-pid").val('');
249
- $("#instance-search-ins").val('');
250
- searchObject.hid = $("#instance-search-hid").val()
251
- searchObject.sid = '';
252
- searchObject.pid = '';
253
- searchObject.ins = '';
254
- if (/((^([0-9A-F]){6}$)|^$)/.test(searchObject.hid)) {
255
- $.getJSON(`mgetservices?mobius=${mobiusSrvc}&hid=${searchObject.hid}`, serviceSearch)
256
- .fail((err) => {
257
- console.log('Some kind of html failure message on service discovery');
258
- });
259
- }
260
- }
261
-
262
- //Finish a search
263
- function finishSearch() {
264
- $("#wildcard-alert-row").hide();
265
- let uri = `${searchObject.hid}/${searchObject.sid}/${searchObject.pid}/${searchObject.ins}/${searchObject.rid}`
266
- if (uri.includes('#')) {
267
- uri = uri.substring(0,uri.indexOf('#') + 1)
268
- }
269
- $("#node-input-resource").val(uri);
270
- $("#node-search-accept").css('color', '#CCCCCC');
271
- readyToAccept = false;
272
- $("#node-search-return").addClass('disabled');
273
- $("#node-search-accept").addClass('disabled');
274
- $("#node-lookup-instance").removeClass('disabled');
275
- $("#instance-search-row").hide();
276
- $("#instance-row").show();
277
- }
278
-
279
- //Function to update if accept button is grade out and functions based on conditions of fields
280
- function acceptCheck() {
281
- if (($("#instance-search-hid").val() !== '' && $("#instance-search-sid").val() !== '' && $("#instance-search-pid").val() !== '' && $("#instance-search-ins").val() !== '' && $("#instance-search-rid").val() !== '') ||
282
- $("#instance-search-sid").val() === '#' || $("#instance-search-pid").val() === '#' || $("#instance-search-ins").val() === '#' || $("#instance-search-rid").val() === '#') {
283
- $("#node-search-accept").css('color', '#555555');
284
- readyToAccept = true;
285
- } else {
286
- $("#node-search-accept").css('color', '#CCCCCC');
287
- readyToAccept = false;
288
- }
289
- if ($("#instance-search-sid").val() !== '+' && $("#instance-search-pid").val() !== '+' && $("#instance-search-ins").val() !== '+') {
290
- $("#wildcard-alert-row").hide();
291
- } else {
292
- $("#wildcard-alert-row").show();
293
- }
294
- }
295
-
296
- // Respond to clicks
297
- $("#node-lookup-instance").click(function () { //When search button is clicked
298
- $("#instance-search-sid").val('');
299
- $("#instance-search-pid").val('');
300
- $("#instance-search-ins").val('');
301
- $("#instance-search-rid").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
- $("#instance-search-sid").click(function () { //SID field clicked
309
- $("#instance-search-pid").val('')
310
- $("#instance-search-ins").val('')
311
- searchObject.pid = '';
312
- searchObject.ins = '';
313
- searchObject.rid = '';
314
- searchObject.objects = [];
315
- startSearch();
316
- })
317
- $("#instance-search-pid").click(function () { //PID field clicked
318
- $("#instance-search-ins").val('')
319
- $("#instance-search-rid").val('')
320
- searchObject.ins = '';
321
- searchObject.rid = '';
322
- if (searchObject.sid !== '') {
323
- pidsSearch(searchObject.objects);
324
- }
325
- })
326
- $("#instance-search-ins").click(function () { //INS field clicked
327
- $("#instance-search-rid").val('')
328
- searchObject.rid = '';
329
- if (searchObject.pid !== '' && searchObject.pid !== '+' && searchObject.sid !== '+') {
330
- insSearch(searchObject.objects, searchObject.pid);
331
- }
332
- })
333
- $("#instance-search-rid").click(function () { //RID clicked
334
- if (searchObject.ins !== '' && searchObject.ins !== '+' && searchObject.pid !== '+' && searchObject.sid !== '+') {
335
- ridSearch(searchObject.objects, searchObject.ins);
336
- }
337
- });
338
- $("#node-search-return").click(function () { //Return/Back button clicked
339
- $("#node-search-return").addClass('disabled');
340
- $("#node-search-accept").addClass('disabled');
341
- $("#node-lookup-instance").removeClass('disabled');
342
- $("#instance-search-row").hide();
343
- $("#instance-row").show();
344
- });
345
- $("#node-search-accept").click(function () { //Accept button clicked
346
- if (readyToAccept) {
347
- finishSearch();
348
- }
349
- });
350
-
351
- // Respond to search field changes
352
- $("#instance-search-hid").change(function () {
353
- acceptCheck();
354
- $("#instance-search-sid").val('');
355
- $("#instance-search-pid").val('');
356
- $("#instance-search-ins").val('');
357
- $("#instance-search-rid").val('');
358
- });
359
- $("#instance-search-sid").change(function () {
360
- searchObject.sid = $("#instance-search-sid").val()
361
- acceptCheck();
362
- });
363
- $("#instance-search-pid").change(function () {
364
- searchObject.pid = $("#instance-search-pid").val()
365
- acceptCheck();
366
- });
367
- $("#instance-search-ins").change(function () {
368
- searchObject.ins = $("#instance-search-ins").val()
369
- acceptCheck();
370
- });
371
- $("#instance-search-rid").change(function () {
372
- searchObject.rid = $("#instance-search-rid").val()
373
- acceptCheck();
374
- });
375
-
376
- // *** MOBSEARCH *** //
107
+ opts = {
108
+ htmlElementId: 'mobsearch',
109
+ uriFieldName: 'node-input-resource',
110
+ inputRowId: 'input-row',
111
+ };
112
+ initMobsearch.toRid(mobiusSrvc, opts);
377
113
  },
378
114
  oneditsave: function() {
379
115
  if($("#node-input-detailedOutput").prop('checked')) {
@@ -28,7 +28,7 @@
28
28
  'use strict';
29
29
 
30
30
  module.exports = function (RED) {
31
- function MobiusClearResourceNode (n) {
31
+ function MobiusClearResourceNode(n) {
32
32
  RED.nodes.createNode(this, n);
33
33
  this.detailedOutput = n.detailedOutput;
34
34
  this.resource = n.resource;
@@ -40,7 +40,7 @@ module.exports = function (RED) {
40
40
  node.status({
41
41
  fill: 'red',
42
42
  shape: 'ring',
43
- text: 'Disconnected'
43
+ text: 'Disconnected',
44
44
  });
45
45
 
46
46
  node.on('input', function (msg) {
@@ -57,7 +57,7 @@ module.exports = function (RED) {
57
57
  node.status({
58
58
  fill: 'green',
59
59
  shape: 'ring',
60
- text: 'Busy'
60
+ text: 'Busy',
61
61
  });
62
62
 
63
63
  node.serviceConn.clearResourcePriority(uri, pri, (err, response) => {
@@ -65,29 +65,34 @@ module.exports = function (RED) {
65
65
  node.status({
66
66
  fill: 'yellow',
67
67
  shape: 'dot',
68
- text: 'Error: ' + JSON.stringify(err.code)
68
+ text: 'Error: ' + JSON.stringify(err.code),
69
69
  });
70
70
  node.error('Mobius error clearing resource priority ' + JSON.stringify(err));
71
71
  if (node.detailedOutput === true) {
72
- node.send([null, null, null, {topic: uri, payload: { error: true, response: err }}]);
72
+ node.send([
73
+ null,
74
+ null,
75
+ null,
76
+ { topic: uri, payload: { error: true, response: err } },
77
+ ]);
73
78
  }
74
79
  } else {
75
80
  node.status({
76
81
  fill: 'green',
77
82
  shape: 'dot',
78
- text: JSON.stringify(response.value.pv)
83
+ text: JSON.stringify(response.value.pv),
79
84
  });
80
85
  if (node.detailedOutput === true) {
81
86
  node.send([
82
87
  { topic: uri, payload: response.value.pv },
83
88
  { topic: uri, payload: { pv: response.value.pv, name: response.value.name } },
84
89
  { topic: uri, payload: response.value },
85
- { topic: uri, payload: { error: false, response: response } }
90
+ { topic: uri, payload: { error: false, response: response } },
86
91
  ]);
87
92
  } else {
88
93
  node.send([
89
94
  { topic: uri, payload: response.value.pv },
90
- { topic: uri, payload: { pv: response.value.pv, name: response.value.name } }
95
+ { topic: uri, payload: { pv: response.value.pv, name: response.value.name } },
91
96
  ]);
92
97
  }
93
98
  }
@@ -106,4 +111,12 @@ module.exports = function (RED) {
106
111
  }
107
112
 
108
113
  RED.nodes.registerType('mobius clear resource', MobiusClearResourceNode);
114
+
115
+ RED.httpAdmin.get('/common/*', function (req, res) {
116
+ var options = {
117
+ root: __dirname + '/common/',
118
+ dotfiles: 'deny',
119
+ };
120
+ res.sendFile(req.params[0], options);
121
+ });
109
122
  };