Skip to content
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

Merged
merged 12 commits into from
Oct 8, 2022
Merged

Add missing sitemap attributes #1487

merged 12 commits into from
Oct 8, 2022

Conversation

mherwege
Copy link
Contributor

@mherwege mherwege commented Sep 1, 2022

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

@mherwege mherwege requested a review from a team as a code owner September 1, 2022 19:48
@relativeci
Copy link

relativeci bot commented Sep 1, 2022

Job #549: Bundle Size — 11.33MB (+0.07%).

35c62fe(current) vs b99ff2b main#548(baseline)

Metrics (2 changes)
                 Current
Job #549
     Baseline
Job #548
Initial JS 1.7MB(-0.01%) 1.7MB
Initial CSS 607.98KB 607.98KB
Cache Invalidation 15.93% 41.75%
Chunks 218 218
Assets 242 242
Modules 1949 1949
Duplicate Modules 100 100
Duplicate Code 1.8% 1.8%
Packages 133 133
Duplicate Packages 15 15
Total size by type (1 change)
                 Current
Job #549
     Baseline
Job #548
CSS 855.93KB 855.93KB
Fonts 1.08MB 1.08MB
HTML 1.19KB 1.19KB
IMG 140.74KB 140.74KB
JS 8.98MB (+0.08%) 8.98MB
Media 295.6KB 295.6KB
Other 846B 846B

View job #549 reportView main branch activity

@mherwege
Copy link
Contributor Author

mherwege commented Sep 9, 2022

PR#3075 has been merged, so this PR should now work in a recent snapshot.

@ghys
Copy link
Member

ghys commented Sep 20, 2022

Many thanks @mherwege for - finally! - implementing this much requested and desired feature.
This looks good at first sight! 👍
But I'll make a thorough test & review in the following days, so thanks for your patience.

Copy link
Member

@ghys ghys left a 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:

Comment on lines 94 to 110
MappingCommand -> %number | %identifier | %string
Mapping -> MappingCommand _ %equals _ MappingLabel {% (d) => d[0][0].value.toString() + '=' + d[4][0].value.toString() %}
MappingCommand -> %identifier | %string
Copy link
Member

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:

image

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.

Copy link
Contributor Author

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 />
Copy link
Member

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.

Copy link
Contributor Author

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">
Copy link
Member

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:

Suggested change
<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...)

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works great 👍

Copy link
Member

@ghys ghys left a 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:

Comment on lines 22 to 24
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}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I try this:

image

it works properly:

Text icon="frontdoor" item=HS1DSZDoorSensor_DoorSensor label="Front Door" valuecolor=[=="CLOSED"="blue",=="OPEN"="red"]

However when changed to:

image

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.

Copy link
Contributor Author

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?

Copy link
Member

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?)

image

outputs:

visibility=[Day_Time=="Morning",Temperature>19]
labelcolor=[Temperature==22="green",Last_Update=="Uninitialized"=gray,LastUpdate=="OPEN"=red,22="green","gray"]

Copy link
Contributor Author

@mherwege mherwege Oct 8, 2022

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.

@mherwege mherwege requested a review from ghys October 6, 2022 20:20
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>
@mherwege
Copy link
Contributor Author

mherwege commented Oct 7, 2022

@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.
All other remarks in the review should have been covered as well.

@ghys
Copy link
Member

ghys commented Oct 7, 2022

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:

Error: Syntax error at line 9 col 92:

     Text icon="window" item=FGDW002WindowSensor_Open label="Window" visibility=[]
                                                                                 ^
Unexpected rbracket token: "]". Instead, I was expecting to see one of the following:

(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'
Copy link
Member

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.

Copy link
Contributor Author

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.

Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
@mherwege
Copy link
Contributor Author

mherwege commented Oct 8, 2022

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:

Error: Syntax error at line 9 col 92:

     Text icon="window" item=FGDW002WindowSensor_Open label="Window" visibility=[]
                                                                                 ^
Unexpected rbracket token: "]". Instead, I was expecting to see one of the following:

(to be clear it's not your fault, that was an already existing bug, but maybe it'd be nice to have it solved.)

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.

@mherwege mherwege requested a review from ghys October 8, 2022 08:40
Copy link
Member

@ghys ghys left a 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! 🥳

@ghys ghys merged commit 72fe51e into openhab:main Oct 8, 2022
@ghys ghys added enhancement New feature or request main ui Main UI labels Oct 8, 2022
@ghys ghys added this to the 3.4 milestone Oct 8, 2022
@mherwege mherwege deleted the sitemaps branch October 10, 2022 07:29
@jimmys01
Copy link

Great Work Thank to all that made this possible!
I have some issues.
-Commends in the file make it complain.
-At sliders the sendFrequency attribute is not recognized.
example
Slider item=RGB_middle_Speed sendFrequency=1000 switchSupport minValue=1 maxValue=40 step=2 labelcolor=[RGB_middle_Unreach==CLOSED="red"]

@crcowan
Copy link

crcowan commented Aug 10, 2023

I find that when the text of the sitemap has a quoted string:
Text icon="text" item=Picture_Information_CaptionAbstract label="Caption/Abstract" visibility=[Picture_Information_CaptionAbstract!="Not Available"]

That quoted string looses the quotation in the YAML:
{ "component": "Text", "config": { "icon": "text", "item": "Picture_Information_CaptionAbstract", "label": "Caption/Abstract", "visibility": [ "Picture_Information_CaptionAbstract!=Not Available" ] }

This causes the error:
2023-08-10 15:03:20.358 [WARN ] [omponents.UIComponentSitemapProvider] - Syntax error in visibility rule 'Picture_Information_CaptionAbstract!=Not Available' for widget Text

@mherwege
Copy link
Contributor Author

@crcowan This should be fixed with the proposed core PR.

ghys pushed a commit that referenced this pull request Sep 5, 2023
These parameters should be number instead of text.

See: #1487 (comment)

Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
stefan-hoehn pushed a commit to stefan-hoehn/openhab-webui that referenced this pull request Sep 23, 2023
…#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>
digitaldan pushed a commit to digitaldan/openhab-webui that referenced this pull request Sep 24, 2023
…#2033)

These parameters should be number instead of text.

See: openhab#1487 (comment)

Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
@mherwege mherwege mentioned this pull request Sep 25, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request main ui Main UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants