Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui-led.html 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <script type="text/javascript">
  2. function generateStateRow (i, state) {
  3. const color = state.color
  4. const value = state.value
  5. const valueType = state.valueType
  6. const container = $('<li/>', { style: 'background: var(--red-ui-secondary-background, #fff); margin:0; padding:8px 0px 0px; border-bottom: 1px solid var(--red-ui-form-input-border-color, #ccc);' })
  7. const row = $('<div/>', {class: 'form-row-flex'}).appendTo(container)
  8. $('<div/>', { style: 'padding-top:5px; padding-left:175px;' }).appendTo(container)
  9. $('<div/>', { style: 'padding-top:5px; padding-left:120px;' }).appendTo(container)
  10. $('<i style="color: var(--red-ui-form-text-color, #eee); cursor:move; margin-left:3px;" class="node-input-state-handle fa fa-bars"></i>').appendTo(row)
  11. // color picker
  12. $('<input/>', { class: 'node-input-state-color', type: 'color', style: 'margin-left:7px; width: 50px;', placeholder: 'Color', value: color }).appendTo(row)
  13. // value field
  14. const valueFieldContainer = $('<div/>', {
  15. style: 'min-width:30%; flex-grow:1; margin-left:10px;'
  16. }).appendTo(row)
  17. const valueField = $('<input/>', { class: 'node-input-state-value', type: 'text', style: 'width: 100%;', placeholder: 'Value', value: value }).appendTo(valueFieldContainer)
  18. const valueTypeField = $('<input/>', { class: 'node-input-state-valueType', type: 'hidden', value: valueType }).appendTo(valueFieldContainer)
  19. valueField.typedInput({
  20. default: 'bool',
  21. typeField: valueTypeField,
  22. types: ['str', 'num', 'bool', 'json', 'bin']
  23. })
  24. const finalSpan = $('<span/>', { style: 'float:right; margin-right:8px;' }).appendTo(row)
  25. const deleteButton = $('<a/>', { href: '#', class: 'editor-button editor-button-small', style: 'margin-top:7px; margin-left:5px;' }).appendTo(finalSpan)
  26. $('<i/>', { class: 'fa fa-remove' }).appendTo(deleteButton)
  27. deleteButton.click(function () {
  28. container.css({ background: 'var(--red-ui-secondary-background-inactive, #fee)' })
  29. container.fadeOut(300, function () {
  30. $(this).remove()
  31. })
  32. })
  33. $('#node-input-states-container').append(container)
  34. }
  35. RED.nodes.registerType('ui-led', {
  36. category: RED._('@flowfuse/node-red-dashboard/ui-base:ui-base.label.category'),
  37. color: RED._('@flowfuse/node-red-dashboard/ui-base:ui-base.colors.medium'),
  38. defaults: {
  39. name: { value: "" },
  40. group: { type: 'ui-group', required: true },
  41. order: { value: -1 },
  42. width: {
  43. value: 0,
  44. validate: function (v) {
  45. const width = v || 0
  46. const currentGroup = $('#node-input-group').val() || this.group
  47. const groupNode = RED.nodes.node(currentGroup)
  48. const valid = !groupNode || +width <= +groupNode.width
  49. $('#node-input-size').toggleClass('input-error', !valid)
  50. return valid
  51. }
  52. },
  53. height: { value: 0 },
  54. label: { value: '' },
  55. labelPlacement: { value: 'left' },
  56. labelAlignment: { value: 'left' },
  57. states: {
  58. required: true,
  59. value: [
  60. {
  61. color: '#FF0000',
  62. value: false,
  63. valueType: 'bool'
  64. },
  65. {
  66. color: '#00FF00',
  67. value: true,
  68. valueType: 'bool'
  69. }
  70. ]
  71. },
  72. allowColorForValueInMessage: { value: false },
  73. shape: { value: 'circle' },
  74. showBorder: { value: true },
  75. showGlow: { value: true }
  76. },
  77. inputs: 1,
  78. outputs: 0,
  79. icon: "font-awesome/fa-lightbulb-o",
  80. label: function() {
  81. return this.name || "ui-led";
  82. },
  83. oneditprepare: function () {
  84. $('#node-input-size').elementSizer({
  85. width: '#node-input-width',
  86. height: '#node-input-height',
  87. group: '#node-input-group'
  88. });
  89. // update the colorForValue list
  90. // setupColorForValue(this)
  91. console.log(this.states)
  92. $('#node-input-add-state').click(function () {
  93. generateStateRow($('#node-input-states-container').children().length + 1, {})
  94. $('#node-input-states-container-div').scrollTop($('#node-input-states-container-div').get(0).scrollHeight)
  95. })
  96. $('#node-input-states-container').sortable({
  97. axis: 'y',
  98. handle: '.node-input-option-handle',
  99. cursor: 'move'
  100. })
  101. for (let i = 0; i < this.states.length; i++) {
  102. const state = this.states[i]
  103. generateStateRow(i + 1, state)
  104. }
  105. },
  106. oneditsave: function () {
  107. const states = $('#node-input-states-container').children()
  108. const node = this
  109. node.states = []
  110. states.each(function (i) {
  111. const state = $(this)
  112. const s = {
  113. value: state.find('.node-input-state-value').val(),
  114. valueType: state.find('.node-input-state-valueType').val(),
  115. color: state.find('.node-input-state-color').val()
  116. }
  117. node.states.push(s)
  118. })
  119. }
  120. });
  121. </script>
  122. <script type="text/html" data-template-name="ui-led">
  123. <div class="form-row">
  124. <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
  125. <input type="text" id="node-input-name" placeholder="Name">
  126. </div>
  127. <div class="form-row">
  128. <label for="node-input-group"><i class="fa fa-table"></i> Group</label>
  129. <input type="text" id="node-input-group">
  130. </div>
  131. <div class="form-row">
  132. <label><i class="fa fa-object-group"></i> <span data-i18n="ui-led.label.size"></label>
  133. <input type="hidden" id="node-input-width">
  134. <input type="hidden" id="node-input-height">
  135. <button class="editor-button" id="node-input-size"></button>
  136. </div>
  137. <h3>Label Styling</h3>
  138. <div class="form-row">
  139. <label for="node-input-label"><i class="icon-tag"></i> <span data-i18n="ui-led.label.text"></span></label>
  140. <input type="text" id="node-input-label" data-i18n="[placeholder]editor:editor.defaultLabel">
  141. </div>
  142. <div class="form-row-flex" style="gap: 100px;">
  143. <div class="form-row">
  144. <label for="node-input-labelPlacement"><i class="icon-tag"></i> Placement</label>
  145. <select id="node-input-labelPlacement" style="width: 75px;">
  146. <option value="left">left</option>
  147. <option value="right">right</option>
  148. </select>
  149. </div>
  150. <div class="form-row">
  151. <label for="node-input-labelAlignment"><i class="icon-tag"></i> Alignment</label>
  152. <select id="node-input-labelAlignment" style="width: 75px;">
  153. <option value="flex-start">left</option>
  154. <option value="center">center</option>
  155. <option value="flex-end">right</option>
  156. </select>
  157. </div>
  158. </div>
  159. <h3>LED Styling</h3>
  160. <div class="form-row">
  161. <label for="node-input-shape"><i class="icon-tag"></i> Shape</label>
  162. <select id="node-input-shape" style="width: 75px;">
  163. <option value="circle">circle</option>
  164. <option value="square">square</option>
  165. </select>
  166. </div>
  167. <div class="form-row" style="display: flex; flex-direction: row; width: 100%;">
  168. <div style="flex-grow: 1; display: flex; flex-direction: row;">
  169. <label for="node-input-showBorder" style="flex-grow: 1; margin-bottom: unset;">Show border around LED</label>
  170. <input type="checkbox" id="node-input-showBorder" style="width: unset;">
  171. </div>
  172. </div>
  173. <div class="form-row" style="display: flex; flex-direction: row; width: 100%;">
  174. <div style="flex-grow: 1; display: flex; flex-direction: row;">
  175. <label for="node-input-showGlow" style="flex-grow: 1; margin-bottom: unset;">Show glow effect around LED</label>
  176. <input type="checkbox" id="node-input-showGlow" style="width: unset;">
  177. </div>
  178. </div>
  179. <h3>Values</h3>
  180. <div class="form-row node-input-states-container-row" style="margin-bottom:0px; width:100%; min-width:520px; display: flex; flex-direction: column;">
  181. <label style="vertical-align:top; width: 100%;"><i class="fa fa-list-alt"></i> Colors for value of msg.payload</label>
  182. <div id="node-input-states-container-div" style="box-sizing:border-box; border-radius:5px; height:257px; padding:5px; border:1px solid var(--red-ui-form-input-border-color, #ccc); overflow-y:scroll; display:inline-block; width: 100%;">
  183. <span id="valWarning" style="color: var(--red-ui-text-color-error, #910000)"><b data-i18n="ui-led.errors.unique"></b></span>
  184. <ol id="node-input-states-container" style="list-style-type:none; margin:0;"></ol>
  185. </div>
  186. </div>
  187. <div class="form-row">
  188. <a href="#" class="editor-button editor-button-small" id="node-input-add-state" style="margin-top:4px;"><i class="fa fa-plus"></i> <span>Color</span></a>
  189. </div>
  190. </script>