diff --git a/.idea/misc.xml b/.idea/misc.xml
index 5cd2caa..6619eb6 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -4,7 +4,7 @@
-
+
\ No newline at end of file
diff --git a/src/java/com/wasteinformationserver/mqtt/MqttService.java b/src/java/com/wasteinformationserver/mqtt/MqttService.java
index dabd55a..9c004a2 100644
--- a/src/java/com/wasteinformationserver/mqtt/MqttService.java
+++ b/src/java/com/wasteinformationserver/mqtt/MqttService.java
@@ -101,12 +101,12 @@ 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
- tramsmitMessage(deviceid + "," + "Plastic" + "," + 1);
+ tramsmitMessage(deviceid + "," + getIntTyp("Plastic") + "," + 1);
Log.debug("valid time");
return;
}
} while (result.next());
- tramsmitMessage(deviceid + "," + "Plastic" + "," + 0); //transmit zero if not returned before
+ tramsmitMessage(deviceid + "," + getIntTyp("Plastic") + "," + 0); //transmit zero if not returned before
}
} catch (SQLException | ParseException e) {
e.printStackTrace();
diff --git a/src/java/com/wasteinformationserver/website/datarequests/DeviceRequest.java b/src/java/com/wasteinformationserver/website/datarequests/DeviceRequest.java
index c12139d..488e4ef 100644
--- a/src/java/com/wasteinformationserver/website/datarequests/DeviceRequest.java
+++ b/src/java/com/wasteinformationserver/website/datarequests/DeviceRequest.java
@@ -1,5 +1,6 @@
package com.wasteinformationserver.website.datarequests;
+import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB;
import com.wasteinformationserver.website.basicrequest.PostRequest;
@@ -19,25 +20,107 @@ public class DeviceRequest extends PostRequest {
e.printStackTrace();
}
+ StringBuilder sb = new StringBuilder();
switch (params.get("action")) {
case "getdevices":
ResultSet set = jdcb.executeQuery("SELECT * from devices");
- StringBuilder sb = new StringBuilder("{\"data\":[");
+ sb.append("{\"data\":[");
try {
while (set.next()) {
- sb.append("{\"name\":\"" + set.getString("devicename") + "\"}");
+ int deviceid = set.getInt("DeviceID");
+ int cityid = set.getInt("CityID");
+ if (cityid == -1) {
+ //not configured
+ sb.append("{\"deviceid\":\"" + deviceid + "\",\"cityid\":\"" + cityid + "\"}");
+ } else {
+ String devicename = set.getString("DeviceName");
+ String devicelocation = set.getString("DeviceLocation");
+
+ sb.append("{\"deviceid\":\"" + deviceid + "\",\"cityid\":\"" + cityid + "\",\"devicename\":\"" + devicename + "\",\"devicelocation\":\"" + devicelocation + "\"}");
+ }
+
if (!set.isLast()) {
sb.append(",");
}
}
sb.append("]}");
- return sb.toString();
} catch (SQLException e) {
e.printStackTrace();
}
+ break;
+ case "getCitynames":
+ set = jdcb.executeQuery("select * from cities");
+ Log.debug(set.toString());
+ sb.append("{");
+ try {
+ String prev = "";
+ while (set.next()) {
+ if (prev.equals(set.getString("name"))) {
+
+ } else {
+ if (!set.isFirst()) {
+ sb.append(",");
+ }
+ sb.append("\"" + set.getString("name") + "\":\"" + set.getString("name") + "\"");
+ }
+ prev = set.getString("name");
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ sb.append("}");
+ Log.debug(sb.toString());
+ break;
+ case "getzones":
+ set = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' ORDER BY zone ASC");
+ Log.debug(set.toString());
+ sb.append("{\"data\":[");
+ try {
+ int prev = 42;
+ while (set.next()) {
+ if (prev == set.getInt("zone")) {
+
+ } else {
+ sb.append("{\"zone\":\"" + set.getInt("zone") + "\"}");
+ if (!set.isLast()) {
+ sb.append(",");
+ }
+ }
+ prev = set.getInt("zone");
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ sb.append("]");
+ sb.append(",\"query\":\"ok\"");
+ sb.append("}");
+ break;
+ case "gettypes":
+ set = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zonename") + "' ORDER BY zone ASC");
+ Log.debug(set.toString());
+ sb.append("{\"data\":[");
+ try {
+ String prev = "42";
+ while (set.next()) {
+ if (prev == set.getString("wastetype")) {
+
+ } else {
+ sb.append("{\"wastetype\":\"" + set.getString("wastetype") + "\"}");
+ if (!set.isLast()) {
+ sb.append(",");
+ }
+ }
+ prev = set.getString("wastetype");
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ sb.append("]");
+ sb.append(",\"query\":\"ok\"");
+ sb.append("}");
break;
}
- return null;
+ return sb.toString();
}
}
diff --git a/src/resources/wwwroot/device.html b/src/resources/wwwroot/device.html
index 531174c..b06d960 100644
--- a/src/resources/wwwroot/device.html
+++ b/src/resources/wwwroot/device.html
@@ -183,7 +183,7 @@
-
+
Device ID |
@@ -193,21 +193,7 @@
X |
-
-
- 42 |
- new Device |
-
-
- |
-
-
- 42 |
- lukis anziges |
- htl steyr |
- Steyr/2/Plastic |
- del |
-
+
diff --git a/src/resources/wwwroot/js/device.js b/src/resources/wwwroot/js/device.js
index f6ae7ef..8ba78db 100644
--- a/src/resources/wwwroot/js/device.js
+++ b/src/resources/wwwroot/js/device.js
@@ -1,8 +1,127 @@
$(document).ready(function () {
+
$.post('/senddata/Devicedata', 'action=getdevices', function (data) {
console.log(data);
+ for (var i = 0; i < data.data.length; i++) {
+ var id = data.data[i].deviceid;
+ var cityid = data.data[i].cityid;
+
+ if (cityid == -1) {
+ $("#devices-tablebody").append("
" + id + " | new Device | | | |
");
+ } else {
+ var devicename = data.data[i].devicename;
+ var devicelocation = data.data[i].devicelocation;
+
+ $("#devices-tablebody").append("" + id + " | " + devicename + " | " + devicelocation + " | " + cityid + " | DEL |
");
+ }
+ console.log();
+ //devices-tablebody
+
+ }
+ $(".configuredevicebutton").click(function (event) {
+ var id = event.target.getAttribute("deviceid");
+
+ $.post('/senddata/Devicedata', 'action=getCitynames', function (data) {
+ Swal.mixin({
+ input: 'text',
+ confirmButtonText: 'Next →',
+ showCancelButton: true,
+ progressSteps: ['1', '2', '3']
+ }).queue([
+ {
+ title: 'Name of device',
+ text: 'Please define a device name'
+ }, {
+ title: 'Location of device',
+ text: 'Please define a device location'
+ }, {
+ title: 'City',
+ text: 'Select your City',
+ input: 'select',
+ inputOptions: data
+ }
+ ]).then((result) => {
+ if (result.value) {
+ console.log(result.value);
+ const answers = JSON.stringify(result.value);
+
+ Swal.mixin({
+ input: 'text',
+ confirmButtonText: 'Next →',
+ showCancelButton: true,
+ progressSteps: ['1']
+ }).queue([
+ {
+ title: 'City',
+ text: 'Select your City',
+ input: 'select',
+ inputOptions: {
+ 'SRB': 'Serbia', // How do I dynamically set value?
+ 'UKR': 'Ukraine',
+ 'HRV': 'Croatia'
+ }
+ }
+ ]).then((result) => {
+ if (result.value) {
+ console.log(result.value);
+
+ Swal.mixin({
+ input: 'text',
+ confirmButtonText: 'Next →',
+ showCancelButton: true,
+ progressSteps: ['1']
+ }).queue([
+ {
+ title: 'City',
+ text: 'Select your City',
+ input: 'select',
+ inputOptions: {
+ 'SRB': 'Serbia', // How do I dynamically set value?
+ 'UKR': 'Ukraine',
+ 'HRV': 'Croatia'
+ }
+ }
+ ]).then((result) => {
+ if (result.value) {
+ console.log(result.value);
+ }
+ });
+ }
+ });
+ }
+ });
+ });
+
+
+ console.log("click..." + id);
+ });
+ /*
+ ,{
+ title: 'Zone',
+ text: 'Select the Waste Zone',
+ input: 'select',
+ inputOptions: {
+ 'SRB': 'Serbia', // How do I dynamically set value?
+ 'UKR': 'Ukraine',
+ 'HRV': 'Croatia'
+ }
+ },{
+ title: 'Type',
+ text: 'Select the Waste type',
+ input: 'select',
+ inputOptions: {
+ 'SRB': 'Serbia', // How do I dynamically set value?
+ 'UKR': 'Ukraine',
+ 'HRV': 'Croatia'
+ }
+ }
+ */
+
+ var test = $('#table-devices').DataTable();
}, 'json');
+
+
});