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> Year</button>
</div> </div>
</form--> </form-->
<a class="dropdown-item" href="#" onclick="dashboard.setTimeRange(86400)">Today</a> <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(-604800)">This
Week</a> Week</a>
<a class="dropdown-item" href="#" onclick="dashboard.setTimeRange(2678400)">This <a class="dropdown-item" href="#" onclick="dashboard.setTimeRange(-2678400)">This
Month</a> Month</a>
<a class="dropdown-item" href="#" onclick="dashboard.setTimeRange(31536000)">This <a class="dropdown-item" href="#" onclick="dashboard.setTimeRange(-31536000)">This
Year</a> Year</a>
</div> </div>
</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.log("starting location request; URL is: " + url, 3)
this.xhttp.open("GET", url, async) this.xhttp.open("GET", url, async)
this.xhttp.send() this.xhttp.send()

View file

@ -13,7 +13,10 @@ class BlueWeatherDashboard {
this.params = { this.params = {
loc: 1, loc: 1,
page: -1, page: -1,
maxVals: 100, maxVals: {
mode: 'avg',
count: 100
},
range: { range: {
from: "", from: "",
to: "" to: ""
@ -29,7 +32,7 @@ class BlueWeatherDashboard {
loadDashboard() { loadDashboard() {
window.history.pushState("object or string", "Title", this.buildUrl({ "params": JSON.stringify(this.params) })); 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 // page: -1 for dashboard or sensor id
var mainContent = document.getElementById('mainContent') var mainContent = document.getElementById('mainContent')
@ -226,31 +229,23 @@ class BlueWeatherDashboard {
Object.assign(this.params, newParams) 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) })); window.history.pushState("object or string", "Title", this.buildUrl({ "params": JSON.stringify(this.params) }));
this.loadDashboard() 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 // 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) 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 !== "") { if (from !== "") {
from = parseInt(from) from = parseInt(from)
} }
if (to !== "") { if (to !== "") {
to = parseInt(to) to = parseInt(to)
} }
}
var tmpFrom = from var tmpFrom = from
var tmpTo = to var tmpTo = to
@ -259,10 +254,16 @@ class BlueWeatherDashboard {
tmpFrom = Math.round(new Date().getTime() / 1000 - 60 * 60 * 24) tmpFrom = Math.round(new Date().getTime() / 1000 - 60 * 60 * 24)
} }
if(tmpFrom < 0) {
tmpFrom = Math.round(new Date().getTime() / 1000 + tmpFrom)
}
if (tmpTo === "") { if (tmpTo === "") {
tmpTo = Math.round(new Date().getTime() / 1000) tmpTo = Math.round(new Date().getTime() / 1000)
} }
console.log(tmpFrom)
var dateFromString = this.getDateTimeString(tmpFrom, tmpTo - tmpFrom) var dateFromString = this.getDateTimeString(tmpFrom, tmpTo - tmpFrom)
var dateToString = this.getDateTimeString(tmpTo, tmpTo - tmpFrom) var dateToString = this.getDateTimeString(tmpTo, tmpTo - tmpFrom)