From e0daec4c67ebd336df29402737868d373be24ce9 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Mon, 2 Oct 2023 10:41:24 +0200 Subject: [PATCH] Add timely filter --- resources/js/main.js | 12 ++++++++++-- resources/static/index.html | 13 ++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/resources/js/main.js b/resources/js/main.js index f80df31..f998528 100644 --- a/resources/js/main.js +++ b/resources/js/main.js @@ -215,12 +215,20 @@ async function render_graph(plug, name) { old.remove(); } + // get start date + let start_text = document.getElementById("start").value; + let start_date = parseInt(new Date(start_text).getTime() / 1000).toFixed(0); + + // get end date1 + let end_text = document.getElementById("end").value; + let end_date = parseInt(new Date(end_text).getTime() / 1000).toFixed(0); + // create new chart div let chart = document.createElement('canvas'); chart.id = "chart"; const response = await fetch( - "/plug_data/" + plug, + "/plug_data/" + plug + "/" + start_date + "/" + end_date + "/" + "hourly", { method: "GET" } @@ -270,5 +278,5 @@ async function render_graph(plug, name) { } }); - document.getElementById("main").appendChild(chart); + document.getElementById("graph").appendChild(chart); } \ No newline at end of file diff --git a/resources/static/index.html b/resources/static/index.html index fa9bd51..756c5ec 100644 --- a/resources/static/index.html +++ b/resources/static/index.html @@ -2,10 +2,15 @@ + + + + Smart Homeserver - + + @@ -15,6 +20,12 @@ src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"> + + + + +
+
\ No newline at end of file