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

ui: Allow multiple same properties in single thing #1249

Merged

Conversation

rzr
Copy link
Contributor

@rzr rzr commented Aug 2, 2018

Previously item ids were duplicated,
the observed consequence is that any click on widgets
is seen as click on 1st declared element.

For example, a thing with 2 switches is displayed correctly,
and click events are also triggered but will be "redirected"
to 1st switch only, this is not desired.

Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65
Bug: #1148
Fixes #1148
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval p.coval@samsung.com

@rzr rzr force-pushed the sandbox/rzr/devel/review/master branch from 9a482e4 to 78ebf0e Compare August 2, 2018 13:49
rzr added a commit to TizenTeam/gateway that referenced this pull request Aug 2, 2018
Previously item ids were duplicated,
the observed consequence is that any click on widgets
is seen as click on 1st declared element.

For example, a thing with 2 switches is displayed correctly,
and click events are also triggered
but event will be "redirected" to 1st switch only,
this is not desired.

This change fix it for boolean related widget,
and once solution merged,
it can be easly replicated to others WoT types (level, text etc).

Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65
Bug: WebThingsIO#1148
Forwarded: WebThingsIO#1249
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval <p.coval@samsung.com>
@mrstegeman
Copy link
Contributor

@rzr

> eslint .

/home/travis/build/mozilla-iot/gateway/static/js/components/base-component.js
  15:11  error  'idSuffix' is assigned a value but never used. Allowed unused vars must match /^_/  no-unused-vars

/home/travis/build/mozilla-iot/gateway/static/js/components/property/boolean.js
  17:13  error  Infix operators must be spaced            space-infix-ops
  18:5   error  Unexpected var, use let or const instead  no-var

/home/travis/build/mozilla-iot/gateway/static/js/components/property/switch.js
  17:13  error  Infix operators must be spaced            space-infix-ops
  18:5   error  Unexpected var, use let or const instead  no-var

✖ 5 problems (5 errors, 0 warnings)
  4 errors, 0 warnings potentially fixable with the `--fix` option.

@rzr rzr force-pushed the sandbox/rzr/devel/review/master branch from 78ebf0e to 647ab4f Compare August 2, 2018 15:15
rzr added a commit to TizenTeam/gateway that referenced this pull request Aug 2, 2018
Previously item ids were duplicated,
the observed consequence is that any click on widgets
is seen as click on 1st declared element.

For example, a thing with 2 switches is displayed correctly,
and click events are also triggered
but event will be "redirected" to 1st switch only,
this is not desired.

This change fix it for boolean related widget,
and once solution merged,
it can be easly replicated to others WoT types (level, text etc).

Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65
Bug: WebThingsIO#1148
Forwarded: WebThingsIO#1249
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval <p.coval@samsung.com>
@codecov-io
Copy link

codecov-io commented Aug 2, 2018

Codecov Report

Merging #1249 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1249   +/-   ##
=======================================
  Coverage   75.33%   75.33%           
=======================================
  Files         123      123           
  Lines        5916     5916           
  Branches      824      824           
=======================================
  Hits         4457     4457           
  Misses       1287     1287           
  Partials      172      172

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c8a383f...68f5c51. Read the comment docs.

@rzr rzr force-pushed the sandbox/rzr/devel/review/master branch from 647ab4f to d9f6918 Compare August 2, 2018 15:22
rzr added a commit to TizenTeam/gateway that referenced this pull request Aug 2, 2018
Previously item ids were duplicated,
the observed consequence is that any click on widgets
is seen as click on 1st declared element.

For example, a thing with 2 switches is displayed correctly,
and click events are also triggered
but event will be "redirected" to 1st switch only,
this is not desired.

This change fix it for boolean related widget,
and once solution merged,
it can be easly replicated to others WoT types (level, text etc).

Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65
Bug: WebThingsIO#1148
Forwarded: WebThingsIO#1249
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval <p.coval@samsung.com>
@rzr rzr force-pushed the sandbox/rzr/devel/review/master branch from d9f6918 to cb9fa76 Compare August 3, 2018 00:01
rzr added a commit to TizenTeam/gateway that referenced this pull request Aug 3, 2018
Previously item ids were duplicated,
the observed consequence is that any click on widgets
is seen as click on 1st declared element.

For example, a thing with 2 switches is displayed correctly,
and click events are also triggered
but event will be "redirected" to 1st switch only,
this is not desired.

It was tested for boolean, number related components.

Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65
Bug: WebThingsIO#1148
Forwarded: WebThingsIO#1249
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval <p.coval@samsung.com>
@rzr rzr force-pushed the sandbox/rzr/devel/review/master branch from cb9fa76 to dd37b60 Compare August 3, 2018 08:40
rzr added a commit to TizenTeam/gateway that referenced this pull request Aug 3, 2018
Previously UI item's ids were duplicated,
the observed consequence is that any click on widgets
is catched by 1st declared element.

For example, a thing with 2 switches is displayed correctly,
and click events are also triggered
but event will be "redirected" to 1st switch only,
this is not desired.

It was tested for boolean, number related components.

Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65
Bug: WebThingsIO#1148
Forwarded: WebThingsIO#1249
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval <p.coval@samsung.com>
@rzr rzr force-pushed the sandbox/rzr/devel/review/master branch from dd37b60 to 3b7dea8 Compare August 3, 2018 17:15
rzr added a commit to TizenTeam/gateway that referenced this pull request Aug 3, 2018
Previously UI item's ids were duplicated,
the observed consequence is that any click on widgets
is catched by 1st declared element.

For example, a thing with 2 switches is displayed correctly,
and click events are also triggered
but event will be "redirected" to 1st switch only,
this is not desired.

It was tested for boolean, number related components.

Slider not fully updated, to keep passing tests,
more refactoring to come in that part (grep '#slide')

Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65
Bug: WebThingsIO#1148
Forwarded: WebThingsIO#1249
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval <p.coval@samsung.com>
@rzr rzr force-pushed the sandbox/rzr/devel/review/master branch from 3b7dea8 to 68f5c51 Compare August 3, 2018 18:13
rzr added a commit to TizenTeam/gateway that referenced this pull request Aug 3, 2018
Previously UI item's ids were duplicated,
the observed consequence is that any click on widgets
is catched by 1st declared element.

For example, a thing with 2 switches is displayed correctly,
and click events are also triggered
but event will be "redirected" to 1st switch only,
this is not desired.

It was tested for boolean, number related components.

Slider not fully updated, to keep passing tests,
more refactoring to come in that part (grep '#slider')

Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65
Bug: WebThingsIO#1148
Forwarded: WebThingsIO#1249
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval <p.coval@samsung.com>
rzr added a commit to TizenTeam/gateway that referenced this pull request Aug 4, 2018
Previously UI item's ids were duplicated,
the observed consequence is that any click on widgets
is catched by 1st declared element.

For example, a thing with 2 switches is displayed correctly,
and click events are also triggered
but event will be "redirected" to 1st switch only,
this is not desired.

It was tested for boolean, number related components.

Slider not fully updated, to keep passing tests,
more refactoring to come in that part (grep '#slider')

Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65
Bug: WebThingsIO#1148
Forwarded: WebThingsIO#1249
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval <p.coval@samsung.com>
rzr added a commit to TizenTeam/gateway that referenced this pull request Aug 4, 2018
To avoid clash LevelProperty's id are renamed to slide-level-${count}

It was tested on ARTIK05x thing (2 switches, 2 booleans, 2 levels)

Change-Id: If530737168af14eb8f6f1e9e230e04a432490045
Bug: WebThingsIO#1148
Forwarded: WebThingsIO#1249
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval <p.coval@samsung.com>
rzr added a commit to TizenTeam/gateway that referenced this pull request Aug 10, 2018
Previously UI item's ids were duplicated,
the observed consequence is that any click on widgets
is catched by 1st declared element.

For example, a thing with 2 switches is displayed correctly,
and click events are also triggered
but event will be "redirected" to 1st switch only,
this is not desired.

It was tested for boolean, number related components.

Slider not fully updated, to keep passing tests,
more refactoring to come in that part (grep '#slider')

Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65
Bug: WebThingsIO#1148
Forwarded: WebThingsIO#1249
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval <p.coval@samsung.com>
rzr added a commit to TizenTeam/gateway that referenced this pull request Aug 10, 2018
To avoid clash LevelProperty's id are renamed to slide-level-${count}

It was tested on ARTIK05x thing (2 switches, 2 booleans, 2 levels)

Change-Id: If530737168af14eb8f6f1e9e230e04a432490045
Bug: WebThingsIO#1148
Forwarded: WebThingsIO#1249
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval <p.coval@samsung.com>
@rzr
Copy link
Contributor Author

rzr commented Aug 10, 2018

If it helps, I can share an example to test using webthing-node (currently using webthing-iotjs)

artik710.png

rzr added a commit to TizenTeam/gateway that referenced this pull request Aug 21, 2018
Previously UI item's ids were duplicated,
the observed consequence is that any click on widgets
is catched by 1st declared element.

For example, a thing with 2 switches is displayed correctly,
and click events are also triggered
but event will be "redirected" to 1st switch only,
this is not desired.

It was tested for boolean, number related components.

Slider not fully updated, to keep passing tests,
more refactoring to come in that part (grep '#slider')

Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65
Bug: WebThingsIO#1148
Forwarded: WebThingsIO#1249
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval <p.coval@samsung.com>
rzr added a commit to TizenTeam/gateway that referenced this pull request Aug 21, 2018
Previously UI item's ids were duplicated,
the observed consequence is that any click on widgets
is catched by 1st declared element.

For example, a thing with 2 switches is displayed correctly,
and click events are also triggered
but event will be "redirected" to 1st switch only,
this is not desired.

It was tested for boolean, number related components.

Slider not fully updated, to keep passing tests,
more refactoring to come in that part (grep '#slider')

Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65
Bug: WebThingsIO#1148
Forwarded: WebThingsIO#1249
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval <p.coval@samsung.com>
Copy link
Contributor

@hobinjk hobinjk left a comment

Choose a reason for hiding this comment

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

This is a really comprehensive set of changes! I think it might be better to switch the querySelectors to use classes which are naturally less conflicting. I believe the reason for the issue with shadowRoot.querySelector is that if an id conflicts at the base document level there is nothing the webcomponents polyfill can do to constrain the querySelector within the shadowRoot. I'm hoping the behavior will be better with classes and not require switching over so much code to use this idSuffix construction (and introducing weird bugs if one fails to use idSuffix)

<div id="container" class="webthing-action-container">
<div id="contents" class="webthing-action-contents">
<button id="button" type="button" class="webthing-action-button"></button>
<div id="container-${BaseComponent.count}" class="webthing-action-container">
Copy link
Contributor

Choose a reason for hiding this comment

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

Since all of these elements are retrieved using this.shadowRoot.querySelector I believe a better way of solving the ID conflicts is to use querySelector with the class instead of the id and drop the id altogether.

super(template);

this._button = this.shadowRoot.querySelector('#button');
this._name = this.shadowRoot.querySelector('#name');
this._button = this.shadowRoot.querySelector(`#button${this.idSuffix}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

e.g. this becomes this.shadowRoot.querySelector('.webthing-action-button').

class="webthing-switch-property-switch">
<label id="slider" for="switch" class="webthing-switch-property-slider">
<label id="slider-${BaseComponent.count}" for="switch-${BaseComponent.count}" class="webthing-switch-property-slider">
Copy link
Contributor

Choose a reason for hiding this comment

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

Here the input might need to be nested within the label to allow the dropping of the for property which would otherwise be subject to an id conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes the next patch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got your point but I fear we still need IDs : see comments at bottom of : https://stackoverflow.com/questions/41811551/custom-styling-for-checkbox-with-input-within-label

I have updated the patch to make it smaller and easier to review, once OK I will generalize this to other widgets.

@rzr rzr force-pushed the sandbox/rzr/devel/review/master branch from 68f5c51 to 6fab303 Compare September 11, 2018 15:30
rzr added a commit to TizenTeam/gateway that referenced this pull request Sep 11, 2018
Previously UI item's ids were duplicated,
the observed consequence is that any click on widgets
is catched by 1st declared element.

For example, a thing with 2 switches is displayed correctly,
and click events are also triggered
but event will be "redirected" to 1st switch only,
this is not desired.

The change is only fixing boolean widgets, others to come later.

Note: It was suggested to use nested inputs,
but unfortunately CSS can't traverse (to input)
and get back to parent (label), so "for" facility and id must be used.

Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65
Bug: WebThingsIO#1148
Forwarded: WebThingsIO#1249
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval <p.coval@samsung.com>
Previously UI item's ids were duplicated,
the observed consequence is that any click on widgets
is catched by 1st declared element.

For example, a thing with 2 switches is displayed correctly,
and click events are also triggered
but event will be "redirected" to 1st switch only,
this is not desired.

The change is only fixing boolean widgets, others to come later.

Note: It was suggested to use nested inputs,
but unfortunately CSS can't traverse (to input)
and get back to parent (label), so "for" facility and id must be used.

Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65
Bug: WebThingsIO#1148
Forwarded: WebThingsIO#1249
Origin: https://github.com/tizenteam/gateway
Signed-off-by: Philippe Coval <p.coval@samsung.com>
@rzr rzr force-pushed the sandbox/rzr/devel/review/master branch from 6fab303 to 2bb23a5 Compare September 11, 2018 15:53
@rzr
Copy link
Contributor Author

rzr commented Sep 17, 2018

Feedback welcome, I plan to add changes for sliders soon

@codecov-io
Copy link

Codecov Report

Merging #1249 into master will increase coverage by 0.1%.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1249     +/-   ##
========================================
+ Coverage    75.1%   75.2%   +0.1%     
========================================
  Files         123     123             
  Lines        5989    5989             
  Branches      842     842             
========================================
+ Hits         4498    4504      +6     
+ Misses       1317    1312      -5     
+ Partials      174     173      -1
Impacted Files Coverage Δ
src/models/things.js 98.71% <0%> (+1.28%) ⬆️
src/models/thing.js 68.62% <0%> (+1.3%) ⬆️
src/db.js 82.08% <0%> (+1.73%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 89a9fee...acf9eb8. Read the comment docs.

@ghost ghost assigned mrstegeman Sep 18, 2018
Copy link
Contributor

@mrstegeman mrstegeman left a comment

Choose a reason for hiding this comment

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

This seems ok to me. @hobinjk do you have any other objections?

@codecov-io
Copy link

Codecov Report

Merging #1249 into master will decrease coverage by 0.1%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1249      +/-   ##
=========================================
- Coverage    75.1%     75%   -0.11%     
=========================================
  Files         123     125       +2     
  Lines        5989    6076      +87     
  Branches      842     848       +6     
=========================================
+ Hits         4498    4557      +59     
- Misses       1317    1344      +27     
- Partials      174     175       +1
Impacted Files Coverage Δ
src/controllers/logs_controller.js 82.97% <0%> (-13.45%) ⬇️
src/db.js 75.53% <0%> (-4.82%) ⬇️
src/router.js 96.42% <0%> (-1.69%) ⬇️
src/plugin/plugin.js 74.66% <0%> (-0.67%) ⬇️
src/plugin/addon-manager-proxy.js 80.91% <0%> (-0.63%) ⬇️
src/rules-engine/effects/index.js 100% <0%> (ø) ⬆️
src/constants.js 100% <0%> (ø) ⬆️
src/rules-engine/effects/NotificationEffect.js 36.36% <0%> (ø)
src/controllers/push_controller.js 58.62% <0%> (ø)
src/plugin/plugin-server.js 86.66% <0%> (+0.95%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 89a9fee...acf9eb8. Read the comment docs.

@WebThingsIO WebThingsIO deleted a comment from codecov-io Sep 18, 2018
@WebThingsIO WebThingsIO deleted a comment from codecov-io Sep 18, 2018
@hobinjk
Copy link
Contributor

hobinjk commented Sep 18, 2018

I'm still not a fan of introducing BaseComponent.count but that appears to be necessary for this to work so LGTM.

@mrstegeman mrstegeman merged commit 6f909b2 into WebThingsIO:master Sep 19, 2018
@ghost ghost removed the review label Sep 19, 2018
rzr added a commit to TizenTeam/gateway that referenced this pull request Sep 24, 2018
In case of multiple property of same types,
UI events were forwarded to 1st instance of widget.

This change is a follow up of the switch change:

Bug: WebThingsIO#1148
Relate-to: WebThingsIO#1249
Change-Id: I2018092168af14eb8f6f1e9e230e04a432490045
Signed-off-by: Philippe Coval <p.coval@samsung.com>
rzr added a commit to TizenTeam/gateway that referenced this pull request Sep 24, 2018
In case of multiple property of same types,
UI events were forwarded to 1st instance of widget.

This change is a follow up of the switch change:

Origin: WebThingsIO#1370
Bug: WebThingsIO#1148
Relate-to: WebThingsIO#1249
Change-Id: I2018092168af14eb8f6f1e9e230e04a432490045
Signed-off-by: Philippe Coval <p.coval@samsung.com>
mrstegeman pushed a commit that referenced this pull request Sep 25, 2018
* ui: Select by class instead of (multiple) id

In case of multiple property of same types,
UI events were forwarded to 1st instance of widget.

This change is a follow up of the switch change:

Origin: #1370
Bug: #1148
Relate-to: #1249
Change-Id: I2018092168af14eb8f6f1e9e230e04a432490045
Signed-off-by: Philippe Coval <p.coval@samsung.com>

* ui: Prevent duplicated id

This change has no real effect,
only for making code more uniform,

Note that slider id has been renamed to slider-level
to remove ambiguity with slider,
and counter suffix adjusted.

Forwarded: #1370
Change-Id: I64fe6a78a8ae9d300bab58561a7b0eec7bfb09db
Signed-off-by: Philippe Coval <p.coval@samsung.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants