adapted to new maxVals spec

This commit is contained in:
dorian 2019-07-30 13:08:24 +02:00
parent 07f715eac9
commit b7dbbd3621
3 changed files with 20 additions and 19 deletions

View File

@ -129,12 +129,12 @@
Year</button>
</div>
</form-->
<a class="dropdown-item" href="#" onclick="dashboard.setTimeRange(86400)">Today</a>
<a class="dropdown-item" href="#" onclick="dashboard.setTimeRange(604800)">This
<a class="dropdown-item" href="#" onclick="dashboard.setTimeRange(-86400)">Today</a>
<a class="dropdown-item" href="#" onclick="dashboard.setTimeRange(-604800)">This
Week</a>
<a class="dropdown-item" href="#" onclick="dashboard.setTimeRange(2678400)">This
<a class="dropdown-item" href="#" onclick="dashboard.setTimeRange(-2678400)">This
Month</a>
<a class="dropdown-item" href="#" onclick="dashboard.setTimeRange(31536000)">This
<a class="dropdown-item" href="#" onclick="dashboard.setTimeRange(-31536000)">This
Year</a>
</div>
</div>

View File

@ -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()

View File

@ -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)