From 00e06ee938aa8cc6a4a90723afcc698437abae33 Mon Sep 17 00:00:00 2001 From: bartbutenaers Date: Sat, 21 Dec 2024 23:12:09 +0100 Subject: [PATCH 1/2] ui-control colon in group name --- nodes/widgets/ui_control.js | 14 ++++++++++---- ui/src/widgets/ui-control/UIControl.vue | 12 +++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/nodes/widgets/ui_control.js b/nodes/widgets/ui_control.js index 1f068b80..41cec1f8 100644 --- a/nodes/widgets/ui_control.js +++ b/nodes/widgets/ui_control.js @@ -26,6 +26,12 @@ module.exports = function (RED) { ui.emit('ui-control:' + node.id, msg, node) } + function splitUnEscapedColon (str) { + // Split only on colons (:) that ar not escaped, i.e. not preceded by a backslash (\\). + // And for each part replace the escaped colons again by normal colons. + return str.split(/(? part.replace(/\\:/g, ':')) + } + const evts = { onInput: function (msg, send, done) { const wNode = RED.nodes.getNode(node.id) @@ -111,28 +117,28 @@ module.exports = function (RED) { }) if ('show' in groups) { const gs = groups.show.map((g) => { - const levels = g.split(':') + const levels = splitUnEscapedColon(g) return levels.length > 1 ? levels[1] : g }) updateStore(allGroups, gs, msg, 'visible', true) } if ('hide' in groups) { const gh = groups.hide.map((g) => { - const levels = g.split(':') + const levels = splitUnEscapedColon(g) return levels.length > 1 ? levels[1] : g }) updateStore(allGroups, gh, msg, 'visible', false) } if ('enable' in groups) { const ge = groups.enable.map((g) => { - const levels = g.split(':') + const levels = splitUnEscapedColon(g) return levels.length > 1 ? levels[1] : g }) updateStore(allGroups, ge, msg, 'disabled', false) } if ('disable' in groups) { const gd = groups.disable.map((g) => { - const levels = g.split(':') + const levels = splitUnEscapedColon(g) return levels.length > 1 ? levels[1] : g }) updateStore(allGroups, gd, msg, 'disabled', true) diff --git a/ui/src/widgets/ui-control/UIControl.vue b/ui/src/widgets/ui-control/UIControl.vue index d2b03f09..84ee48d0 100644 --- a/ui/src/widgets/ui-control/UIControl.vue +++ b/ui/src/widgets/ui-control/UIControl.vue @@ -44,8 +44,14 @@ export default { }) } + function splitUnEscapedColon (str) { + // Split only on colons (:) that ar not escaped, i.e. not preceded by a backslash (\\). + // And for each part replace the escaped colons again by normal colons. + return str.split(/(? part.replace(/\\:/g, ':')) + } + function setGroup (name, prop, value) { - const [pageName, groupName] = name.split(':') + const [pageName, groupName] = splitUnEscapedColon(name) const groups = vue.findBy('group', 'name', groupName) if (groups.length === 1) { set('group', groupName, prop, value) @@ -175,7 +181,7 @@ export default { if ('groups' in payload) { if ('show' in payload.groups) { payload.groups.show.forEach((name) => { - const groupName = name.split(':')[1] + const groupName = splitUnEscapedColon(name)[1] const exactGroup = vue.groups ? Object.values(vue.groups).find(group => group.name === groupName) : null if (exactGroup?.groupType === 'dialog') { @@ -189,7 +195,7 @@ export default { } if ('hide' in payload.groups) { payload.groups.hide.forEach((name) => { - const groupName = name.split(':')[1] + const groupName = splitUnEscapedColon(name)[1] const exactGroup = vue.groups ? Object.values(vue.groups).find(group => group.name === groupName) : null if (exactGroup?.groupType === 'dialog') { From 067210ec0a2292da16e0b3d08c781a5d8f9436b5 Mon Sep 17 00:00:00 2001 From: bartbutenaers Date: Sat, 21 Dec 2024 23:38:41 +0100 Subject: [PATCH 2/2] ui-control colon in group name (docs) --- docs/nodes/widgets/ui-control.md | 3 ++- nodes/widgets/locales/en-US/ui_control.html | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/nodes/widgets/ui-control.md b/docs/nodes/widgets/ui-control.md index f0642119..e86229d8 100644 --- a/docs/nodes/widgets/ui-control.md +++ b/docs/nodes/widgets/ui-control.md @@ -123,6 +123,7 @@ msg.payload = { ``` _Note:_ `pages` can be subbed with `tabs` as per Dashboard 1.0 and `groups` can also be subbed with `group` as per Dashboard 1.0. +_Note:_ when the `group` name contains a colon `:`, then that should be escaped using a backslash `\`. ### Enable/Disable @@ -187,4 +188,4 @@ msg = { tab: '', name: '' } -``` \ No newline at end of file +``` diff --git a/nodes/widgets/locales/en-US/ui_control.html b/nodes/widgets/locales/en-US/ui_control.html index fe435bf2..42201a1a 100644 --- a/nodes/widgets/locales/en-US/ui_control.html +++ b/nodes/widgets/locales/en-US/ui_control.html @@ -33,7 +33,7 @@

Show/Hide Pages & Groups

} }

Enable/Disable Pages & Groups

-

Dashboard pages & groups can be disabled & re-enabled by sending a msg.payload object with the format +

Dashboard pages & groups can be disabled & re-enabled by sending a msg.payload object with the format

msg.payload = {
     pages: {
         enable: ['<Page Name>', '<Page Name>'],
@@ -44,6 +44,7 @@ 

Enable/Disable Pages & Groups

disable: ['<Group Name>'] } }
+

When the group name contains a colon :, that needs to be escaped using a backslash \.

External URL

It is possible to trigger navigation to an external site, away from your Dashboard by passing in a URL string.

msg.payload = {
@@ -64,4 +65,4 @@ 

Events List

  • name - the name of the tab. (only for 'change' event).

    Optional - report only connect events - useful to use to trigger a resend of data to a new client without needing to filter out other events.

    - \ No newline at end of file +