From 60d6bba12efff59ac53663b2892dc738406e7976 Mon Sep 17 00:00:00 2001 From: dorian Date: Mon, 22 Jul 2019 21:33:02 +0200 Subject: [PATCH] added js for for filling the locations list --- index.html | 7 +++---- js/blueweather.js | 30 +++++++++++++++++++++++++++++ js/index.js | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index eb29b6a..b58f7e0 100644 --- a/index.html +++ b/index.html @@ -66,9 +66,7 @@
current places
- - Placeholder + 32x32 @@ -119,7 +117,8 @@ - + + diff --git a/js/blueweather.js b/js/blueweather.js index 485bd8f..1d44577 100644 --- a/js/blueweather.js +++ b/js/blueweather.js @@ -8,6 +8,36 @@ class BlueWeather { this.log("init done", 2) } + getLocations(async, processingFunction, errorFunction) { + this.xhttp.abort() + var thisObject = this + + if(async) { + this.xhttp.onreadystatechange = function () { + if (this.readyState === 4) { + // Typical action to be performed when the document is ready: + if(this.status === 200) { + thisObject.log("getting sensors response was: " + this.responseText, 3) + var ret = JSON.parse(this.responseText) + if(ret){ + processingFunction(ret); + return + } + } + + if(errorFunction !== null) { + errorFunction(this.status, this.text) + } + } + }; + } + + var url = "https://weather.itsblue.de/api/json.php" + this.log("starting location request; URL is: " + url, 3) + this.xhttp.open("GET", url, async) + this.xhttp.send() + } + getLocationData(locId, range = {from:"", to:""}, maxVals = 0, async, processingFunction, errorFunction) { this.xhttp.abort() var thisObject = this diff --git a/js/index.js b/js/index.js index e69de29..ee493ef 100644 --- a/js/index.js +++ b/js/index.js @@ -0,0 +1,48 @@ +class BlueWeatherIndex { + + constructor() { + this.initDone = false + this.blueweather = new BlueWeather() + + this.initDone = true + + this.loadLocations() + } + + loadLocations () { + this.blueweather.getLocations(true, function(locations) { + var locationsList = document.getElementById("locationsList") + locationsList.innerHTML = "" + for(var location in locations) { + var thisLocation = locations[location] + + var locDiv = document.createElement("div") + locationsList.appendChild(locDiv) + locDiv.classList.add("media", "text-muted", "pt-3") + locDiv.innerHTML = '32x32' + + var locBody = document.createElement("p") + locDiv.appendChild(locBody) + locBody.classList.add("media-body", "pb-3", "mb-0", "small", "lh-125", "border-bottom", "border-gray") + + var locHeading = document.createElement("strong") + locBody.appendChild(locHeading) + locHeading.classList.add("d-block", "text-gray-dark") + + var locHeadingText = document.createElement("a") + locHeading.appendChild(locHeadingText) + locHeadingText.href = "dashboard.html?params=" + JSON.stringify({locId: thisLocation.id}) + locHeadingText.innerHTML = thisLocation.locationname + + var locLocationLink = document.createElement("a") + locBody.appendChild(locLocationLink) + locLocationLink.href = "https://www.openstreetmap.org/#map=19/" + thisLocation.latitude + "/" + thisLocation.longitude + locLocationLink.target = "blank" + locLocationLink.innerHTML = "View on map" + + } + }) + } +} + +index = new BlueWeatherIndex() \ No newline at end of file