waste zone/type/city info on device page

This commit is contained in:
lukas-heiligenbrunner 2020-01-18 08:42:08 +01:00
parent ce44ee5d17
commit fa16d1206b
12 changed files with 191 additions and 152 deletions

View File

@ -5,10 +5,10 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
public class JDCB { public class JDBC {
static Connection conn; static Connection conn;
static JDCB jdcb; static JDBC JDBC;
static boolean loggedin = false; static boolean loggedin = false;
static String usernamec; static String usernamec;
@ -21,19 +21,19 @@ public class JDCB {
usernamec = username; usernamec = username;
passwordc = password; passwordc = password;
dbnamec = dbname; dbnamec = dbname;
jdcb = new JDCB(username, password, dbname, ip, port); JDBC = new JDBC(username, password, dbname, ip, port);
} }
private JDCB(String username, String password, String dbname, String ip, int port) throws IOException { private JDBC(String username, String password, String dbname, String ip, int port) throws IOException {
logintodb(username, password, dbname, ip, port); logintodb(username, password, dbname, ip, port);
} }
public static JDCB getInstance() throws IOException { public static JDBC getInstance() throws IOException {
if (loggedin) { if (loggedin) {
return jdcb; return JDBC;
} else { } else {
logintodb(usernamec, passwordc, dbnamec, ipc, portc); logintodb(usernamec, passwordc, dbnamec, ipc, portc);
return jdcb; return JDBC;
} }
} }

View File

@ -1,37 +0,0 @@
package com.wasteinformationserver.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class PostgreSQLConnector extends Database {
static {
try {
Class.forName("org.postgresql.Driver").newInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
public PostgreSQLConnector(String user, String password, String host, int port, String dbName) {
super(user, password, host, port, dbName);
}
@Override
public Connection getConnection() {
Connection con = null;
try {
con = DriverManager.getConnection(
"jdbc:postgresql://" + host + ":" + port + "/" + dbName,
user,
password);
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
}

View File

@ -2,7 +2,7 @@ package com.wasteinformationserver;
import com.wasteinformationserver.basicutils.Info; import com.wasteinformationserver.basicutils.Info;
import com.wasteinformationserver.basicutils.Log; import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB; import com.wasteinformationserver.db.JDBC;
import com.wasteinformationserver.mqtt.MqttService; import com.wasteinformationserver.mqtt.MqttService;
import com.wasteinformationserver.website.Webserver; import com.wasteinformationserver.website.Webserver;
@ -32,8 +32,8 @@ public class main {
//initial connect to db //initial connect to db
Log.message("initial login to db"); Log.message("initial login to db");
try { try {
JDCB.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306); //JDBC.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306);
//JDCB.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306); JDBC.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306);
} catch (IOException e) { } catch (IOException e) {
//e.printStackTrace(); //e.printStackTrace();
Log.error("no connection to db"); Log.error("no connection to db");

View File

@ -1,7 +1,7 @@
package com.wasteinformationserver.mqtt; package com.wasteinformationserver.mqtt;
import com.wasteinformationserver.basicutils.Log; import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB; import com.wasteinformationserver.db.JDBC;
import org.eclipse.paho.client.mqttv3.*; import org.eclipse.paho.client.mqttv3.*;
import java.io.IOException; import java.io.IOException;
@ -14,12 +14,12 @@ import java.util.Date;
public class MqttService { public class MqttService {
private MqttClient client = null; private MqttClient client = null;
private String serveruri; private String serveruri;
JDCB db; JDBC db;
public MqttService(String serverurl, String port) { public MqttService(String serverurl, String port) {
serveruri = "tcp://" + serverurl + ":" + port; serveruri = "tcp://" + serverurl + ":" + port;
try { try {
db = JDCB.getInstance(); db = JDBC.getInstance();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -2,7 +2,7 @@ package com.wasteinformationserver.website.datarequests;
import com.wasteinformationserver.basicutils.Info; import com.wasteinformationserver.basicutils.Info;
import com.wasteinformationserver.basicutils.Log; import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB; import com.wasteinformationserver.db.JDBC;
import com.wasteinformationserver.website.basicrequest.PostRequest; import com.wasteinformationserver.website.basicrequest.PostRequest;
import java.io.IOException; import java.io.IOException;
@ -20,9 +20,9 @@ public class DataRequest extends PostRequest {
ResultSet set = null; ResultSet set = null;
int status = -1; int status = -1;
JDCB jdcb; JDBC jdbc;
try { try {
jdcb = JDCB.getInstance(); jdbc = JDBC.getInstance();
} catch (IOException e) { } catch (IOException e) {
Log.error("no connection to db"); Log.error("no connection to db");
return "{\"query\" : \"nodbconn\"}"; return "{\"query\" : \"nodbconn\"}";
@ -35,7 +35,7 @@ public class DataRequest extends PostRequest {
// check if wastezone and wasteregion already exists // check if wastezone and wasteregion already exists
Log.debug(params.get("cityname") + params.get("wastetype") + params.get("wastezone")); Log.debug(params.get("cityname") + params.get("wastetype") + params.get("wastezone"));
set = jdcb.executeQuery("select * from `cities` where `name`='" + params.get("cityname") + "' AND `wastetype`='" + params.get("wastetype") + "' AND `zone`='" + params.get("wastezone") + "'"); set = jdbc.executeQuery("select * from `cities` where `name`='" + params.get("cityname") + "' AND `wastetype`='" + params.get("wastetype") + "' AND `zone`='" + params.get("wastezone") + "'");
int size = 0; int size = 0;
try { try {
if (set != null) { if (set != null) {
@ -48,7 +48,7 @@ public class DataRequest extends PostRequest {
if (size == 0) { if (size == 0) {
//doesnt exist //doesnt exist
try { try {
status = jdcb.executeUpdate("INSERT INTO `cities`(`userid`, `name`, `wastetype`, `zone`) VALUES ('0','" + params.get("cityname") + "','" + params.get("wastetype") + "','" + params.get("wastezone") + "');"); status = jdbc.executeUpdate("INSERT INTO `cities`(`userid`, `name`, `wastetype`, `zone`) VALUES ('0','" + params.get("cityname") + "','" + params.get("wastetype") + "','" + params.get("wastezone") + "');");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -71,7 +71,7 @@ public class DataRequest extends PostRequest {
sb.append("}"); sb.append("}");
break; break;
case "getAllCities": case "getAllCities":
set = jdcb.executeQuery("select * from cities"); set = jdbc.executeQuery("select * from cities");
Log.debug(set.toString()); Log.debug(set.toString());
sb.append("{\"data\":["); sb.append("{\"data\":[");
try { try {
@ -95,7 +95,7 @@ public class DataRequest extends PostRequest {
//DELETE FROM `cities` WHERE `id`=0 //DELETE FROM `cities` WHERE `id`=0
sb.append("{"); sb.append("{");
try { try {
status = jdcb.executeUpdate("DELETE FROM `cities` WHERE `id`='" + params.get("id") + "'"); status = jdbc.executeUpdate("DELETE FROM `cities` WHERE `id`='" + params.get("id") + "'");
if (status == 1) { if (status == 1) {
//success //success
sb.append("\"status\" : \"success\""); sb.append("\"status\" : \"success\"");
@ -117,7 +117,7 @@ public class DataRequest extends PostRequest {
break; break;
case "getAllDates": case "getAllDates":
set = jdcb.executeQuery("SELECT pickupdates.id,pickupdates.pickupdate,cities.userid,cities.name,cities.wastetype,cities.zone " + set = jdbc.executeQuery("SELECT pickupdates.id,pickupdates.pickupdate,cities.userid,cities.name,cities.wastetype,cities.zone " +
"FROM `pickupdates` INNER JOIN `cities` ON pickupdates.citywastezoneid = cities.id"); "FROM `pickupdates` INNER JOIN `cities` ON pickupdates.citywastezoneid = cities.id");
sb.append("{\"data\":["); sb.append("{\"data\":[");
try { try {
@ -141,7 +141,7 @@ public class DataRequest extends PostRequest {
case "deletedate": case "deletedate":
sb.append("{"); sb.append("{");
try { try {
status = jdcb.executeUpdate("DELETE FROM `pickupdates` WHERE `id`='" + params.get("id") + "'"); status = jdbc.executeUpdate("DELETE FROM `pickupdates` WHERE `id`='" + params.get("id") + "'");
if (status == 1) { if (status == 1) {
//success //success
sb.append("\"status\" : \"success\""); sb.append("\"status\" : \"success\"");
@ -176,7 +176,7 @@ public class DataRequest extends PostRequest {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date(); Date date = new Date();
String time = sdf.format(date); String time = sdf.format(date);
set = jdcb.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '0000-12-27' AND '"+time+"'"); set = jdbc.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '0000-12-27' AND '"+time+"'");
set.last(); set.last();
sb.append("\"finshedcollections\":\"" + set.getRow() + "\""); sb.append("\"finshedcollections\":\"" + set.getRow() + "\"");
@ -185,15 +185,15 @@ public class DataRequest extends PostRequest {
date = new Date(date.getTime()+1 * 24 * 60 * 60 * 1000); date = new Date(date.getTime()+1 * 24 * 60 * 60 * 1000);
time = sdf.format(date); time = sdf.format(date);
set = jdcb.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '"+time+"' AND '2222-12-27'"); set = jdbc.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '"+time+"' AND '2222-12-27'");
set.last(); set.last();
sb.append(",\"futurecollections\":\"" + set.getRow() + "\""); sb.append(",\"futurecollections\":\"" + set.getRow() + "\"");
set = jdcb.executeQuery("select * from pickupdates"); set = jdbc.executeQuery("select * from pickupdates");
set.last(); set.last();
sb.append(",\"collectionnumber\":\"" + set.getRow() + "\""); sb.append(",\"collectionnumber\":\"" + set.getRow() + "\"");
set = jdcb.executeQuery("select * from `cities`"); set = jdbc.executeQuery("select * from `cities`");
set.last(); set.last();
sb.append(",\"citynumber\":\"" + set.getRow() + "\""); sb.append(",\"citynumber\":\"" + set.getRow() + "\"");
} catch (SQLException e) { } catch (SQLException e) {

View File

@ -1,7 +1,7 @@
package com.wasteinformationserver.website.datarequests; package com.wasteinformationserver.website.datarequests;
import com.wasteinformationserver.basicutils.Log; import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB; import com.wasteinformationserver.db.JDBC;
import com.wasteinformationserver.website.basicrequest.PostRequest; import com.wasteinformationserver.website.basicrequest.PostRequest;
import java.io.IOException; import java.io.IOException;
@ -13,9 +13,9 @@ public class DeviceRequest extends PostRequest {
@Override @Override
public String request(HashMap<String, String> params) { public String request(HashMap<String, String> params) {
JDCB jdcb = null; JDBC jdbc = null;
try { try {
jdcb = JDCB.getInstance(); jdbc = jdbc.getInstance();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -23,48 +23,68 @@ public class DeviceRequest extends PostRequest {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
switch (params.get("action")) { switch (params.get("action")) {
case "getdevices": case "getdevices":
ResultSet set = jdcb.executeQuery("SELECT * from devices"); ResultSet setunconfigured = jdbc.executeQuery("SELECT * FROM `devices` WHERE `CityID`=-1");
ResultSet setconfigured = jdbc.executeQuery("SELECT * FROM `devices` INNER JOIN `cities` ON devices.CityID = cities.id");
sb.append("{\"data\":["); sb.append("{\"data\":[");
try { try {
while (set.next()) { setconfigured.last();
int deviceid = set.getInt("DeviceID"); int configsize = setconfigured.getRow();
int cityid = set.getInt("CityID"); System.out.println(configsize);
if (cityid == -1) { setconfigured.first();
//not configured setconfigured.previous();
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 + "\"}"); while (setunconfigured.next()) {
} int deviceid = setunconfigured.getInt("DeviceID");
int cityid = setunconfigured.getInt("CityID");
if (!set.isLast()) { sb.append("{\"deviceid\":\"" + deviceid + "\",\"cityid\":\"" + cityid + "\"}");
if (!(setunconfigured.isLast() && configsize==0)) {
sb.append(","); sb.append(",");
} }
} }
while (setconfigured.next()) {
int deviceid = setconfigured.getInt("DeviceID");
int cityid = setconfigured.getInt("CityID");
String devicename = setconfigured.getString("DeviceName");
String devicelocation = setconfigured.getString("DeviceLocation");
String cityname = setconfigured.getString("name");
String wastetype = setconfigured.getString("wastetype");
String zone = setconfigured.getString("zone");
sb.append("{\"deviceid\":\"" + deviceid + "\",\"cityid\":\"" + cityid + "\",\"devicename\":\"" + devicename + "\",\"devicelocation\":\"" + devicelocation + "\",\"cityname\":\"" + cityname + "\",\"wastetype\":\"" + wastetype + "\",\"zone\":\"" + zone + "\"}");
if (!setconfigured.isLast()) {
sb.append(",");
}
}
sb.append("]}"); sb.append("]}");
System.out.println(sb.toString());
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
break; break;
case "getCitynames": case "getCitynames":
set = jdcb.executeQuery("select * from cities"); setunconfigured = jdbc.executeQuery("select * from cities");
Log.debug(set.toString()); Log.debug(setunconfigured.toString());
sb.append("{"); sb.append("{");
try { try {
String prev = ""; String prev = "";
while (set.next()) { while (setunconfigured.next()) {
if (prev.equals(set.getString("name"))) { if (prev.equals(setunconfigured.getString("name"))) {
} else { } else {
if (!set.isFirst()) { if (!setunconfigured.isFirst()) {
sb.append(","); sb.append(",");
} }
sb.append("\"" + set.getString("name") + "\":\"" + set.getString("name") + "\""); sb.append("\"" + setunconfigured.getString("name") + "\":\"" + setunconfigured.getString("name") + "\"");
} }
prev = set.getString("name"); prev = setunconfigured.getString("name");
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
@ -73,21 +93,21 @@ public class DeviceRequest extends PostRequest {
Log.debug(sb.toString()); Log.debug(sb.toString());
break; break;
case "getzones": case "getzones":
set = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' ORDER BY zone ASC"); setunconfigured = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' ORDER BY zone ASC");
Log.debug(set.toString()); Log.debug(setunconfigured.toString());
sb.append("{"); sb.append("{");
try { try {
int prev = 42; int prev = 42;
while (set.next()) { while (setunconfigured.next()) {
if (prev == set.getInt("zone")) { if (prev == setunconfigured.getInt("zone")) {
} else { } else {
sb.append("\"" + set.getInt("zone") + "\":\"" + set.getInt("zone") + "\""); sb.append("\"" + setunconfigured.getInt("zone") + "\":\"" + setunconfigured.getInt("zone") + "\"");
if (!set.isLast()) { if (!setunconfigured.isLast()) {
sb.append(","); sb.append(",");
} }
} }
prev = set.getInt("zone"); prev = setunconfigured.getInt("zone");
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
@ -95,21 +115,21 @@ public class DeviceRequest extends PostRequest {
sb.append("}"); sb.append("}");
break; break;
case "gettypes": case "gettypes":
set = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zonename") + "' ORDER BY zone ASC"); setunconfigured = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zonename") + "' ORDER BY zone ASC");
Log.debug(set.toString()); Log.debug(setunconfigured.toString());
sb.append("{"); sb.append("{");
try { try {
String prev = "42"; String prev = "42";
while (set.next()) { while (setunconfigured.next()) {
if (prev == set.getString("wastetype")) { if (prev == setunconfigured.getString("wastetype")) {
} else { } else {
sb.append("\"" + set.getString("wastetype") + "\":\"" + set.getString("wastetype") + "\""); sb.append("\"" + setunconfigured.getString("wastetype") + "\":\"" + setunconfigured.getString("wastetype") + "\"");
if (!set.isLast()) { if (!setunconfigured.isLast()) {
sb.append(","); sb.append(",");
} }
} }
prev = set.getString("wastetype"); prev = setunconfigured.getString("wastetype");
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
@ -117,21 +137,27 @@ public class DeviceRequest extends PostRequest {
sb.append("}"); sb.append("}");
break; break;
case "savetodb": case "savetodb":
set = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zonename") + "' AND `wastetype`='" + params.get("wastetype") + "'"); setunconfigured = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zonename") + "' AND `wastetype`='" + params.get("wastetype") + "'");
try { try {
set.last(); setunconfigured.last();
if (set.getRow() != 1) { if (setunconfigured.getRow() != 1) {
//error // TODO: 17.01.20 error handling
} else { } else {
int id = set.getInt("id"); int id = setunconfigured.getInt("id");
jdcb.executeUpdate("UPDATE devices SET `CityID`='" + id + "',`DeviceName`='" + params.get("devicename") + "',`DeviceLocation`='" + params.get("devicelocation") + "' WHERE `DeviceID`='" + params.get("deviceid") + "'"); jdbc.executeUpdate("UPDATE devices SET `CityID`='" + id + "',`DeviceName`='" + params.get("devicename") + "',`DeviceLocation`='" + params.get("devicelocation") + "' WHERE `DeviceID`='" + params.get("deviceid") + "'");
sb.append("{\"success\":\"true\"}");
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
break;
case "deleteDevice":
//'action=savetodb&cityname=' + cityname + '&zonename=' + zone+'&wastetype='+wastetype+'&devicename='+devicename+'&devicelocation='+devicelocation try {
int res = jdbc.executeUpdate("DELETE FROM devices WHERE `DeviceID`='" + params.get("id") + "'");
} catch (SQLException e) {
e.printStackTrace();
}
sb.append("{\"status\":\"success\"}");
break; break;
} }
return sb.toString(); return sb.toString();

View File

@ -1,7 +1,7 @@
package com.wasteinformationserver.website.datarequests; package com.wasteinformationserver.website.datarequests;
import com.wasteinformationserver.basicutils.Log; import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB; import com.wasteinformationserver.db.JDBC;
import com.wasteinformationserver.website.basicrequest.PostRequest; import com.wasteinformationserver.website.basicrequest.PostRequest;
import java.io.IOException; import java.io.IOException;
@ -13,17 +13,17 @@ public class NewDateRequest extends PostRequest {
@Override @Override
public String request(HashMap<String, String> params) { public String request(HashMap<String, String> params) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
JDCB jdcb; JDBC jdbc;
ResultSet set; ResultSet set;
try { try {
jdcb = JDCB.getInstance(); jdbc = JDBC.getInstance();
} catch (IOException e) { } catch (IOException e) {
Log.error("no connection to db"); Log.error("no connection to db");
return "{\"query\" : \"nodbconn\"}"; return "{\"query\" : \"nodbconn\"}";
} }
switch (params.get("action")) { switch (params.get("action")) {
case "getCitynames": case "getCitynames":
set = jdcb.executeQuery("select * from cities"); set = jdbc.executeQuery("select * from cities");
Log.debug(set.toString()); Log.debug(set.toString());
sb.append("{\"data\":["); sb.append("{\"data\":[");
try { try {
@ -48,7 +48,7 @@ public class NewDateRequest extends PostRequest {
Log.debug(sb.toString()); Log.debug(sb.toString());
break; break;
case "getzones": case "getzones":
set = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' ORDER BY zone ASC"); set = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' ORDER BY zone ASC");
Log.debug(set.toString()); Log.debug(set.toString());
sb.append("{\"data\":["); sb.append("{\"data\":[");
try { try {
@ -72,7 +72,7 @@ public class NewDateRequest extends PostRequest {
sb.append("}"); sb.append("}");
break; break;
case "gettypes": case "gettypes":
set = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='"+params.get("zonename")+"' ORDER BY zone ASC"); set = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='"+params.get("zonename")+"' ORDER BY zone ASC");
Log.debug(set.toString()); Log.debug(set.toString());
sb.append("{\"data\":["); sb.append("{\"data\":[");
try { try {
@ -98,13 +98,13 @@ public class NewDateRequest extends PostRequest {
case "newdate": case "newdate":
sb.append("{"); sb.append("{");
Log.debug(params); Log.debug(params);
set = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zone") + "' AND `wastetype`='" + params.get("wastetype") + "'"); set = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zone") + "' AND `wastetype`='" + params.get("wastetype") + "'");
try { try {
set.last(); set.last();
if (set.getRow() == 1) { if (set.getRow() == 1) {
Log.debug(set.getInt("id")); Log.debug(set.getInt("id"));
int status = jdcb.executeUpdate("INSERT INTO `pickupdates`(`citywastezoneid`, `pickupdate`) VALUES ('" + set.getInt("id") + "','" + params.get("date") + "')"); int status = jdbc.executeUpdate("INSERT INTO `pickupdates`(`citywastezoneid`, `pickupdate`) VALUES ('" + set.getInt("id") + "','" + params.get("date") + "')");
if (status == 1) { if (status == 1) {
sb.append("\"status\" : \"success\""); sb.append("\"status\" : \"success\"");
} else { } else {

View File

@ -1,7 +1,7 @@
package com.wasteinformationserver.website.datarequests; package com.wasteinformationserver.website.datarequests;
import com.wasteinformationserver.basicutils.Log; import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB; import com.wasteinformationserver.db.JDBC;
import com.wasteinformationserver.website.HttpTools; import com.wasteinformationserver.website.HttpTools;
import com.wasteinformationserver.website.basicrequest.PostRequest; import com.wasteinformationserver.website.basicrequest.PostRequest;
@ -16,9 +16,9 @@ public class RegisterRequest extends PostRequest {
String passhash = HttpTools.StringToMD5(params.get("password")); String passhash = HttpTools.StringToMD5(params.get("password"));
JDCB myjd = null; JDBC myjd = null;
try { try {
myjd = JDCB.getInstance(); myjd = JDBC.getInstance();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -1,7 +1,7 @@
package com.wasteinformationserver.website.datarequests.login; package com.wasteinformationserver.website.datarequests.login;
import com.wasteinformationserver.basicutils.Log; import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB; import com.wasteinformationserver.db.JDBC;
import com.wasteinformationserver.website.HttpTools; import com.wasteinformationserver.website.HttpTools;
import com.wasteinformationserver.website.basicrequest.PostRequest; import com.wasteinformationserver.website.basicrequest.PostRequest;
@ -19,16 +19,16 @@ public class LoginRequest extends PostRequest {
String password = params.get("password"); String password = params.get("password");
String username = params.get("username"); String username = params.get("username");
JDCB jdcb; JDBC jdbc;
try { try {
jdcb = JDCB.getInstance(); jdbc = JDBC.getInstance();
} catch (IOException e) { } catch (IOException e) {
Log.error("no connection to db"); Log.error("no connection to db");
return "{\"status\" : \"nodbconn\"}"; return "{\"status\" : \"nodbconn\"}";
} }
ResultSet s = jdcb.executeQuery("select * from user where username ='" + username + "'"); ResultSet s = jdbc.executeQuery("select * from user where username ='" + username + "'");
;
//new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation").executeQuery("select * from user where username ='" + username + "'"); //new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation").executeQuery("select * from user where username ='" + username + "'");
Log.debug("successfully logged in to db"); Log.debug("successfully logged in to db");
String response = "{\"accept\": false}"; String response = "{\"accept\": false}";

View File

@ -210,7 +210,7 @@
<div class="card-header"> <div class="card-header">
<h3 class="card-title"> <h3 class="card-title">
<i class="fas fa-chart-pie mr-1"></i> <i class="fas fa-chart-pie mr-1"></i>
Alle abholdaten All pickupdats
</h3> </h3>
</div><!-- /.card-header --> </div><!-- /.card-header -->
<div class="card-body"> <div class="card-body">

View File

@ -141,7 +141,7 @@
<!-- small box --> <!-- small box -->
<div class="small-box bg-info"> <div class="small-box bg-info">
<div class="inner"> <div class="inner">
<h3>150</h3> <h3>TODO</h3>
<p>Todo</p> <p>Todo</p>
</div> </div>
@ -156,7 +156,7 @@
<!-- small box --> <!-- small box -->
<div class="small-box bg-success"> <div class="small-box bg-success">
<div class="inner"> <div class="inner">
<h3>42</h3> <h3>TODO</h3>
<p>Devices</p> <p>Devices</p>
</div> </div>

View File

@ -1,25 +1,79 @@
$(document).ready(function () { $(document).ready(function () {
var devicetable = null;
reloadDevices();
$.post('/senddata/Devicedata', 'action=getdevices', function (data) { function reloadDevices() {
$.post('/senddata/Devicedata', 'action=getdevices', function (data) {
console.log(data); if (devicetable != null) {
for (var i = 0; i < data.data.length; i++) { devicetable.destroy();
var id = data.data[i].deviceid;
var cityid = data.data[i].cityid;
if (cityid == -1) {
$("#devices-tablebody").append("<tr><td>" + id + "</td><td>new Device</td><td><button deviceid=\"" + id + "\"type=\"button\" class=\"btn btn-primary configuredevicebutton\">Configure</button></td><td></td><td></td></tr>");
} else {
var devicename = data.data[i].devicename;
var devicelocation = data.data[i].devicelocation;
$("#devices-tablebody").append("<tr><td>" + id + "</td><td>" + devicename + "</td><td>" + devicelocation + "</td><td>" + cityid + "</td><td>DEL</td></tr>");
} }
console.log(); console.log(data);
//devices-tablebody
} $('#devices-tablebody').html("");
$(".delbtn").off();
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("<tr><td>" + id + "</td><td>new Device</td><td><button deviceid=\"" + id + "\"type=\"button\" class=\"btn btn-primary configuredevicebutton\">Configure</button></td><td></td><td><button dataid='" + id + "' type='button' class='delbtn btn btn-danger'>X</button></td></tr>");
} else {
var devicename = data.data[i].devicename;
var devicelocation = data.data[i].devicelocation;
var cityname = data.data[i].cityname;
var cityzone = data.data[i].zone;
var wastetype = data.data[i].wastetype;
//todo load right names from db
$("#devices-tablebody").append("<tr><td>" + id + "</td><td>" + devicename + "</td><td>" + devicelocation + "</td><td>" + cityname + "/" + wastetype + "/" + cityzone + "</td><td><button dataid='" + id + "' type='button' class='delbtn btn btn-danger'>X</button></td></tr>");
}
}
addDeleteButton();
addConfigDialog();
devicetable = $('#table-devices').DataTable();
}, 'json');
}
function addDeleteButton() {
$(".delbtn").click(function (event) {
var id = event.target.getAttribute("dataid");
console.log("clicked btn data " + id);
$.post('/senddata/Devicedata', 'action=deleteDevice&id=' + id, function (data) {
console.log(data);
if (data.status == "success") {
Swal.fire({
type: "success",
title: 'Successfully deleted city!',
html: 'This alert closes automatically.',
timer: 1000,
}).then((result) => {
console.log('Popup closed. ')
});
reloadDevices();
} else if (data.status == "dependenciesnotdeleted") {
Swal.fire({
type: "warning",
title: 'This city is a dependency of a date',
html: 'Do you want do delete it anyway with all dependencies?',
}).then((result) => {
console.log('Popup closed. ')
});
//todo set yes no button here
}
}, "json");
});
}
function addConfigDialog() {
$(".configuredevicebutton").click(function (event) { $(".configuredevicebutton").click(function (event) {
var id = event.target.getAttribute("deviceid"); var id = event.target.getAttribute("deviceid");
var cityname; var cityname;
@ -99,19 +153,17 @@ $(document).ready(function () {
html: 'This alert closes automatically.', html: 'This alert closes automatically.',
timer: 1000, timer: 1000,
}).then((result) => { }).then((result) => {
console.log('Popup closed. ') console.log('Popup closed. ');
reloadDevices();
}); });
} }
}); });
} }
}); });
}); });
} }
}); });
}); });
} }
}); });
}); });
@ -119,9 +171,7 @@ $(document).ready(function () {
console.log("click..." + id); console.log("click..." + id);
}); });
var test = $('#table-devices').DataTable(); }
}, 'json');
}); });