Node-Red configuration
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <script type="text/x-red" data-help-name="Logger">
  2. <p>
  3. Log message for a set number of times before turning off.
  4. Allows for dynamic traces without the need to deploy.
  5. Prevents console and log being flood by loads of messages be having a set limit.
  6. </p>
  7. </script>
  8. <script type="text/x-red" data-template-name="Logger">
  9. <div class="form-row">
  10. <label for="node-input-name"><i class="fa fa-tag"></i> Name </label>
  11. <input type="text" id="node-input-name" placeholder="Name">
  12. </div>
  13. <div class="form-row">
  14. <label for="node-input-count"><i class="fa fa-tag"></i> Number of messages </label>
  15. <input type="number" min="1" max="100000" step="10" id="node-input-count">
  16. </div>
  17. <div class="form-row">
  18. <input type="checkbox" id="node-input-sendOutputLog" style="display: inline-block; width: auto; vertical-align: top;">
  19. <label for="node-input-sendOutputLog" style="width: auto">Send to log port</label>
  20. </div>
  21. <div class="form-row">
  22. <input type="checkbox" id="node-input-active" style="display: inline-block; width: auto; vertical-align: top;">
  23. <label for="node-input-active" style="width: auto">Initially On</label>
  24. </div>
  25. <div class="form-row">
  26. <input type="checkbox" id="node-input-sendConsoleLog" style="display: inline-block; width: auto; vertical-align: top;">
  27. <label for="node-input-sendConsoleLog" style="width: auto">Send to debug console</label>
  28. </div>
  29. </script>
  30. <script type="text/javascript">
  31. const nodeName="Logger";
  32. RED.nodes.registerType(nodeName,{
  33. category: 'function',
  34. defaults: {
  35. name: {value:"",required:false},
  36. count: {value:100,required:true},
  37. sendOutputLog: {value:false,required:true},
  38. sendConsoleLog: {value:false,required:true},
  39. active: {value:true,required:true}
  40. },
  41. inputs:1,
  42. inputLabels: "Message",
  43. outputs:2,
  44. outputLabels: ["Out","Log"],
  45. icon: "setting.png",
  46. label: function() {
  47. return this.name||this._(nodeName);
  48. },
  49. labelStyle: function() {
  50. return "node_label_italic";
  51. },
  52. oneditprepare: function() {
  53. if(typeof this.sendOutputLog === 'undefined') {
  54. this.sendOutputLog = false;
  55. $("#node-config-input-sendOutputLog").prop("checked",false);
  56. }
  57. if(typeof this.sendConsoleLog === 'undefined') {
  58. this.sendConsoleLog = false;
  59. $("#node-config-input-sendConsoleLog").prop("checked",false);
  60. }
  61. if(typeof this.active === 'undefined') {
  62. this.active = true;
  63. $("#node-config-input-active").prop("checked",true);
  64. }
  65. },
  66. oneditsave: function() {
  67. },
  68. oneditresize: function(size) {
  69. },
  70. button: {
  71. enabled: function() {
  72. return !this.changed;
  73. },
  74. onclick: function() {
  75. if (this.changed) {
  76. return RED.notify(RED._(nodeName+" undeployed changes"),"warning");
  77. }
  78. var label = this._def.label.call(this);
  79. if (label.length > 30) {
  80. label = label.substring(0,50)+"...";
  81. }
  82. label = label.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
  83. var node = this;
  84. function sendCommand(element,action) {
  85. $(element).dialog("close");
  86. $.get( "/"+nodeName+"/"+node.id+"/"+action )
  87. .done(function(json) {
  88. console.log(JSON.stringify(json));
  89. RED.notify(node._(nodeName+" signal success",{label:label}),{type:"success",id:"Load Injector"});
  90. $('<div></div>').appendTo('body').html(JSON.stringify(json))
  91. .dialog({
  92. modal: true,
  93. title: (node.name||nodeName)+" "+action,
  94. zIndex: 10000,
  95. autoOpen: true,
  96. width: 'auto',
  97. resizable: false,
  98. buttons: {
  99. close: function (event, ui) {
  100. $(this).remove();
  101. }
  102. }
  103. });
  104. }).fail(function( jqXHR, textStatus, error ) {
  105. if (jqXHR.status === 404) {
  106. RED.notify(node._(nodeName+" signal not deployed"),"error");
  107. } else if (jqXHR.status === 500) {
  108. RED.notify(node._(nodeName+" signal inject failed with error "+textStatus||error||""),"error");
  109. } else if (jqXHR.status === 0) {
  110. RED.notify(node._(nodeName+" signal no response"),"error");
  111. } else {
  112. RED.notify(node._(nodeName+" signal unexpected status:"+jqXHR.status+" message:"+textStatus+" "+error),"error");
  113. }
  114. });
  115. }
  116. $('<div></div>').appendTo('body').html('<div>Choose Action</div>')
  117. .dialog({
  118. modal: true, title: (node.name||nodeName), zIndex: 10000, autoOpen: true,
  119. width: 'auto', resizable: false,
  120. buttons: {
  121. "On": function () {
  122. sendCommand(this,"setOn");
  123. },
  124. "Off": function () {
  125. sendCommand(this,"setOff");
  126. },
  127. },
  128. close: function (event, ui) {
  129. $(this).remove();
  130. }
  131. });
  132. }
  133. }
  134. });
  135. </script>