From ee1418f39bd2b560f62f73eac7539c8071ba5341 Mon Sep 17 00:00:00 2001 From: Laurent Garnier Date: Sat, 18 Nov 2023 14:26:20 +0100 Subject: [PATCH] [BasicUI] Accept ISI8601 duration notation for chart period Also add few new default periods in the selection of chart period Depends on openhab/openhab-core#3863 Signed-off-by: Laurent Garnier --- .../ui/basic/internal/render/ChartRenderer.java | 12 +++++++----- bundles/org.openhab.ui.basic/web-src/smarthome.js | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ChartRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ChartRenderer.java index f1e51da4f3..5b58674f71 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ChartRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ChartRenderer.java @@ -151,11 +151,13 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th snippet = snippet.replace("%url%", url); snippet = snippet.replace("%legend%", Boolean.valueOf(legend).toString()); - List> 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> 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 period : periods) { buildRow(chart, period.get(0), period.get(1), chart.getPeriod(), rowSB); diff --git a/bundles/org.openhab.ui.basic/web-src/smarthome.js b/bundles/org.openhab.ui.basic/web-src/smarthome.js index 01f4ab0853..2ed4674834 100644 --- a/bundles/org.openhab.ui.basic/web-src/smarthome.js +++ b/bundles/org.openhab.ui.basic/web-src/smarthome.js @@ -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() {