Initial commit

This commit is contained in:
root
2023-04-27 14:46:18 +00:00
commit bbca1a86d1
35 changed files with 2418 additions and 0 deletions
+19
View File
@@ -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);
});
}
+57
View File
@@ -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;
+26
View File
@@ -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);
});
}