Skip to content

Commit

Permalink
ui-control colon in group name
Browse files Browse the repository at this point in the history
  • Loading branch information
bartbutenaers committed Dec 21, 2024
1 parent abf3130 commit 00e06ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
14 changes: 10 additions & 4 deletions nodes/widgets/ui_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(/(?<!\\):/).map(part => part.replace(/\\:/g, ':'))
}

const evts = {
onInput: function (msg, send, done) {
const wNode = RED.nodes.getNode(node.id)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions ui/src/widgets/ui-control/UIControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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(/(?<!\\):/).map(part => 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)
Expand Down Expand Up @@ -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') {
Expand All @@ -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') {
Expand Down

0 comments on commit 00e06ee

Please sign in to comment.