@bitpoolos/edge-bacnet 1.3.2 → 1.4.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.
@@ -147,16 +147,19 @@
147
147
  .optionParent {
148
148
  display: flex;
149
149
  }
150
- .injectHeading > a {
150
+
151
+ .injectHeading>a {
151
152
  margin: 0;
152
153
  font-weight: 600;
153
154
  font-size: 14px;
154
155
  }
156
+
155
157
  .injectHeading {
156
158
  border-bottom: 1px solid #cbcbcb;
157
159
  text-align: start;
158
160
  height: 30px;
159
161
  }
162
+
160
163
  .checkbox-round {
161
164
  width: 13px !important;
162
165
  height: 13px !important;
@@ -169,12 +172,15 @@
169
172
  outline: none;
170
173
  cursor: pointer;
171
174
  }
175
+
172
176
  .checkbox-round:checked {
173
177
  background-color: #00AEEF;
174
178
  }
179
+
175
180
  .checkbox-round:focus {
176
181
  outline: none !important;
177
182
  }
183
+
178
184
  .msgOptions {
179
185
  border: 1px solid #cbcbcb;
180
186
  border-radius: 4px;
@@ -187,22 +193,26 @@
187
193
  cursor: pointer;
188
194
  width: 50%;
189
195
  }
196
+
190
197
  .msgOptions:hover {
191
198
  border: 1px solid #00AEEF;
192
199
  transition: 1s;
193
200
  background-color: #f5fcff;
194
201
  }
202
+
195
203
  .discoverOption {
196
204
  margin-top: 15px;
197
205
  width: 180px;
198
206
  margin-right: 20px;
199
207
  margin-left: auto;
200
208
  }
209
+
201
210
  .pollOption {
202
211
  margin-top: 15px;
203
212
  width: 180px;
204
213
  margin-right: auto;
205
214
  }
215
+
206
216
  .optionsSelector {
207
217
  min-height: 90px !important;
208
218
  max-height: none !important;
@@ -210,12 +220,12 @@
210
220
  flex-direction: column;
211
221
  flex-wrap: nowrap;
212
222
  justify-content: space-around;
213
- }
223
+ }
214
224
 
215
- .bitpoolInjectList > .red-ui-editableList > .red-ui-editableList-container {
225
+ .bitpoolInjectList>.red-ui-editableList>.red-ui-editableList-container {
216
226
  min-height: 120px !important;
217
227
  max-height: none;
218
- overflow-y: scroll;
228
+ overflow-y: scroll;
219
229
  height: 410px !important;
220
230
  }
221
231
 
@@ -224,9 +234,11 @@
224
234
  .inject-time-row {
225
235
  padding-left: 110px;
226
236
  }
237
+
227
238
  .inject-time-row select {
228
239
  margin: 3px 0;
229
240
  }
241
+
230
242
  .inject-time-days label {
231
243
  -webkit-user-select: none;
232
244
  -khtml-user-select: none;
@@ -236,18 +248,22 @@
236
248
  vertical-align: baseline;
237
249
  width: 100px;
238
250
  }
251
+
239
252
  .inject-time-days input {
240
253
  width: auto !important;
241
254
  vertical-align: baseline !important;
242
255
  }
256
+
243
257
  .inject-time-times {
244
258
  width: 90px !important;
245
259
  }
260
+
246
261
  #inject-time-time {
247
262
  width: 75px;
248
263
  margin-left: 8px;
249
264
  margin-bottom: 8px;
250
265
  }
266
+
251
267
  .inject-time-count {
252
268
  padding-left: 3px !important;
253
269
  width: 80px !important;
@@ -255,520 +271,534 @@
255
271
  </style>
256
272
 
257
273
  <script type="text/javascript">
258
- (function() {
259
-
260
- function resizeDialog(size) {
261
- size = size || { height: $(".red-ui-tray-content form").height() }
262
- var rows = $("#dialog-form>div:not(.node-input-property-container-row):visible");
263
- var height = size.height;
264
- for (var i=0; i<rows.length; i++) {
265
- height -= $(rows[i]).outerHeight(true);
266
- }
267
- var editorRow = $("#dialog-form>div.node-input-property-container-row");
268
- height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
269
- height += 16;
270
- $("#node-input-property-container").editableList('height',height);
271
- }
272
- /** Retrieve editableList items (refactored for re-use in the form inject button)*/
273
- function getProps(el, legacy) {
274
- var result = {
275
- props: []
276
- }
277
- el.each(function(i) {
278
- var prop = $(this);
279
- var p = {
280
- p:prop.find(".node-input-prop-property-name").typedInput('value')
281
- };
282
- if (p.p) {
283
- p.v = prop.find(".node-input-prop-property-value").typedInput('value');
284
- p.vt = prop.find(".node-input-prop-property-value").typedInput('type');
285
- if(legacy) {
286
- if (p.p === "payload") { // save payload to old "legacy" property
287
- result.payloadType = p.vt;
288
- result.payload = p.v;
289
- delete p.v;
290
- delete p.vt;
291
- } else if (p.p === "topic" && p.vt === "str") {
292
- result.topic = p.v;
293
- delete p.v;
294
- }
295
- }
296
- result.props.push(p);
274
+ (function () {
275
+
276
+ function resizeDialog(size) {
277
+ size = size || { height: $(".red-ui-tray-content form").height() }
278
+ var rows = $("#dialog-form>div:not(.node-input-property-container-row):visible");
279
+ var height = size.height;
280
+ for (var i = 0; i < rows.length; i++) {
281
+ height -= $(rows[i]).outerHeight(true);
297
282
  }
298
- });
299
- return result;
300
- }
301
- /** Perform inject, optionally sending a custom msg (refactored for re-use in the form inject button)*/
302
- function doInject(node, customMsg) {
303
- var label = node._def.label.call(node,customMsg?customMsg.__user_inject_props__:undefined);
304
- if (label.length > 30) {
305
- label = label.substring(0, 50) + "...";
283
+ var editorRow = $("#dialog-form>div.node-input-property-container-row");
284
+ height -= (parseInt(editorRow.css("marginTop")) + parseInt(editorRow.css("marginBottom")));
285
+ height += 16;
286
+ $("#node-input-property-container").editableList('height', height);
306
287
  }
307
- label = label.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
308
- $.ajax({
309
- url: "inject/" + node.id,
310
- type: "POST",
311
- data: JSON.stringify(customMsg||{}),
312
- contentType: "application/json; charset=utf-8",
313
- success: function (resp) {
314
- RED.notify(node._("inject.success", { label: label }), { type: "success", id: "inject", timeout: 2000 });
315
- },
316
- error: function (jqXHR, textStatus, errorThrown) {
317
- if (jqXHR.status == 404) {
318
- RED.notify(node._("common.notification.error", { message: node._("common.notification.errors.not-deployed") }), "error");
319
- } else if (jqXHR.status == 500) {
320
- RED.notify(node._("common.notification.error", { message: node._("inject.errors.failed") }), "error");
321
- } else if (jqXHR.status == 0) {
322
- RED.notify(node._("common.notification.error", { message: node._("common.notification.errors.no-response") }), "error");
323
- } else {
324
- RED.notify(node._("common.notification.error", { message: node._("common.notification.errors.unexpected", { status: jqXHR.status, message: textStatus }) }), "error");
325
- }
288
+ /** Retrieve editableList items (refactored for re-use in the form inject button)*/
289
+ function getProps(el, legacy) {
290
+ var result = {
291
+ props: []
326
292
  }
327
- });
328
- }
329
- RED.nodes.registerType('Bitpool-Inject',{
330
- category: 'Bitpool BACnet',
331
- color: '#00aeef',
332
- defaults: {
333
- name: {value:""},
334
- props:{value:[{p:"payload"},{p:"topic",vt:"str"}], validate:function(v) {
335
- if (!v || v.length === 0) { return true }
336
- for (var i=0;i<v.length;i++) {
337
- if (/msg|flow|global/.test(v[i].vt)) {
338
- if (!RED.utils.validatePropertyExpression(v[i].v)) {
339
- return false;
340
- }
341
- } else if (v[i].vt === "jsonata") {
342
- try{jsonata(v[i].v);}catch(e){return false;}
343
- } else if (v[i].vt === "json") {
344
- try{JSON.parse(v[i].v);}catch(e){return false;}
293
+ el.each(function (i) {
294
+ var prop = $(this);
295
+ var p = {
296
+ p: prop.find(".node-input-prop-property-name").typedInput('value')
297
+ };
298
+ if (p.p) {
299
+ p.v = prop.find(".node-input-prop-property-value").typedInput('value');
300
+ p.vt = prop.find(".node-input-prop-property-value").typedInput('type');
301
+ if (legacy) {
302
+ if (p.p === "payload") { // save payload to old "legacy" property
303
+ result.payloadType = p.vt;
304
+ result.payload = p.v;
305
+ delete p.v;
306
+ delete p.vt;
307
+ } else if (p.p === "topic" && p.vt === "str") {
308
+ result.topic = p.v;
309
+ delete p.v;
345
310
  }
346
311
  }
347
- return true;
312
+ result.props.push(p);
348
313
  }
349
- },
350
- repeat: {value:"", validate:function(v) { return ((v === "") || (RED.validators.number(v) && (v >= 0) && (v <= 2147483))) }},
351
- crontab: {value:""},
352
- once: {value:false},
353
- onceDelay: {value:0.1},
354
- topic: {value:""},
355
- payload: {value:"", validate: RED.validators.typedInput("payloadType")},
356
- payloadType: {value:"date"},
357
- doPoll: {value:true},
358
- doDiscover: {value: false},
359
- },
360
- icon: "bitpool.svg",
361
- inputs:0,
362
- outputs:1,
363
- outputLabels: function(index) {
364
- var lab = '';
365
-
366
- // if only payload and topic - display payload type
367
- // if only one property - show it's type
368
- // if more than one property (other than payload and topic) - show "x properties" where x is the number of properties.
369
- // this.props will not be an array for legacy inject nodes until they are re-deployed
370
- //
371
- var props = this.props;
372
- if (!Array.isArray(props)) {
373
- props = [
374
- { p:"payload", v: this.payload, vt: this.payloadType },
375
- { p:"topic", v: this.topic, vt: "str" }
376
- ]
314
+ });
315
+ return result;
316
+ }
317
+ /** Perform inject, optionally sending a custom msg (refactored for re-use in the form inject button)*/
318
+ function doInject(node, customMsg) {
319
+ var label = node._def.label.call(node, customMsg ? customMsg.__user_inject_props__ : undefined);
320
+ if (label.length > 30) {
321
+ label = label.substring(0, 50) + "...";
377
322
  }
378
- if (props) {
379
- for (var i=0,l=props.length; i<l; i++) {
380
- if (i > 0) lab += "\n";
381
- if (i === 5) {
382
- lab += "... +"+(props.length-5);
383
- break;
323
+ label = label.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
324
+ $.ajax({
325
+ url: "inject/" + node.id,
326
+ type: "POST",
327
+ data: JSON.stringify(customMsg || {}),
328
+ contentType: "application/json; charset=utf-8",
329
+ success: function (resp) {
330
+ RED.notify(node._("inject.success", { label: label }), { type: "success", id: "inject", timeout: 2000 });
331
+ },
332
+ error: function (jqXHR, textStatus, errorThrown) {
333
+ if (jqXHR.status == 404) {
334
+ RED.notify(node._("common.notification.error", { message: node._("common.notification.errors.not-deployed") }), "error");
335
+ } else if (jqXHR.status == 500) {
336
+ RED.notify(node._("common.notification.error", { message: node._("inject.errors.failed") }), "error");
337
+ } else if (jqXHR.status == 0) {
338
+ RED.notify(node._("common.notification.error", { message: node._("common.notification.errors.no-response") }), "error");
339
+ } else {
340
+ RED.notify(node._("common.notification.error", { message: node._("common.notification.errors.unexpected", { status: jqXHR.status, message: textStatus }) }), "error");
384
341
  }
385
- lab += props[i].p+": ";
386
-
387
- var propType = props[i].p === "payload"? this.payloadType : props[i].vt;
388
- if (propType === "json") {
389
- try {
390
- var parsedProp = JSON.parse(props[i].p === "payload"? this.payload : props[i].v);
391
- propType = typeof parsedProp;
392
- if (propType === "object" && Array.isArray(parsedProp)) {
393
- propType = "Array";
342
+ }
343
+ });
344
+ }
345
+ RED.nodes.registerType('Bitpool-Inject', {
346
+ category: 'Bitpool BACnet',
347
+ color: '#00aeef',
348
+ defaults: {
349
+ name: { value: "" },
350
+ props: {
351
+ value: [{ p: "payload" }, { p: "topic", vt: "str" }], validate: function (v) {
352
+ if (!v || v.length === 0) { return true }
353
+ for (var i = 0; i < v.length; i++) {
354
+ if (/msg|flow|global/.test(v[i].vt)) {
355
+ if (!RED.utils.validatePropertyExpression(v[i].v)) {
356
+ return false;
357
+ }
358
+ } else if (v[i].vt === "jsonata") {
359
+ try { jsonata(v[i].v); } catch (e) { return false; }
360
+ } else if (v[i].vt === "json") {
361
+ try { JSON.parse(v[i].v); } catch (e) { return false; }
394
362
  }
395
- } catch(e) {
396
- propType = "invalid";
397
363
  }
364
+ return true;
398
365
  }
399
- lab += this._("inject.label."+propType);
366
+ },
367
+ repeat: { value: "", validate: function (v) { return ((v === "") || (RED.validators.number(v) && (v >= 0) && (v <= 2147483))) } },
368
+ crontab: { value: "" },
369
+ once: { value: false },
370
+ onceDelay: { value: 0.1 },
371
+ topic: { value: "" },
372
+ payload: { value: "", validate: RED.validators.typedInput("payloadType") },
373
+ payloadType: { value: "date" },
374
+ doPoll: { value: true },
375
+ doDiscover: { value: false },
376
+ },
377
+ icon: "bitpool.svg",
378
+ inputs: 0,
379
+ outputs: 1,
380
+ outputLabels: function (index) {
381
+ var lab = '';
382
+
383
+ // if only payload and topic - display payload type
384
+ // if only one property - show it's type
385
+ // if more than one property (other than payload and topic) - show "x properties" where x is the number of properties.
386
+ // this.props will not be an array for legacy inject nodes until they are re-deployed
387
+ //
388
+ var props = this.props;
389
+ if (!Array.isArray(props)) {
390
+ props = [
391
+ { p: "payload", v: this.payload, vt: this.payloadType },
392
+ { p: "topic", v: this.topic, vt: "str" }
393
+ ]
400
394
  }
401
- }
402
- return lab;
403
- },
404
- paletteLabel: function () {
405
- return "inject";
406
- },
407
- label: function(customProps) {
408
- return this.name || "inject";
409
- },
410
- labelStyle: function() {
411
- return this.name?"node_label_italic":"";
412
- },
413
- oneditprepare: function() {
414
- var node = this;
415
- var payloadType = node.payloadType;
416
-
417
- if (node.payloadType == null) {
418
- if (node.payload == "") {
419
- payloadType = "date";
420
- } else {
421
- payloadType = "str";
395
+ if (props) {
396
+ for (var i = 0, l = props.length; i < l; i++) {
397
+ if (i > 0) lab += "\n";
398
+ if (i === 5) {
399
+ lab += "... +" + (props.length - 5);
400
+ break;
401
+ }
402
+ lab += props[i].p + ": ";
403
+
404
+ var propType = props[i].p === "payload" ? this.payloadType : props[i].vt;
405
+ if (propType === "json") {
406
+ try {
407
+ var parsedProp = JSON.parse(props[i].p === "payload" ? this.payload : props[i].v);
408
+ propType = typeof parsedProp;
409
+ if (propType === "object" && Array.isArray(parsedProp)) {
410
+ propType = "Array";
411
+ }
412
+ } catch (e) {
413
+ propType = "invalid";
414
+ }
415
+ }
416
+ lab += this._("inject.label." + propType);
417
+ }
422
418
  }
423
- } else if (node.payloadType === 'string' || node.payloadType === 'none') {
424
- payloadType = "str";
425
- }
419
+ return lab;
420
+ },
421
+ paletteLabel: function () {
422
+ return "inject";
423
+ },
424
+ label: function (customProps) {
425
+ return this.name || "inject";
426
+ },
427
+ labelStyle: function () {
428
+ return this.name ? "node_label_italic" : "";
429
+ },
430
+ oneditprepare: function () {
431
+ var node = this;
432
+ var payloadType = node.payloadType;
426
433
 
427
- $("#inject-time-type-select").on("change", function() {
428
- $("#node-input-crontab").val('');
429
- var id = $("#inject-time-type-select").val();
430
- $(".inject-time-row").hide();
431
- $("#inject-time-row-"+id).show();
432
- if ((id == "none") || (id == "interval") || (id == "interval-time")) {
433
- $("#node-once").show();
434
- }
435
- else {
436
- $("#node-once").hide();
437
- $("#node-input-once").prop('checked', false);
434
+ if (node.payloadType == null) {
435
+ if (node.payload == "") {
436
+ payloadType = "date";
437
+ } else {
438
+ payloadType = "str";
439
+ }
440
+ } else if (node.payloadType === 'string' || node.payloadType === 'none') {
441
+ payloadType = "str";
438
442
  }
439
443
 
440
- // Scroll down
441
- var scrollDiv = $("#dialog-form").parent();
442
- scrollDiv.scrollTop(scrollDiv.prop('scrollHeight'));
443
- resizeDialog();
444
- });
445
-
446
- $("#node-input-once").on("change", function() {
447
- $("#node-input-onceDelay").attr('disabled', !$("#node-input-once").prop('checked'));
448
- })
449
-
450
- $(".inject-time-times").each(function() {
451
- for (var i=0; i<24; i++) {
452
- var l = (i<10?"0":"")+i+":00";
453
- $(this).append($("<option></option>").val(i).text(l));
454
- }
455
- });
456
- $("<option></option>").val(24).text("00:00").appendTo("#inject-time-interval-time-end");
457
- $("#inject-time-interval-time-start").on("change", function() {
458
- var start = Number($("#inject-time-interval-time-start").val());
459
- var end = Number($("#inject-time-interval-time-end").val());
460
- $("#inject-time-interval-time-end option").remove();
461
- for (var i=start+1; i<25; i++) {
462
- var l = (i<10?"0":"")+i+":00";
463
- if (i==24) {
464
- l = "00:00";
444
+ $("#inject-time-type-select").on("change", function () {
445
+ $("#node-input-crontab").val('');
446
+ var id = $("#inject-time-type-select").val();
447
+ $(".inject-time-row").hide();
448
+ $("#inject-time-row-" + id).show();
449
+ if ((id == "none") || (id == "interval") || (id == "interval-time")) {
450
+ $("#node-once").show();
465
451
  }
466
- var opt = $("<option></option>").val(i).text(l).appendTo("#inject-time-interval-time-end");
467
- if (i === end) {
468
- opt.attr("selected","selected");
452
+ else {
453
+ $("#node-once").hide();
454
+ $("#node-input-once").prop('checked', false);
469
455
  }
470
- }
471
- });
472
456
 
473
- $(".inject-time-count").spinner({
474
- //max:60,
475
- min:1
476
- });
457
+ // Scroll down
458
+ var scrollDiv = $("#dialog-form").parent();
459
+ scrollDiv.scrollTop(scrollDiv.prop('scrollHeight'));
460
+ resizeDialog();
461
+ });
477
462
 
478
- var repeattype = "none";
479
- if (node.repeat != "" && node.repeat != 0) {
480
- repeattype = "interval";
481
- var r = "s";
482
- var c = node.repeat;
483
- if (node.repeat % 60 === 0) { r = "m"; c = c/60; }
484
- if (node.repeat % 1440 === 0) { r = "h"; c = c/60; }
485
- $("#inject-time-interval-count").val(c);
486
- $("#inject-time-interval-units").val(r);
487
- $("#inject-time-interval-days").prop("disabled","disabled");
488
- } else if (node.crontab) {
489
- var cronparts = node.crontab.split(" ");
490
- var days = cronparts[4];
491
- if (!isNaN(cronparts[0]) && !isNaN(cronparts[1])) {
492
- repeattype = "time";
493
- // Fixed time
494
- var time = cronparts[1]+":"+cronparts[0];
495
- $("#inject-time-time").val(time);
496
- $("#inject-time-type-select").val("s");
497
- if (days == "*") {
498
- $("#inject-time-time-days input[type=checkbox]").prop("checked",true);
499
- } else {
500
- $("#inject-time-time-days input[type=checkbox]").removeAttr("checked");
501
- days.split(",").forEach(function(v) {
502
- $("#inject-time-time-days [value=" + v + "]").prop("checked", true);
503
- });
463
+ $("#node-input-once").on("change", function () {
464
+ $("#node-input-onceDelay").attr('disabled', !$("#node-input-once").prop('checked'));
465
+ })
466
+
467
+ $(".inject-time-times").each(function () {
468
+ for (var i = 0; i < 24; i++) {
469
+ var l = (i < 10 ? "0" : "") + i + ":00";
470
+ $(this).append($("<option></option>").val(i).text(l));
504
471
  }
505
- } else {
506
- repeattype = "interval-time";
507
- // interval - time period
508
- var minutes = cronparts[0].slice(2);
509
- if (minutes === "") { minutes = "0"; }
510
- $("#inject-time-interval-time-units").val(minutes);
511
- if (days == "*") {
512
- $("#inject-time-interval-time-days input[type=checkbox]").prop("checked",true);
513
- } else {
514
- $("#inject-time-interval-time-days input[type=checkbox]").removeAttr("checked");
515
- days.split(",").forEach(function(v) {
516
- $("#inject-time-interval-time-days [value=" + v + "]").prop("checked", true);
517
- });
472
+ });
473
+ $("<option></option>").val(24).text("00:00").appendTo("#inject-time-interval-time-end");
474
+ $("#inject-time-interval-time-start").on("change", function () {
475
+ var start = Number($("#inject-time-interval-time-start").val());
476
+ var end = Number($("#inject-time-interval-time-end").val());
477
+ $("#inject-time-interval-time-end option").remove();
478
+ for (var i = start + 1; i < 25; i++) {
479
+ var l = (i < 10 ? "0" : "") + i + ":00";
480
+ if (i == 24) {
481
+ l = "00:00";
482
+ }
483
+ var opt = $("<option></option>").val(i).text(l).appendTo("#inject-time-interval-time-end");
484
+ if (i === end) {
485
+ opt.attr("selected", "selected");
486
+ }
518
487
  }
519
- var time = cronparts[1];
520
- var timeparts = time.split(",");
521
- var start;
522
- var end;
523
- if (timeparts.length == 1) {
524
- // 0 or 0-10
525
- var hours = timeparts[0].split("-");
526
- if (hours.length == 1) {
527
- if (hours[0] === "") {
528
- start = "0";
529
- end = "0";
530
- }
531
- else {
532
- start = hours[0];
533
- end = Number(hours[0])+1;
534
- }
488
+ });
489
+
490
+ $(".inject-time-count").spinner({
491
+ //max:60,
492
+ min: 1
493
+ });
494
+
495
+ var repeattype = "none";
496
+ if (node.repeat != "" && node.repeat != 0) {
497
+ repeattype = "interval";
498
+ var r = "s";
499
+ var c = node.repeat;
500
+ if (node.repeat % 60 === 0) { r = "m"; c = c / 60; }
501
+ if (node.repeat % 1440 === 0) { r = "h"; c = c / 60; }
502
+ $("#inject-time-interval-count").val(c);
503
+ $("#inject-time-interval-units").val(r);
504
+ $("#inject-time-interval-days").prop("disabled", "disabled");
505
+ } else if (node.crontab) {
506
+ var cronparts = node.crontab.split(" ");
507
+ var days = cronparts[4];
508
+ if (!isNaN(cronparts[0]) && !isNaN(cronparts[1])) {
509
+ repeattype = "time";
510
+ // Fixed time
511
+ var time = cronparts[1] + ":" + cronparts[0];
512
+ $("#inject-time-time").val(time);
513
+ $("#inject-time-type-select").val("s");
514
+ if (days == "*") {
515
+ $("#inject-time-time-days input[type=checkbox]").prop("checked", true);
535
516
  } else {
536
- start = hours[0];
537
- end = Number(hours[1])+1;
517
+ $("#inject-time-time-days input[type=checkbox]").removeAttr("checked");
518
+ days.split(",").forEach(function (v) {
519
+ $("#inject-time-time-days [value=" + v + "]").prop("checked", true);
520
+ });
538
521
  }
539
522
  } else {
540
- // 23,0 or 17-23,0-10 or 23,0-2 or 17-23,0
541
- var startparts = timeparts[0].split("-");
542
- start = startparts[0];
543
-
544
- var endparts = timeparts[1].split("-");
545
- if (endparts.length == 1) {
546
- end = Number(endparts[0])+1;
523
+ repeattype = "interval-time";
524
+ // interval - time period
525
+ var minutes = cronparts[0].slice(2);
526
+ if (minutes === "") { minutes = "0"; }
527
+ $("#inject-time-interval-time-units").val(minutes);
528
+ if (days == "*") {
529
+ $("#inject-time-interval-time-days input[type=checkbox]").prop("checked", true);
547
530
  } else {
548
- end = Number(endparts[1])+1;
531
+ $("#inject-time-interval-time-days input[type=checkbox]").removeAttr("checked");
532
+ days.split(",").forEach(function (v) {
533
+ $("#inject-time-interval-time-days [value=" + v + "]").prop("checked", true);
534
+ });
549
535
  }
550
- }
551
- $("#inject-time-interval-time-end").val(end);
552
- $("#inject-time-interval-time-start").val(start);
536
+ var time = cronparts[1];
537
+ var timeparts = time.split(",");
538
+ var start;
539
+ var end;
540
+ if (timeparts.length == 1) {
541
+ // 0 or 0-10
542
+ var hours = timeparts[0].split("-");
543
+ if (hours.length == 1) {
544
+ if (hours[0] === "") {
545
+ start = "0";
546
+ end = "0";
547
+ }
548
+ else {
549
+ start = hours[0];
550
+ end = Number(hours[0]) + 1;
551
+ }
552
+ } else {
553
+ start = hours[0];
554
+ end = Number(hours[1]) + 1;
555
+ }
556
+ } else {
557
+ // 23,0 or 17-23,0-10 or 23,0-2 or 17-23,0
558
+ var startparts = timeparts[0].split("-");
559
+ start = startparts[0];
560
+
561
+ var endparts = timeparts[1].split("-");
562
+ if (endparts.length == 1) {
563
+ end = Number(endparts[0]) + 1;
564
+ } else {
565
+ end = Number(endparts[1]) + 1;
566
+ }
567
+ }
568
+ $("#inject-time-interval-time-end").val(end);
569
+ $("#inject-time-interval-time-start").val(start);
553
570
 
571
+ }
572
+ } else {
573
+ $("#inject-time-type-select").val("none");
554
574
  }
555
- } else {
556
- $("#inject-time-type-select").val("none");
557
- }
558
575
 
559
- $(".inject-time-row").hide();
560
- $("#inject-time-type-select").val(repeattype);
561
- $("#inject-time-row-"+repeattype).show();
562
-
563
- /* */
564
-
565
- var eList = $('#node-input-property-container-list').css('min-height','120px').css('min-width','450px');
566
- var eList2 = $('#node-input-property-container').css('min-height','120px').css('min-width','450px');
567
-
568
- eList2.editableList({
569
- buttons: [
570
- {
571
- id: "node-inject-test-inject-button",
572
- label: node._("inject.injectNow"),
573
- click: function(e) {
574
- var items = eList2.editableList('items');
575
- var props = getProps(items);
576
- var m = {__user_inject_props__: props.props};
577
- doInject(node, m);
576
+ $(".inject-time-row").hide();
577
+ $("#inject-time-type-select").val(repeattype);
578
+ $("#inject-time-row-" + repeattype).show();
579
+
580
+ /* */
581
+
582
+ var eList = $('#node-input-property-container-list').css('min-height', '120px').css('min-width', '450px');
583
+ var eList2 = $('#node-input-property-container').css('min-height', '120px').css('min-width', '450px');
584
+
585
+ eList2.editableList({
586
+ buttons: [
587
+ {
588
+ id: "node-inject-test-inject-button",
589
+ label: node._("inject.injectNow"),
590
+ click: function (e) {
591
+ var items = eList2.editableList('items');
592
+ var props = getProps(items);
593
+ var m = { __user_inject_props__: props.props };
594
+ doInject(node, m);
595
+ }
578
596
  }
579
- }
580
- ],
581
- addItem: function(container,i,opt) {
582
- var prop = opt;
583
- if (!prop.hasOwnProperty('p')) {
584
- prop = {p:"",v:"",vt:"str"};
585
- }
586
- container.css({
587
- overflow: 'hidden',
588
- whiteSpace: 'nowrap'
589
- });
590
- var row = $('<div/>').appendTo(container);
591
-
592
- var propertyName = $('<input/>',{class:"node-input-prop-property-name",type:"text"})
593
- .css("width","30%")
594
- .appendTo(row)
595
- .typedInput({types:['msg']});
596
-
597
- $('<div/>',{style: 'display:inline-block; padding:0px 6px;'})
598
- .text('=')
599
- .appendTo(row);
600
-
601
- var propertyValue = $('<input/>',{class:"node-input-prop-property-value",type:"text"})
602
- .css("width","calc(70% - 30px)")
603
- .appendTo(row)
604
- .typedInput({default:prop.vt || 'str',types:['flow','global','str','num','bool','json','bin','date','jsonata','env','msg']});
605
-
606
- propertyName.typedInput('value',prop.p);
607
- propertyValue.typedInput('value',prop.v);
608
- },
609
- removable: true,
610
- sortable: true
611
- });
597
+ ],
598
+ addItem: function (container, i, opt) {
599
+ var prop = opt;
600
+ if (!prop.hasOwnProperty('p')) {
601
+ prop = { p: "", v: "", vt: "str" };
602
+ }
603
+ container.css({
604
+ overflow: 'hidden',
605
+ whiteSpace: 'nowrap'
606
+ });
607
+ var row = $('<div/>').appendTo(container);
612
608
 
613
- $('#node-inject-test-inject-button').css("float", "right").css("margin-right", "unset");
609
+ var propertyName = $('<input/>', { class: "node-input-prop-property-name", type: "text" })
610
+ .css("width", "30%")
611
+ .appendTo(row)
612
+ .typedInput({ types: ['msg'] });
614
613
 
615
- if (RED.nodes.subflow(node.z)) {
616
- $('#node-inject-test-inject-button').attr("disabled",true);
617
- }
614
+ $('<div/>', { style: 'display:inline-block; padding:0px 6px;' })
615
+ .text('=')
616
+ .appendTo(row);
618
617
 
619
- if (!node.props) {
620
- var payload = {
621
- p:'payload',
622
- v: node.payload ? node.payload : '',
623
- vt:payloadType ? payloadType : 'date'
624
- };
625
- var topic = {
626
- p:'topic',
627
- v: node.topic ? node.topic : '',
628
- vt:'str'
618
+ var propertyValue = $('<input/>', { class: "node-input-prop-property-value", type: "text" })
619
+ .css("width", "calc(70% - 30px)")
620
+ .appendTo(row)
621
+ .typedInput({ default: prop.vt || 'str', types: ['flow', 'global', 'str', 'num', 'bool', 'json', 'bin', 'date', 'jsonata', 'env', 'msg'] });
622
+
623
+ propertyName.typedInput('value', prop.p);
624
+ propertyValue.typedInput('value', prop.v);
625
+ },
626
+ removable: true,
627
+ sortable: true
628
+ });
629
+
630
+ $('#node-inject-test-inject-button').css("float", "right").css("margin-right", "unset");
631
+
632
+ if (RED.nodes.subflow(node.z)) {
633
+ $('#node-inject-test-inject-button').attr("disabled", true);
629
634
  }
630
- node.props = [payload,topic];
631
- }
632
635
 
633
- for (var i=0; i<node.props.length; i++) {
634
- var prop = node.props[i];
635
- var newProp = { p: prop.p, v: prop.v, vt: prop.vt };
636
- if (newProp.v === undefined) {
637
- if (prop.p === 'payload') {
638
- newProp.v = node.payload ? node.payload : '';
639
- newProp.vt = payloadType ? payloadType : 'date';
640
- } else if (prop.p === 'topic' && prop.vt === "str") {
641
- newProp.v = node.topic ? node.topic : '';
636
+ if (!node.props) {
637
+ var payload = {
638
+ p: 'payload',
639
+ v: node.payload ? node.payload : '',
640
+ vt: payloadType ? payloadType : 'date'
641
+ };
642
+ var topic = {
643
+ p: 'topic',
644
+ v: node.topic ? node.topic : '',
645
+ vt: 'str'
642
646
  }
647
+ node.props = [payload, topic];
643
648
  }
644
- if (newProp.vt === "string") {
645
- // Fix bug in pre 2.1 where an old Inject node might have
646
- // a migrated rule with type 'string' not 'str'
647
- newProp.vt = "str";
649
+
650
+ for (var i = 0; i < node.props.length; i++) {
651
+ var prop = node.props[i];
652
+ var newProp = { p: prop.p, v: prop.v, vt: prop.vt };
653
+ if (newProp.v === undefined) {
654
+ if (prop.p === 'payload') {
655
+ newProp.v = node.payload ? node.payload : '';
656
+ newProp.vt = payloadType ? payloadType : 'date';
657
+ } else if (prop.p === 'topic' && prop.vt === "str") {
658
+ newProp.v = node.topic ? node.topic : '';
659
+ }
660
+ }
661
+ if (newProp.vt === "string") {
662
+ // Fix bug in pre 2.1 where an old Inject node might have
663
+ // a migrated rule with type 'string' not 'str'
664
+ newProp.vt = "str";
665
+ }
666
+ eList2.editableList('addItem', newProp);
648
667
  }
649
- eList2.editableList('addItem',newProp);
650
- }
651
668
 
652
- $("#inject-time-type-select").trigger("change");
653
- $("#inject-time-interval-time-start").trigger("change");
654
-
655
- },
656
- oneditsave: function() {
657
- var repeat = "";
658
- var crontab = "";
659
- var type = $("#inject-time-type-select").val();
660
- if (type == "none") {
661
- // nothing
662
- } else if (type == "interval") {
663
- var count = $("#inject-time-interval-count").val();
664
- var units = $("#inject-time-interval-units").val();
665
- if (units == "s") {
666
- repeat = count;
667
- } else {
668
- if (units == "m") {
669
- //crontab = "*/"+count+" * * * "+days;
670
- repeat = count * 60;
671
- } else if (units == "h") {
672
- //crontab = "0 */"+count+" * * "+days;
673
- repeat = count * 60 * 60;
669
+ $("#inject-time-type-select").trigger("change");
670
+ $("#inject-time-interval-time-start").trigger("change");
671
+
672
+
673
+ document.getElementById("node-input-doDiscover").onclick = handleCheckboxClick;
674
+ document.getElementById("node-input-doPoll").onclick = handleCheckboxClick;
675
+
676
+ function handleCheckboxClick() {
677
+ if (this.id == "node-input-doDiscover") {
678
+ document.getElementById("node-input-doPoll").checked = false;
679
+ }
680
+ if (this.id == "node-input-doPoll") {
681
+ document.getElementById("node-input-doDiscover").checked = false;
674
682
  }
675
683
  }
676
- } else if (type == "interval-time") {
677
- repeat = "";
678
- var count = $("#inject-time-interval-time-units").val();
679
- var startTime = Number($("#inject-time-interval-time-start").val());
680
- var endTime = Number($("#inject-time-interval-time-end").val());
681
- var days = $('#inject-time-interval-time-days input[type=checkbox]:checked').map(function(_, el) {
682
- return $(el).val()
683
- }).get();
684
- if (days.length == 0) {
685
- crontab = "";
686
- } else {
687
- if (days.length == 7) {
688
- days="*";
684
+
685
+ },
686
+ oneditsave: function () {
687
+ var repeat = "";
688
+ var crontab = "";
689
+ var type = $("#inject-time-type-select").val();
690
+ if (type == "none") {
691
+ // nothing
692
+ } else if (type == "interval") {
693
+ var count = $("#inject-time-interval-count").val();
694
+ var units = $("#inject-time-interval-units").val();
695
+ if (units == "s") {
696
+ repeat = count;
689
697
  } else {
690
- days = days.join(",");
698
+ if (units == "m") {
699
+ //crontab = "*/"+count+" * * * "+days;
700
+ repeat = count * 60;
701
+ } else if (units == "h") {
702
+ //crontab = "0 */"+count+" * * "+days;
703
+ repeat = count * 60 * 60;
704
+ }
691
705
  }
692
- var timerange = "";
693
- if (endTime == 0) {
694
- timerange = startTime+"-23";
695
- } else if (startTime+1 < endTime) {
696
- timerange = startTime+"-"+(endTime-1);
697
- } else if (startTime+1 == endTime) {
698
- timerange = startTime;
706
+ } else if (type == "interval-time") {
707
+ repeat = "";
708
+ var count = $("#inject-time-interval-time-units").val();
709
+ var startTime = Number($("#inject-time-interval-time-start").val());
710
+ var endTime = Number($("#inject-time-interval-time-end").val());
711
+ var days = $('#inject-time-interval-time-days input[type=checkbox]:checked').map(function (_, el) {
712
+ return $(el).val()
713
+ }).get();
714
+ if (days.length == 0) {
715
+ crontab = "";
699
716
  } else {
700
- var startpart = "";
701
- var endpart = "";
702
- if (startTime == 23) {
703
- startpart = "23";
717
+ if (days.length == 7) {
718
+ days = "*";
704
719
  } else {
705
- startpart = startTime+"-23";
720
+ days = days.join(",");
706
721
  }
707
- if (endTime == 1) {
708
- endpart = "0";
722
+ var timerange = "";
723
+ if (endTime == 0) {
724
+ timerange = startTime + "-23";
725
+ } else if (startTime + 1 < endTime) {
726
+ timerange = startTime + "-" + (endTime - 1);
727
+ } else if (startTime + 1 == endTime) {
728
+ timerange = startTime;
709
729
  } else {
710
- endpart = "0-"+(endTime-1);
730
+ var startpart = "";
731
+ var endpart = "";
732
+ if (startTime == 23) {
733
+ startpart = "23";
734
+ } else {
735
+ startpart = startTime + "-23";
736
+ }
737
+ if (endTime == 1) {
738
+ endpart = "0";
739
+ } else {
740
+ endpart = "0-" + (endTime - 1);
741
+ }
742
+ timerange = startpart + "," + endpart;
743
+ }
744
+ if (count === "0") {
745
+ crontab = count + " " + timerange + " * * " + days;
746
+ } else {
747
+ crontab = "*/" + count + " " + timerange + " * * " + days;
711
748
  }
712
- timerange = startpart+","+endpart;
713
- }
714
- if (count === "0") {
715
- crontab = count+" "+timerange+" * * "+days;
716
- } else {
717
- crontab = "*/"+count+" "+timerange+" * * "+days;
718
749
  }
719
- }
720
- } else if (type == "time") {
721
- var time = $("#inject-time-time").val();
722
- var days = $('#inject-time-time-days input[type=checkbox]:checked').map(function(_, el) {
723
- return $(el).val()
724
- }).get();
725
- if (days.length == 0) {
726
- crontab = "";
727
- } else {
728
- if (days.length == 7) {
729
- days="*";
750
+ } else if (type == "time") {
751
+ var time = $("#inject-time-time").val();
752
+ var days = $('#inject-time-time-days input[type=checkbox]:checked').map(function (_, el) {
753
+ return $(el).val()
754
+ }).get();
755
+ if (days.length == 0) {
756
+ crontab = "";
730
757
  } else {
731
- days = days.join(",");
732
- }
733
- var parts = time.split(":");
734
- if (parts.length === 2) {
735
- repeat = "";
736
- parts[1] = ("00" + (parseInt(parts[1]) % 60)).substr(-2);
737
- parts[0] = ("00" + (parseInt(parts[0]) % 24)).substr(-2);
738
- crontab = parts[1]+" "+parts[0]+" * * "+days;
758
+ if (days.length == 7) {
759
+ days = "*";
760
+ } else {
761
+ days = days.join(",");
762
+ }
763
+ var parts = time.split(":");
764
+ if (parts.length === 2) {
765
+ repeat = "";
766
+ parts[1] = ("00" + (parseInt(parts[1]) % 60)).substr(-2);
767
+ parts[0] = ("00" + (parseInt(parts[0]) % 24)).substr(-2);
768
+ crontab = parts[1] + " " + parts[0] + " * * " + days;
769
+ }
770
+ else { crontab = ""; }
739
771
  }
740
- else { crontab = ""; }
741
772
  }
742
- }
743
773
 
744
- $("#node-input-repeat").val(repeat);
745
- $("#node-input-crontab").val(crontab);
746
-
747
- /* Gather the properties */
748
- var items = $("#node-input-property-container").editableList('items');
749
- delete this.payloadType;
750
- delete this.payload;
751
- this.topic = "";
752
- var result = getProps(items, true);
753
- this.props = result.props;
754
- if(result.hasOwnProperty('payloadType')) { this.payloadType = result.payloadType; };
755
- if(result.hasOwnProperty('payload')) { this.payload = result.payload; };
756
- if(result.hasOwnProperty('topic')) { this.topic = result.topic; };
757
- },
758
- button: {
759
- enabled: function() {
760
- return !this.changed
774
+ $("#node-input-repeat").val(repeat);
775
+ $("#node-input-crontab").val(crontab);
776
+
777
+ /* Gather the properties */
778
+ var items = $("#node-input-property-container").editableList('items');
779
+ delete this.payloadType;
780
+ delete this.payload;
781
+ this.topic = "";
782
+ var result = getProps(items, true);
783
+ this.props = result.props;
784
+ if (result.hasOwnProperty('payloadType')) { this.payloadType = result.payloadType; };
785
+ if (result.hasOwnProperty('payload')) { this.payload = result.payload; };
786
+ if (result.hasOwnProperty('topic')) { this.topic = result.topic; };
761
787
  },
762
- onclick: function () {
763
- if (this.changed) {
764
- return RED.notify(RED._("notification.warning", { message: RED._("notification.warnings.undeployedChanges") }), "warning");
788
+ button: {
789
+ enabled: function () {
790
+ return !this.changed
791
+ },
792
+ onclick: function () {
793
+ if (this.changed) {
794
+ return RED.notify(RED._("notification.warning", { message: RED._("notification.warnings.undeployedChanges") }), "warning");
795
+ }
796
+ doInject(this);
765
797
  }
766
- doInject(this);
767
- }
768
- },
769
- oneditresize: resizeDialog
770
- });
771
- })();
798
+ },
799
+ oneditresize: resizeDialog
800
+ });
801
+ })();
772
802
  </script>
773
803
 
774
804
  <script type="text/html" data-help-name="Bitpool-Inject">