From b7dbbd36210bac0f5ac37648fcfd3268544308ab Mon Sep 17 00:00:00 2001 From: dorian Date: Tue, 30 Jul 2019 13:08:24 +0200 Subject: [PATCH] adapted to new maxVals spec --- dashboard.html | 8 ++++---- js/blueweather.js | 2 +- js/dashboard.js | 29 +++++++++++++++-------------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/dashboard.html b/dashboard.html index 74e72f2..e984fd5 100755 --- a/dashboard.html +++ b/dashboard.html @@ -129,12 +129,12 @@ Year - Today - This + Today + This Week - This + This Month - This + This Year diff --git a/js/blueweather.js b/js/blueweather.js index 099fffc..19f7fb7 100755 --- a/js/blueweather.js +++ b/js/blueweather.js @@ -123,7 +123,7 @@ class BlueWeather { }; } - var url = this.host + "/api/json.php?locId="+locId+"&range[from]="+range.from + "&range[to]="+range.to + "&maxVals=" + maxVals + var url = this.host + "/api/json.php?locId="+locId+"&range[from]="+range.from + "&range[to]="+range.to + "&maxVals[mode]=" + maxVals.mode + "&maxVals[count]=" + maxVals.count this.log("starting location request; URL is: " + url, 3) this.xhttp.open("GET", url, async) this.xhttp.send() diff --git a/js/dashboard.js b/js/dashboard.js index dbc3b9a..cd32a12 100755 --- a/js/dashboard.js +++ b/js/dashboard.js @@ -13,7 +13,10 @@ class BlueWeatherDashboard { this.params = { loc: 1, page: -1, - maxVals: 100, + maxVals: { + mode: 'avg', + count: 100 + }, range: { from: "", to: "" @@ -29,7 +32,7 @@ class BlueWeatherDashboard { loadDashboard() { window.history.pushState("object or string", "Title", this.buildUrl({ "params": JSON.stringify(this.params) })); - this.setTimeRange(this.params.from, this.params.to, false, false) + this.setTimeRange(this.params.range.from, this.params.range.to, false) // page: -1 for dashboard or sensor id var mainContent = document.getElementById('mainContent') @@ -226,31 +229,23 @@ class BlueWeatherDashboard { Object.assign(this.params, newParams) + console.log("params changed: " + JSON.stringify(this.params)) + window.history.pushState("object or string", "Title", this.buildUrl({ "params": JSON.stringify(this.params) })); this.loadDashboard() } - setTimeRange(from = "", to = "", offset = true, autoReload = true) { + setTimeRange(from = "", to = "", autoReload = true) { // offset: if true the gien times will be substracted from the current time to get the target time this.blueweather.log("changing time range; form: " + from + "; to: " + to + "; (now is: " + new Date().getTime() + ")", 3) - if (offset) { - if (from !== "") { - from = new Date().getTime() / 1000 - from - } - - if (to !== "") { - to = new Date().getTime() / 1000 - parseInt(to) - } - } - else { if (from !== "") { from = parseInt(from) } if (to !== "") { to = parseInt(to) } - } + var tmpFrom = from var tmpTo = to @@ -259,10 +254,16 @@ class BlueWeatherDashboard { tmpFrom = Math.round(new Date().getTime() / 1000 - 60 * 60 * 24) } + if(tmpFrom < 0) { + tmpFrom = Math.round(new Date().getTime() / 1000 + tmpFrom) + } + if (tmpTo === "") { tmpTo = Math.round(new Date().getTime() / 1000) } + console.log(tmpFrom) + var dateFromString = this.getDateTimeString(tmpFrom, tmpTo - tmpFrom) var dateToString = this.getDateTimeString(tmpTo, tmpTo - tmpFrom)