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_table.html 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <style>
  2. #node-input-column-container-div {
  3. min-height: 36px;
  4. }
  5. .node-input-column-container-row {
  6. flex-grow: 1;
  7. }
  8. .node-input-column-row {
  9. display: flex;
  10. flex-direction: row;
  11. align-items: center;
  12. gap: 6px;
  13. }
  14. .node-input-column-row .node-input-column-handle {
  15. color: var(--red-ui-form-text-color, #eee);
  16. cursor: move;
  17. margin-right: 3px;
  18. }
  19. .node-input-column-options {
  20. flex-grow: 1;
  21. }
  22. .node-input-column-row-property {
  23. display: flex;
  24. flex-direction: row;
  25. align-items: center;
  26. gap: 6px;
  27. flex-grow: 1;
  28. }
  29. .node-input-column-row-property label {
  30. min-width: 50px;
  31. width: auto !important;
  32. }
  33. .node-input-column-row-property:not(:first-child) {
  34. margin-top: 3px;
  35. }
  36. #node-input-column-container .node-input-column-row-property input,
  37. #node-input-column-container .node-input-column-row-property select {
  38. flex-grow: 1;
  39. width: 50%;
  40. }
  41. .flex-grow {
  42. flex-grow: 1;
  43. }
  44. </style>
  45. <script type="text/javascript">
  46. (function () {
  47. const COLUMN_TYPES = [
  48. { value: 'text', label: 'Text' },
  49. { value: 'html', label: 'HTML' },
  50. { value: 'link', label: 'Link (https://...)' },
  51. { value: 'color', label: 'Color (#RRGGBB)' },
  52. { value: 'tickcross', label: 'Tick/Cross (Boolean)' },
  53. { value: 'progress', label: 'Progress (1-100)' },
  54. { value: 'sparkline-trend', label: 'Sparkline - Trend (Array)' },
  55. { value: 'sparkline-bar', label: 'Sparkline - Bar (Array)' },
  56. { value: 'button', label: 'Button' },
  57. { value: 'row', label: 'Row Number' }
  58. ]
  59. RED.nodes.registerType('ui-table', {
  60. category: RED._('@flowfuse/node-red-dashboard/ui-base:ui-base.label.category'),
  61. color: RED._('@flowfuse/node-red-dashboard/ui-base:ui-base.colors.medium'),
  62. defaults: {
  63. group: { type: 'ui-group', required: true },
  64. name: { value: '' },
  65. label: { value: 'text' },
  66. order: { value: 0 },
  67. width: {
  68. value: 0,
  69. validate: function (v) {
  70. const width = v || 0
  71. const currentGroup = $('#node-input-group').val() || this.group
  72. const groupNode = RED.nodes.node(currentGroup)
  73. const valid = !groupNode || +width <= +groupNode.width
  74. $('#node-input-size').toggleClass('input-error', !valid)
  75. return valid
  76. }
  77. },
  78. height: { value: 0 },
  79. maxrows: { value: 0, validate: RED.validators.number() },
  80. passthru: { value: false },
  81. autocols: { value: true },
  82. showSearch: { value: true },
  83. selectionType: { value: 'none' },
  84. columns: {
  85. value: null
  86. },
  87. mobileBreakpoint: { value: 'sm' },
  88. mobileBreakpointType: { value: 'defaults' }
  89. },
  90. inputs: 1,
  91. outputs: 1,
  92. outputLabels: function () { return this.mode },
  93. icon: 'font-awesome/fa-table',
  94. paletteLabel: 'table',
  95. label: function () {
  96. return this.name || 'table'
  97. },
  98. oneditprepare: function () {
  99. // handle backward compatibility
  100. const validSelectionTypes = ['none', 'checkbox', 'click']
  101. if (!validSelectionTypes.includes(this.selectionType)) {
  102. $('#node-input-selectionType').val('none')
  103. }
  104. // if this groups parent is a subflow template, set the node-config-input-width and node-config-input-height up
  105. // as typedInputs and hide the elementSizer (as it doesn't make sense for subflow templates)
  106. if (RED.nodes.subflow(this.z)) {
  107. // change inputs from hidden to text & display them
  108. $('#node-input-width').attr('type', 'text')
  109. $('#node-input-height').attr('type', 'text')
  110. $('div.form-row.nr-db-ui-element-sizer-row').hide()
  111. $('div.form-row.nr-db-ui-manual-size-row').show()
  112. } else {
  113. // not in a subflow, use the elementSizer
  114. $('div.form-row.nr-db-ui-element-sizer-row').show()
  115. $('div.form-row.nr-db-ui-manual-size-row').hide()
  116. $('#node-input-size').elementSizer({
  117. width: '#node-input-width',
  118. height: '#node-input-height',
  119. group: '#node-input-group'
  120. })
  121. }
  122. // setup mobile breakpoint TypedInput
  123. $('#node-input-mobileBreakpoint').typedInput({
  124. typeField: '#node-input-mobileBreakpointType',
  125. types: [{
  126. value: 'defaults',
  127. label: 'defaults:',
  128. options: [
  129. { value: 'sm', label: 'Mobile (< 576px)' },
  130. { value: 'md', label: 'Tablet (< 768px)' },
  131. { value: 'lg', label: 'Desktop (< 1024px)' }
  132. ]
  133. }, {
  134. value: 'px',
  135. label: 'px:',
  136. validate: RED.validators.number()
  137. }, {
  138. value: 'none',
  139. label: 'None',
  140. hasValue: false
  141. }]
  142. })
  143. const autocols = $('#node-input-autocols')
  144. $(autocols).change(() => {
  145. const val = autocols.is(':checked')
  146. const customColsDiv = $('#node-input-columns-container')
  147. if (val) {
  148. customColsDiv.hide()
  149. } else {
  150. customColsDiv.show()
  151. }
  152. })
  153. // Columns Editor
  154. function generateColumn (i, col) {
  155. 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);' })
  156. const row = $('<div/>', {
  157. class: 'node-input-column-row'
  158. }).appendTo(container)
  159. $('<div/>', { style: 'padding-top:5px; padding-left:175px;' }).appendTo(container)
  160. $('<div/>', { style: 'padding-top:5px; padding-left:120px;' }).appendTo(container)
  161. // sorting handle
  162. $('<i class="node-input-column-handle fa fa-bars"></i>').appendTo(row)
  163. const options = $('<div/>', {
  164. class: 'node-input-column-options'
  165. }).appendTo(row)
  166. // key
  167. const keyRow = $('<div />', { class: 'node-input-column-row-property' }).appendTo(options)
  168. $('<label/>', {
  169. text: `${RED._('@flowfuse/node-red-dashboard/ui-table:ui-table.label.key')}:`
  170. }).appendTo(keyRow)
  171. $('<input/>', {
  172. class: 'node-input-column-key',
  173. type: 'text',
  174. placeholder: RED._('@flowfuse/node-red-dashboard/ui-table:ui-table.label.key'),
  175. value: col.key
  176. }).appendTo(keyRow)
  177. // label
  178. const labelRow = $('<div />', { class: 'node-input-column-row-property' }).appendTo(options)
  179. $('<label/>', {
  180. text: `${RED._('@flowfuse/node-red-dashboard/ui-table:ui-table.label.label')}:`
  181. }).appendTo(labelRow)
  182. $('<input/>', {
  183. class: 'node-input-column-label',
  184. type: 'text',
  185. placeholder: RED._('@flowfuse/node-red-dashboard/ui-table:ui-table.label.label'),
  186. value: col.title
  187. }).appendTo(labelRow)
  188. // style
  189. const styleRow = $('<div />', { class: 'node-input-column-row-property' }).appendTo(options)
  190. // style - width
  191. const widthRow = $('<div />', { class: 'node-input-column-row-property' }).appendTo(styleRow)
  192. $('<label/>', {
  193. text: `${RED._('@flowfuse/node-red-dashboard/ui-table:ui-table.label.width')}:`
  194. }).appendTo(widthRow)
  195. $('<input/>', {
  196. type: 'text',
  197. class: 'node-input-column-width',
  198. placeholder: RED._('@flowfuse/node-red-dashboard/ui-table:ui-table.label.width'),
  199. value: col.width
  200. }).appendTo(widthRow)
  201. // style - align
  202. const alignRow = $('<div />', { class: 'node-input-column-row-property' }).appendTo(styleRow)
  203. $('<label/>', {
  204. text: `${RED._('@flowfuse/node-red-dashboard/ui-table:ui-table.label.align')}:`
  205. }).appendTo(alignRow)
  206. const alignOptions = $('<select>', {
  207. class: 'node-input-column-align'
  208. }).appendTo(alignRow)
  209. alignOptions.append($('<option>').attr('value', 'start').text(RED._('@flowfuse/node-red-dashboard/ui-table:ui-table.label.alignLeft')))
  210. alignOptions.append($('<option>').attr('value', 'center').text(RED._('@flowfuse/node-red-dashboard/ui-table:ui-table.label.alignCenter')))
  211. alignOptions.append($('<option>').attr('value', 'end').text(RED._('@flowfuse/node-red-dashboard/ui-table:ui-table.label.alignRight')))
  212. alignOptions.val(col.align).change()
  213. // type
  214. const typeRow = $('<div />', { class: 'node-input-column-row-property' }).appendTo(options)
  215. $('<label/>', {
  216. text: `${RED._('@flowfuse/node-red-dashboard/ui-table:ui-table.label.type')}:`
  217. }).appendTo(typeRow)
  218. const typeOptions = $('<select>', {
  219. class: 'node-input-column-type'
  220. }).appendTo(typeRow)
  221. // add options for each supported column type
  222. $(COLUMN_TYPES).each(function () {
  223. typeOptions.append($('<option>').attr('value', this.value).text(this.label))
  224. })
  225. typeOptions.val(col.type).change()
  226. const finalSpan = $('<span/>', { style: 'float:right; margin-right:8px;' }).appendTo(row)
  227. const deleteButton = $('<a/>', { href: '#', class: 'editor-button editor-button-small', style: 'margin-top:7px; margin-left:5px;' }).appendTo(finalSpan)
  228. $('<i/>', { class: 'fa fa-remove' }).appendTo(deleteButton)
  229. deleteButton.click(function () {
  230. container.css({ background: 'var(--red-ui-secondary-background-inactive, #fee)' })
  231. container.fadeOut(300, function () {
  232. $(this).remove()
  233. })
  234. })
  235. $('#node-input-column-container').append(container)
  236. }
  237. $('#node-input-add-column').click(function () {
  238. const defaultColumn = {
  239. type: 'text',
  240. align: 'start'
  241. }
  242. generateColumn($('#node-input-column-container').children().length + 1, defaultColumn)
  243. $('#node-input-column-container-div').scrollTop($('#node-input-column-container-div').get(0).scrollHeight)
  244. })
  245. for (let i = 0; i < this.columns?.length; i++) {
  246. const col = this.columns[i]
  247. generateColumn(i + 1, col)
  248. }
  249. $('#node-input-column-container').sortable({
  250. axis: 'y',
  251. handle: '.node-input-column-handle',
  252. cursor: 'move'
  253. })
  254. },
  255. oneditsave: function () {
  256. const columns = $('#node-input-column-container').children()
  257. const node = this
  258. node.columns = []
  259. columns.each(function (i) {
  260. const column = $(this)
  261. const o = {
  262. title: column.find('.node-input-column-label').val(),
  263. key: column.find('.node-input-column-key').val(),
  264. type: column.find('.node-input-column-type').find(':selected').val(),
  265. width: column.find('.node-input-column-width').val(),
  266. align: column.find('.node-input-column-align').find(':selected').val()
  267. }
  268. node.columns.push(o)
  269. })
  270. }
  271. })
  272. })()
  273. </script>
  274. <script type="text/html" data-template-name="ui-table">
  275. <div class="form-row">
  276. <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></label>
  277. <input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
  278. </div>
  279. <div class="form-row">
  280. <label for="node-input-group"><i class="fa fa-table"></i> <span data-i18n="ui-table.label.group"></label>
  281. <input type="text" id="node-input-group">
  282. </div>
  283. <div class="form-row nr-db-ui-element-sizer-row">
  284. <label><i class="fa fa-object-group"></i> <span data-i18n="ui-table.label.size">Size</label>
  285. <button class="editor-button" id="node-input-size"></button>
  286. </div>
  287. <div class="form-row nr-db-ui-manual-size-row">
  288. <label><i class="fa fa-arrows-h"></i> <span data-i18n="ui-table.label.width">Width</label>
  289. <input type="hidden" id="node-input-width">
  290. </div>
  291. <div class="form-row nr-db-ui-manual-size-row">
  292. <label><i class="fa fa-arrows-v"></i> <span data-i18n="ui-table.label.height">Height</label>
  293. <input type="hidden" id="node-input-height">
  294. </div>
  295. <div class="form-row">
  296. <label for="node-input-maxrows"><i class="fa fa-tag"></i> <span data-i18n="ui-table.label.maxRows"></label>
  297. <input type="number" id="node-input-maxrows">
  298. </div>
  299. <div class="form-row">
  300. <label for="node-input-mobileBreakpoint"><i class="fa fa-mobile"></i> <span data-i18n="ui-table.label.mobileBreakpoint"></label>
  301. <input type="text" id="node-input-mobileBreakpoint">
  302. <input type="hidden" id="node-input-mobileBreakpointType">
  303. </div>
  304. <div class="form-row">
  305. <label for="node-input-selectionType"><i class="fa fa-crosshairs"></i> <span data-i18n="ui-table.label.selection"></span></label>
  306. <select id="node-input-selectionType">
  307. <option value="none" data-i18n="ui-table.selection.none"></option>
  308. <option value="click" data-i18n="ui-table.selection.click"></option>
  309. <option value="checkbox" data-i18n="ui-table.selection.checkbox"></option>
  310. </select>
  311. </div>
  312. <div class="form-row form-row-flex">
  313. <label for="node-input-showSearch"><i class="fa fa-search"></i> <span data-i18n="ui-table.label.search"></label>
  314. <div style="margin-bottom: 0px; width:calc(70% + 15px);">
  315. <input type="checkbox" id="node-input-showSearch" style="display: inline-block; width: auto;">
  316. <label for="node-input-showSearch" data-i18n="ui-table.label.showSearch"></label>
  317. </div>
  318. </div>
  319. <div class="form-row" style="display:flex; margin-bottom: 3px;">
  320. <label for="node-input-width" style="vertical-align:top"><i class="fa fa-list-alt"></i> <span data-i18n="ui-table.label.columns"></label>
  321. <div>
  322. <input type="checkbox" checked id="node-input-autocols" style="display: inline-block; width: auto; margin: 0px 0px 0px 4px;">
  323. <label style="width:auto" for="node-input-autocols" data-i18n="ui-table.label.autoCalculateColumns"></label>
  324. </div>
  325. </div>
  326. <div class="form-row">
  327. <div class="form-row node-input-column-container-row">
  328. <div id="node-input-columns-container">
  329. <div id="node-input-column-container-div" style="box-sizing:border-box; border-radius:5px; padding:5px; border:1px solid var(--red-ui-form-input-border-color, #ccc); overflow-y:scroll; display:inline-block; width: 100%;">
  330. <ol id="node-input-column-container" style="list-style-type:none; margin:0;"></ol>
  331. </div>
  332. <a href="#" class="editor-button editor-button-small" id="node-input-add-column" style="margin-top:4px;"><i class="fa fa-plus"></i> <span data-i18n="ui-table.label.columns"></span></a>
  333. </div>
  334. </div>
  335. </div>
  336. </script>