Skip to content

Commit

Permalink
[BasicUI] Fix updating of the chart period parameter in URL (#2162)
Browse files Browse the repository at this point in the history
The period parameter syntax was extended.
Depends on openhab/openhab-core#3863

Also add few new default periods in the selection of chart period

Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo authored Nov 26, 2023
1 parent 2f67839 commit 3e27463
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,13 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) th
snippet = snippet.replace("%url%", url);
snippet = snippet.replace("%legend%", Boolean.valueOf(legend).toString());

List<List<String>> periods = List.of(List.of("Last hour", "h"), List.of("Last 4 hours", "4h"),
List.of("Last 8 hours", "8h"), List.of("Last 12 hours", "12h"), List.of("Last day", "D"),
List.of("Last 2 days", "2D"), List.of("Last 3 days", "3D"), List.of("Last week", "W"),
List.of("Last 2 weeks", "2W"), List.of("Last month", "M"), List.of("Last 2 months", "2M"),
List.of("Last 4 months", "4M"), List.of("Last year", "Y"));
List<List<String>> periods = List.of(List.of("Last hour", "h"), List.of("Last 2 hours", "2h"),
List.of("Last 4 hours", "4h"), List.of("Last 8 hours", "8h"), List.of("Last 12 hours", "12h"),
List.of("Last day", "D"), List.of("Last 2 days", "2D"), List.of("Last 3 days", "3D"),
List.of("Last week", "W"), List.of("Last 2 weeks", "2W"), List.of("Last month", "M"),
List.of("Last 2 months", "2M"), List.of("Last 3 months", "3M"), List.of("Last 4 months", "4M"),
List.of("Last 6 months", "6M"), List.of("Last 9 months", "9M"), List.of("Last year", "Y"),
List.of("Last 2 years", "2Y"));
StringBuilder rowSB = new StringBuilder();
for (List<String> period : periods) {
buildRow(chart, period.get(0), period.get(1), chart.getPeriod(), rowSB);
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.openhab.ui.basic/web-src/smarthome.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@
}

_t.period = event.target.getAttribute("value");
_t.url = _t.url.replace(/&period=(h|4h|8h|12h|D|2D|3D|W|2W|M|2M|4M|Y)/, "&period=" + _t.period);
_t.url = _t.url.replace(/&period=\w+/, "&period=" + _t.period);
_t.image.setAttribute("src", _t.url + "&t=" + Date.now());

setTimeout(function() {
Expand Down

0 comments on commit 3e27463

Please sign in to comment.