In my quest to create an "easy" way to configure the page layouts for openHasp, I thought using a function node would be a good idea, as it takes advantage of the Monaco syntax checking.
Chunks of code can be copied only requiring a couple of values to be edited to suit.
(anyone else always end up with far too many brackets when copy / pasting
I have used arrays so that there is no need to enter numbers for the pages, tabs and buttons, as these can now be calculated, based on the order they are listed.
So if you take a look at this sample, do you think it would be easy enough to understand - how to add a new "hasp", page, tab, and button ?
If I stick with this I will write up some instructions and better comments
But would be interested in any suggestions please ? @yogy @stefan24 @BartButenaers Anyone ?
EDIT - added page setup to allow for size etc to be configured. If not provided it uses some defaults, I think I will move the defaults into the theme object, next.
const layout = {
"1": { // name of hasp device (topic)
page: [ //***************** start of pages ******************
{ // ********* page 1 start **********
props: { width: 480, height: 308, minGap: 15, topMargin: 20, bottomMargin: 15, leftMargin: 0, rightMargin: 0 }, // Page Settings
tab: [
{ // *************** First tab start *******************
props: { name: "Lounge", btnStyle: "btntoggle" }, // Tab 0 Settings
btn: [
{ text: "\n", value_str: "Main", extra: { topic: "loungelights/POWER2", type: "Tas" } },
{ text: "\n", value_str: "Lamp", extra: { topic: "Bulb-20/POWER1", type: "Tas", "color": true, name: "lounge_lamp" } },
{ text: "\n", value_str: "Wall", extra: { topic: "loungelights/POWER1", type: "Tas" } },
{ text: "\n", value_str: "Dining", extra: { topic: "Bulb-10/POWER1", type: "Tas", "color": true, name: "dining_lamp" } },
{ text: "\n", value_str: "Fire", extra: { topic: "lounge_fire", type: "RF433" } },
{ text: "\n", value_str: "Fish Pump", extra: { topic: "fish_pump", type: "RF433" } }
]
}, // *************** First tab end *******************
{
props: { name: "Scene", btnStyle: "btnscene" }, // Add the properties to Tab 1
btn: [
{ text: "\uF1E1\n", value_str: "Main", extra: { topic: "scene/lounge/1", type: "Tas" } },
{ text: "\uE8DD\n", value_str: "Lamp", extra: { topic: "scene/lounge/2", type: "Tas" } },
{ text: "\uE6B5\n", value_str: "Dining", extra: { topic: "scene/lounge/3", type: "Tas" } },
{ text: "\uE238\n", value_str: "Fire", extra: { topic: "scene/lounge/4", type: "RF433" } },
{ text: "\uF1E1\n", value_str: "Main", extra: { topic: "scene/lounge/1", type: "Tas" } },
{ text: "\uE8DD\n", value_str: "Lamp", extra: { topic: "scene/lounge/2", type: "Tas" } },
{ text: "\uE6B5\n", value_str: "Dining", extra: { topic: "scene/lounge/3", type: "Tas" } },
{ text: "\uE238\n", value_str: "Fire", extra: { topic: "scene/lounge/4", type: "RF433" } },
{ text: "\uE238\n", value_str: "Fire", extra: { topic: "scene/lounge/4", type: "RF433" } }
]
},
{
props: { name: "Blinds", btnStyle: "btnbutton" }, // Add the properties to Tab 2
btn: [
{ text: "\uF1E1\n", value_str: "Main", extra: { topic: "blinds/lounge/1", type: "Tas" } },
{ text: "\uE8DD\n", value_str: "Lamp", extra: { topic: "blinds/lounge/2", type: "Tas" } },
{ text: "\uE6B5\n", value_str: "Dining", extra: { topic: "blinds/lounge/3", type: "Tas" } },
{ text: "\uE238\n", value_str: "Fire", extra: { topic: "blinds/lounge/4", type: "RF433" } }
]
}
]
}, // ************ page 1 end ***********
{ // page 2 start
tab: [
{
props: { name: "Kitchen", btnStyle: "btntoggle" },// Add the properties to Tab 0
btn: [
{ text: "\uE769\n", value_str: "Main", extra: { topic: "utility/POWER1", type: "Tas" } },
{ text: "\uE374\n", value_str: "Counter", extra: { topic: "kitchen-lightstrip/POWER1", type: "Tas" } },
{ text: "\uF2BA\n", value_str: "Cupboard", extra: { topic: "kitchen-lightstrip/POWER3", type: "Tas", color: true, name: "kitchen_cupboard_light" } },
{ text: "\uE210\n", value_str: "Fan", extra: { topic: "kitchenfan/POWER1", type: "Tas" } },
{ text: "\uE769\n", value_str: "Utility", extra: { topic: "utility/POWER2", type: "Tas" } },
{ text: "\uF020\n", value_str: "Outside", extra: { topic: "outsidelights/POWER1", type: "Tas" } }
]
},
{
props: { name: "Extra", btnStyle: "btntoggle" },// Add the properties to Tab 1
btn: [
{ text: "\uF1E1\n", value_str: "Main", extra: { topic: "scene/kitchen/1", type: "Tas" } },
{ text: "\uE8DD\n", value_str: "Lamp", extra: { topic: "scene/kitchen/2", type: "Tas" } },
]
}
]
} // page 2 end
] //***************** end of pages ******************
}
}//***************** end of hasp device names ******************