|
| 1 | +<!-- Node-RED editor code for the FlexDash ButtonBar widget --> |
| 2 | + |
| 3 | +<script type="module"> |
| 4 | + // fetch the widget info: a bunch of JSON produced by gen-widget-node.js |
| 5 | + import widgetInfo from './resources/@flexdash/node-red-fd-testnodes/button-bar-info.js' |
| 6 | + |
| 7 | + // construct defaults for the node, setting all but bool to null so widget defaults happen |
| 8 | + var widgetDefaults = Object.fromEntries(Object.values(widgetInfo.props).map(p => |
| 9 | + [p.name, {value: p.default}] |
| 10 | + )) |
| 11 | + //console.log(widgetInfo.name, "widgetDefaults", widgetDefaults) |
| 12 | + |
| 13 | + // construct the palette label |
| 14 | + var paletteLabel = widgetInfo.name_text.toLocaleLowerCase() |
| 15 | + |
| 16 | + // update the text for the help sidebar |
| 17 | + var helpHtml = flexdash.load_help_html(widgetInfo, paletteLabel) |
| 18 | + |
| 19 | + flexdash.insert_general_edit("fd-button-bar", "fd-tab-general") |
| 20 | + |
| 21 | + |
| 22 | + RED.nodes.registerType(widgetInfo.type_kebab, { |
| 23 | + // properties of the NR node used by NR itself |
| 24 | + category: 'flexdash', |
| 25 | + color: "#F0E4B8", |
| 26 | + inputs: 1, |
| 27 | + outputs: widgetInfo.output ? 1 : 0, |
| 28 | + icon: "font-awesome/fa-rocket", // icon in flow editor |
| 29 | + paletteLabel, |
| 30 | + |
| 31 | + // node config properties that the user can edit in the flow editor |
| 32 | + defaults: { |
| 33 | + // required fields for FlexDash Widget nodes |
| 34 | + fd_container: { |
| 35 | + type: "flexdash container", value: "", required: true, // grid/panel |
| 36 | + validate: flexdash.validate_widget_container }, |
| 37 | + fd_cols: { value: 1, validate(v) { return v>0 && v<=20 } }, // widget width |
| 38 | + fd_rows: { value: 1, validate(v) { return v>0 && v<=100 } }, // widget height |
| 39 | + fd_array: { value: false }, // create array of this widget |
| 40 | + fd_array_max: { value: 10, validate(v) { return v>0 && v<1000} }, // max array size |
| 41 | + // name field of Node-RED node (standard) |
| 42 | + name: { value: '' }, |
| 43 | + |
| 44 | + // widget fields, i.e. values being transmitted to the FlexDash Widget as props |
| 45 | + ...widgetDefaults, |
| 46 | + }, |
| 47 | + |
| 48 | + // Node-RED node label |
| 49 | + label() { |
| 50 | + const lbl = this.name || paletteLabel |
| 51 | + return this.fd_array ? lbl+'[ ]' : lbl // indicate whether this is an array-widget |
| 52 | + }, |
| 53 | + labelStyle() { return this.name ? "node_label_italic" : "" }, |
| 54 | + |
| 55 | + oneditprepare() { |
| 56 | + // fetch the html to edit the widget props and insert into DOM |
| 57 | + flexdash.load_props_edit(this, widgetInfo, "fd-tab-props") |
| 58 | + // select last-used container |
| 59 | + flexdash.select_last_container() |
| 60 | + |
| 61 | + // manage tabs |
| 62 | + const tabs = RED.tabs.create({id: "fd-tabs", onchange: function(tab) { |
| 63 | + $("#fd-tabs-content").children().hide() |
| 64 | + $("#" + tab.id).show() |
| 65 | + RED.tray.resize() |
| 66 | + }}) |
| 67 | + tabs.addTab({ id: "fd-tab-general", label: "General" }) |
| 68 | + tabs.addTab({ id: "fd-tab-props", label: "Widget props" }) |
| 69 | + tabs.activateTab(this.fd_container ? "fd-tab-props" : "fd-tab-general") |
| 70 | + }, |
| 71 | + }) |
| 72 | +</script> |
| 73 | + |
| 74 | +<script type="text/html" data-template-name="fd-button-bar"> |
| 75 | + <div class="form-row"> |
| 76 | + <ul id="fd-tabs" style="min-width: 600px; margin-bottom: 20px;"></ul> |
| 77 | + </div> |
| 78 | + <div id="fd-tabs-content" style="min-height: calc(100% - 95px);"> |
| 79 | + <!-- general properties tab --> |
| 80 | + <div id="fd-tab-general" style="display:none"><!-- dynamically loaded --></div> |
| 81 | + <!-- widget props --> |
| 82 | + <div id="fd-tab-props" style="display:none"><!-- dynamically loaded --></div> |
| 83 | + </div> |
| 84 | + <!-- non-tab alternative, remove all above, remove 'manage tabs' code, and use this: |
| 85 | + <div id="fd-tab-general" style="display:contents"></div> |
| 86 | + <div id="fd-tab-props" style="display:contents"></div> |
| 87 | + --> |
| 88 | +</script> |
| 89 | + |
| 90 | +<script type="text/markdown" data-help-name="fd-button-bar"> |
| 91 | + <p id="fd-button-bar-help-text"><i>Ooops, this should have filled-in dynamically...</i></p> |
| 92 | +</script> |
0 commit comments