Skip to content

Commit

Permalink
[BasicUI] Accept ISI8601 duration notation for chart period
Browse files Browse the repository at this point in the history
Also add few new default periods in the selection of chart period

Depends on openhab/openhab-core#3863

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo committed Nov 18, 2023
1 parent b4128cb commit ee1418f
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 ee1418f

Please sign in to comment.