Initial commit
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import RoverApi from "./roverApi.js";
|
||||
|
||||
const api = new RoverApi();
|
||||
const body = document.getElementById("mainDivBody");
|
||||
|
||||
createBody();
|
||||
setInterval(checkNewData, 3 * 1000);
|
||||
|
||||
function checkNewData() {
|
||||
api.getRouteInfos(data => {
|
||||
body.innerText = JSON.stringify(data.infoObj, null, 2);
|
||||
});
|
||||
}
|
||||
|
||||
function createBody() {
|
||||
api.getRouteInfos(data => {
|
||||
body.innerHTML = JSON.stringify(data.infoObj, null, 2);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
const address = "http://rover.kleiax.de/api/";
|
||||
|
||||
class IrrigationApi {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
getRoute(id, callback) {
|
||||
httpGet(id, callback);
|
||||
}
|
||||
|
||||
getRouteInfos(callback) {
|
||||
httpGet('infos', callback);
|
||||
}
|
||||
|
||||
getRouteAmount(callback) {
|
||||
httpGet('amount', callback);
|
||||
}
|
||||
|
||||
deleteRoute(id, callback) {
|
||||
httpDelete(id, callback);
|
||||
}
|
||||
}
|
||||
|
||||
function httpGet(apiCall, callback) {
|
||||
var request = new XMLHttpRequest();
|
||||
request.open('GET', address + apiCall);
|
||||
request.onload = function () {
|
||||
const data = JSON.parse(request.response);
|
||||
|
||||
if (request.status >= 200 && request.status < 400) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log('Error irrigationApi.js httpGet()', data);
|
||||
}
|
||||
};
|
||||
request.send();
|
||||
}
|
||||
|
||||
|
||||
function httpDelete(apiCall, callback) {
|
||||
var request = new XMLHttpRequest();
|
||||
request.open('DELETE', address + apiCall);
|
||||
request.onload = function () {
|
||||
const data = JSON.parse(request.response);
|
||||
|
||||
if (request.status >= 200 && request.status < 400) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log('Error irrigationApi.js httpDelete()', data);
|
||||
}
|
||||
};
|
||||
request.send();
|
||||
}
|
||||
|
||||
export default IrrigationApi;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import RoverApi from "./roverApi.js";
|
||||
|
||||
const api = new RoverApi();
|
||||
const aside = document.getElementsByTagName("aside")[0];
|
||||
const amount = document.createElement("h2");
|
||||
|
||||
|
||||
createStatus();
|
||||
setInterval(checkNewStatus, 3 * 1000);
|
||||
|
||||
function checkNewStatus() {
|
||||
api.getRouteAmount(data => {
|
||||
amount.innerHTML = data.amount;
|
||||
});
|
||||
}
|
||||
|
||||
function createStatus() {
|
||||
api.getRouteAmount((data) => {
|
||||
const title = document.createElement("h2");
|
||||
title.innerHTML = "Anzahl <br> aller <br> Routen";
|
||||
amount.innerHTML = data.amount;
|
||||
aside.append(title);
|
||||
aside.append(amount);
|
||||
});
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user