From a6e5339e38145301851ea1bfa3de7ccb12625e8e Mon Sep 17 00:00:00 2001 From: luisthieme Date: Thu, 21 Nov 2024 16:13:20 +0100 Subject: [PATCH] WIP plugin tab --- nodes/dynamic-form-theme.html | 79 +++++++++++-- nodes/dynamic-form-theme.js | 4 + nodes/ui-dynamic-form.html | 38 +++--- nodes/ui-dynamic-form.js | 2 + ...de-red-dashboard-2-dynamic-form-theme.html | 108 ++++++++++++++++-- ui/components/UIDynamicForm.vue | 5 +- ui/stylesheets/ui-dynamic-form.css | 3 +- 7 files changed, 203 insertions(+), 36 deletions(-) diff --git a/nodes/dynamic-form-theme.html b/nodes/dynamic-form-theme.html index e437e61..55e9e46 100644 --- a/nodes/dynamic-form-theme.html +++ b/nodes/dynamic-form-theme.html @@ -2,21 +2,60 @@ RED.nodes.registerType('dynamic-form-theme', { category: 'config', defaults: { + name: { + value: '', + required: true, + }, colors: { - value: { - surface: '#ffffff', - primary: '#0094CE', - bgPage: '#eeeeee', - groupBg: '#ffffff', - groupOutline: '#cccccc', - }, + surface: '#ffffff', + primary: '#0094CE', + bgPage: '#eeeeee', + groupBg: '#ffffff', + groupOutline: '#cccccc', }, }, label: function () { return this.name || 'DynamicForm Theme'; }, - oneditprepare: function () {}, - oneditsave: function () {}, + oneditprepare: function () { + // loop over keys in this.colors + if (!this.colors) { + this.colors = {}; + // set default values + this.colors.surface = '#ffffff'; + this.colors.primary = '#0094CE'; + // pages + this.colors.bgPage = '#eeeeee'; + // groups + this.colors.groupBg = '#ffffff'; + this.colors.groupOutline = '#cccccc'; + } + + Object.keys(this.colors).forEach((color) => { + // get the value of the key + const value = this.colors[color]; + // set the value of the input + $('#node-config-input-' + color).val(value); + }); + + // update label b/g to match the colour input values + // this provides nicer styling than the default browser styling + const colorWrappers = $('.color-picker-wrapper'); + colorWrappers.each(function (i) { + const wrapper = $(this); + const colorPicker = wrapper.children("input[type='color']").eq(0); + colorPicker.on('change', () => { + wrapper.css('background-color', colorPicker.val()); + }); + wrapper.css('background-color', colorPicker.val()); + }); + }, + oneditsave: function () { + Object.keys(this.colors).forEach((color) => { + // set the value of the input + this.colors[color] = $('#node-config-input-' + color).val(); + }); + }, }); @@ -25,6 +64,28 @@ +
+
+ + +
+
+ + +
+
- diff --git a/nodes/ui-dynamic-form.js b/nodes/ui-dynamic-form.js index fc30a4c..245b7da 100644 --- a/nodes/ui-dynamic-form.js +++ b/nodes/ui-dynamic-form.js @@ -7,6 +7,8 @@ module.exports = function (RED) { // which group are we rendering this widget const group = RED.nodes.getNode(config.group); + config.theme = RED.nodes.getNode(config.theme); + const base = group.getBase(); // server-side event handlers diff --git a/plugins/node-red-dashboard-2-dynamic-form-theme.html b/plugins/node-red-dashboard-2-dynamic-form-theme.html index 5d166a3..98a1452 100644 --- a/plugins/node-red-dashboard-2-dynamic-form-theme.html +++ b/plugins/node-red-dashboard-2-dynamic-form-theme.html @@ -38,9 +38,7 @@ } function addDefaultTheme() { - console.log('adding default theme...'); const theme = RED.nodes.getType('dynamic-form-theme'); - console.log('theme777', theme); const themeNode = { _def: theme, id: RED.nodes.id(), @@ -50,11 +48,69 @@ }; addConfigNode(themeNode); + console.log('node added'); + + const listItem = $('
', { class: 'list-item' }).appendTo(themeList); + listItem.append($('

', { class: 'list-item-text', text: theme.name })); + $( + '' + ) + .click(function (evt) { + RED.editor.editConfig('', theme.type, theme.id); + evt.preventDefault(); + }) + .appendTo(listItem); + return themeNode; } - const tab = $('

', { class: 'test_class_luis' }).appendTo(parent); - tab.append($('' + ) + .click(function (evt) { + const themeResult = addDefaultTheme(); + RED.editor.editConfig('', themeResult.type, themeResult.id); + }) + .appendTo(headerDiv); + + let themes = {}; + + RED.nodes.eachConfig(function (n) { + if (n.type === 'dynamic-form-theme') { + themes[n.id] = n; + } + }); + + Object.values(themes).forEach(function (theme) { + const listItem = $('
', { class: 'list-item' }).appendTo(themeList); + listItem.append($('

', { class: 'list-item-text', text: theme.name })); + $( + '' + ) + .click(function (evt) { + // if (themes.includes(itemc)) { + // RED.editor.editConfig('', item.type, item.id); + // } else { + // RED.editor.edit(item?.node); + // } + + RED.editor.editConfig('', theme.type, theme.id); + evt.stopPropagation(); + evt.preventDefault(); + }) + .appendTo(listItem); + }); }, }, ], @@ -64,10 +120,48 @@ diff --git a/ui/components/UIDynamicForm.vue b/ui/components/UIDynamicForm.vue index df0113e..ca82026 100644 --- a/ui/components/UIDynamicForm.vue +++ b/ui/components/UIDynamicForm.vue @@ -1,6 +1,6 @@