* added table to device page

* request devices from js from db
This commit is contained in:
lukas-heiligenbrunner 2020-01-13 21:00:33 +01:00
parent ac02e4bd62
commit 92ef4cc0c6
7 changed files with 74 additions and 49 deletions

View File

@ -1,3 +1,6 @@
/**
* dead code...
*/
package com.wasteinformationserver;
import com.wasteinformationserver.basicutils.Log;

View File

@ -10,11 +10,10 @@ import java.io.IOException;
public class main {
public static void main(String[] args) {
Log.setLevel(Log.DEBUG);
Log.info("startup of WasteInformationServer");
Info.init();
Log.info("mem: " + Runtime.getRuntime().totalMemory());
Log.info("startup of WasteInformationServer");
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
@ -27,7 +26,6 @@ public class main {
}
}));
Info.init();
Log.info("Server version: " + Info.getVersion());
Log.debug("Build date: " + Info.getBuilddate());
@ -55,7 +53,5 @@ public class main {
} catch (Exception e) {
Log.error("An error occured in the class mqtt");
}
Log.info("mem: " + Runtime.getRuntime().totalMemory());
}
}

View File

@ -100,7 +100,7 @@ public class MqttService {
if (timestamp == timestampnow || timestamp == timestampnow + 86400000) { // 86400000 == one day
// valid time
// TODO: 12.01.20 read right waste type from db and replace below
// TODO: 12.01.20 read right waste type from db and replace below
tramsmitMessage(deviceid + "," + "Plastic" + "," + 1);
Log.debug("valid time");
return;

View File

@ -2,10 +2,7 @@ package com.wasteinformationserver.website;
import com.sun.net.httpserver.HttpServer;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.website.datarequests.AdminRequests;
import com.wasteinformationserver.website.datarequests.DataRequest;
import com.wasteinformationserver.website.datarequests.NewDateRequest;
import com.wasteinformationserver.website.datarequests.RegisterRequest;
import com.wasteinformationserver.website.datarequests.*;
import com.wasteinformationserver.website.datarequests.login.CheckLoginState;
import com.wasteinformationserver.website.datarequests.login.LoginRequest;
@ -29,6 +26,7 @@ public class Webserver {
server.createContext("/senddata/wastedata", new DataRequest());
server.createContext("/senddata/admindata", new AdminRequests());
server.createContext("/senddata/newdate", new NewDateRequest());
server.createContext("/senddata/Devicedata", new DeviceRequest());
server.setExecutor(null); // creates a default executor
server.start();

View File

@ -0,0 +1,43 @@
package com.wasteinformationserver.website.datarequests;
import com.wasteinformationserver.db.JDCB;
import com.wasteinformationserver.website.basicrequest.PostRequest;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
public class DeviceRequest extends PostRequest {
@Override
public String request(HashMap<String, String> params) {
JDCB jdcb = null;
try {
jdcb = JDCB.getInstance();
} catch (IOException e) {
e.printStackTrace();
}
switch (params.get("action")) {
case "getdevices":
ResultSet set = jdcb.executeQuery("SELECT * from devices");
StringBuilder sb = new StringBuilder("{\"data\":[");
try {
while (set.next()) {
sb.append("{\"name\":\"" + set.getString("devicename") + "\"}");
if (!set.isLast()) {
sb.append(",");
}
}
sb.append("]}");
return sb.toString();
} catch (SQLException e) {
e.printStackTrace();
}
break;
}
return null;
}
}

View File

@ -186,21 +186,35 @@
<table id="table-pickupdates" class="table table-bordered table-hover">
<thead>
<tr>
<th>City</th>
<th>Device ID</th>
<th>Devicename</th>
<th>Devicelocation</th>
<th>Zone</th>
<th>Waste Type</th>
<th>Date</th>
<th>X</th>
</tr>
</thead>
<tbody id="picupdates-tablebody">
<tr>
<td>42</td>
<td>new Device</td>
<td>
<button type="button" class="btn btn-primary">Configure</button>
</td>
</tr>
<tr>
<td>42</td>
<td>lukis anziges</td>
<td>htl steyr</td>
<td>Steyr/2/Plastic</td>
<td>del</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>City</th>
<th>Device ID</th>
<th>Devicename</th>
<th>Devicelocation</th>
<th>Zone</th>
<th>Waste Type</th>
<th>Date</th>
<th>X</th>
</tr>
</tfoot>

View File

@ -1,37 +1,8 @@
$(document).ready(function () {
$('#btn-newdevice').click(function (e) {
e.preventDefault();
Swal.showLoading({
title: 'No connection to Database',
html: 'Setup DB here --> <a href="index.html">click<a/>.',
});
$.post('/senddata/Devicedata', 'action=getdevices', function (data) {
// Swal.fire({
// type: "error",
// title: 'No connection to Database',
// html: 'Setup DB here --> <a href="index.html">click<a/>.',
// onBeforeOpen: () => {
// Swal.showLoading()
// },
// }).then((result) => {
// console.log('Popup closed. ')
//
// });
// $.post('/senddata/loginget', 'username=' + username + '&password=' + password, function (data) {
//
// console.log(data);
// if (data.status == "nodbconn"){
//
// }
// if (data.accept == true) {
// console.log("successfully logged in!");
// document.cookie = "username=" + username;
// window.location = 'dashboard.html';
// }
// }, 'json');
});
console.log(data);
}, 'json');
});