-
-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add missing sitemap attributes #1487
Conversation
Job #549: Bundle Size — 11.33MB (+0.07%).Metrics (2 changes)
Total size by type (1 change)
|
PR#3075 has been merged, so this PR should now work in a recent snapshot. |
Many thanks @mherwege for - finally! - implementing this much requested and desired feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mherwege - here are some remarks and findings after testing:
MappingCommand -> %number | %identifier | %string | ||
Mapping -> MappingCommand _ %equals _ MappingLabel {% (d) => d[0][0].value.toString() + '=' + d[4][0].value.toString() %} | ||
MappingCommand -> %identifier | %string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
I have a sitemap with:
Selection item=Scene_General mappings=[1="Morning",10="Cinema",11="TV",3="Bed",4="Night"]
that doesn't parse anymore:
Error: Syntax error at line 3 col 48:
Selection item=Scene_General mappings=[1
^
Unexpected number token: "1". Instead, I was expecting to see one of the following:
...
Adding quotes fixes the problem:
which generates:
Selection item=Scene_General mappings=["1"="Morning","10"="Cinema","11"="TV","3"="Bed","4"="Night"]
but since the syntax is supported (see https://www.openhab.org/docs/ui/sitemaps.html#mappings) it should parse successfully without.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't have been removed
<f7-card-content v-if="attributes.length"> | ||
<f7-list inline-labels sortable @sortable:sort="onSort"> | ||
<f7-list-input v-for="(attr, idx) in attributes" :key="idx" | ||
:label="`#${idx+1}`" type="text" placeholder="command=Label" :value="attr" @input="updateAttribute(idx, $event)" clear-button /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The placeholder should probably be changed to a prop so that it can be configured in sitemap-editor.vue.
Here the placeholders are "command=Label" for all attribute editors even though it's not necessarily the correct syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
<template> | ||
<f7-card v-if="widget"> | ||
<f7-card-content v-if="attributes.length"> | ||
<f7-list inline-labels sortable @sortable:sort="onSort"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea to allow sorting, to enable sortable mode by default you would need:
<f7-list inline-labels sortable @sortable:sort="onSort"> | |
<f7-list inline-labels sortable sortable-opposite class="sortable-enable" @sortable:sort="onSort"> |
The handlers display but sorting doesn't quite work well (the indexes should be recomputed after the sorting and the new order is changed afterwards...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually didn't touch this code, but it indeed didn't work. It cost me some effort, but I think I figured out how to make it work. The index as a key doesn't do it, I needed to construct a key that changes when moving an item in the list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works great 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One additional comment that was left out:
let value = v.substring(0, v.search(/[=<>]/)) | ||
value += v.substring(v.search(/[=<>]/)).replace(/[A-Za-z][A-Za-z0-9 _-]*/, function (x) { return '"' + x + '"' }) | ||
return `${value}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I try this:
it works properly:
Text icon="frontdoor" item=HS1DSZDoorSensor_DoorSensor label="Front Door" valuecolor=[=="CLOSED"="blue",=="OPEN"="red"]
However when changed to:
which should be valid - https://www.openhab.org/docs/ui/sitemaps.html#label-and-value-colors - "If an operator is not specified, the operator will default to ==", the generated code becomes:
Text icon="frontdoor" item=HS1DSZDoorSensor_DoorSensor label="Front Door" valuecolor=[CLOSED=""blue"",OPEN=""red""]
and parsing chokes on the repeated double quotes around the colors.
The same seems to happen when an item name is specified in the designer e.g. HS1DSZDoorSensor_LastChange=="Uninitialized"
- extra double quotes are added:
Text icon="frontdoor" item=HS1DSZDoorSensor_DoorSensor label="Front Door" visibility=[HS1DSZDoorSensor_LastChange==""Uninitialized""]
In fact the examples in the sitemaps docs should probably all be tested & working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did one correction, and for me it now works on all examples that are in the documentation on the website. I did have to submit a small PR to correct a syntax error in one of the examples. Can you check again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems there are still some cases where the quotes aren't right (the color names don't have their quotes anymore) :)
(in fact I'd like to ask, why not simply copy what the user is providing verbatim?)
outputs:
visibility=[Day_Time=="Morning",Temperature>19]
labelcolor=[Temperature==22="green",Last_Update=="Uninitialized"=gray,LastUpdate=="OPEN"=red,22="green","gray"]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the original code, only for mapping:
} else if (key === 'mappings') {
dsl += '['
const mappingsDsl = widget.config.mappings.map((m) =>
`${m.split('=')[0]}="${m.substring(m.indexOf('=') + 1)}"`
)
dsl += mappingsDsl.join(',')
Notice it also adds quotes as they come without quotes from the widget.config. I tried generalizing for all, but that makes it more complex. Not sure if it works without these gymnastics.
Anyway, I think the missing element is to do the quoting not just once, but for all instances of strings, so just missing a 'g' in the replace regex.
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
@ghys I think I am done now. I wasn't happy on not being able to easily remove an added empty attribute (the clear button is not shown with an empty input). I now take care of it when converting to DSL and saving the sitemap, removing empty attribute lines. |
Yeah that was a problem indeed. It would be better I think to try removing them altogether if the arrays are empty, not just before the save, because when you remove all items for an attribute and switch to the Code tab you get this error that you can't get rid of:
(to be clear it's not your fault, that was an already existing bug, but maybe it'd be nice to have it solved.) |
import DirtyMixin from '../../dirty-mixin' | ||
import { isArray } from 'zrender/lib/core/util' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't right - zrender is a graphic library used in ECharts, importing it like that would screw up the webpack chunks and introduce an unwanted dependency.
You can just use https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, indeed, that is what I meant to use. Sorry about that.
I now don't create attributes for empty attribute arrays in DSL, but leave the empty lines until saving. That still allows the user to enter something before save. On save, the remaining empty ones will get removed. Also, if you would add the attribute in the code window, the empty lines will get replaced by the changes from the code window when switching back to the editor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright LGTM now!
Closes #324 - Many thanks again for implementing this after 2 years! 🥳
Great Work Thank to all that made this possible! |
I find that when the text of the sitemap has a quoted string: That quoted string looses the quotation in the YAML: This causes the error: |
@crcowan This should be fixed with the proposed core PR. |
These parameters should be number instead of text. See: #1487 (comment) Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
…#2033) These parameters should be number instead of text. See: openhab#1487 (comment) Signed-off-by: Mark Herwege <mark.herwege@telenet.be> Signed-off-by: Stefan Höhn <mail@stefanhoehn.com>
…#2033) These parameters should be number instead of text. See: openhab#1487 (comment) Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Mark Herwege mark.herwege@telenet.be
This PR adds the possibility to configure sitemap widget parameters so far only configurable through sitemap files. It should allow fully copying sitemap files into the UI and correctly interpreting it, with the possibility to modify in the UI.
This PR depends on PR#3075