Compare commits
27 Commits
0.1-Beta
...
v0.3.0-Bet
Author | SHA1 | Date | |
---|---|---|---|
ce44ee5d17 | |||
23f75cae4f | |||
b9ba0dbcef | |||
92ef4cc0c6 | |||
ac02e4bd62 | |||
c3fb92d6eb | |||
05b15a1ea2 | |||
86dc38a8da | |||
7c8a0d3018 | |||
4b96ad576d | |||
f7383474ac | |||
0518c1c809 | |||
c44a0dd9ec | |||
28d5ba0b03 | |||
7ca16400d4 | |||
a1b3998890 | |||
27c2b9ceb4 | |||
3a82f81c1a | |||
1ef61f13ab | |||
e26258c3cf | |||
b1e7de952a | |||
89426cfcee | |||
e4f9d88cda | |||
ab1ce79900 | |||
f32dbd802b | |||
23bffc4c6e | |||
97214d786e |
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@ -6,6 +6,7 @@
|
|||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
<option name="delegatedBuild" value="true" />
|
<option name="delegatedBuild" value="true" />
|
||||||
<option name="testRunner" value="GRADLE" />
|
<option name="testRunner" value="GRADLE" />
|
||||||
|
<option name="disableWrapperSourceDistributionNotification" value="true" />
|
||||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="gradleJvm" value="11" />
|
<option name="gradleJvm" value="11" />
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
import java.text.SimpleDateFormat
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'com.wasteinformationserver'
|
group 'com.wasteinformationserver'
|
||||||
version '0.1-Beta'
|
version '0.3.0-Beta'
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
|
|
||||||
@ -39,6 +41,7 @@ task createProperties(dependsOn: processResources) {
|
|||||||
new File("$projectDir/src/resources/version.properties").withWriter { w ->
|
new File("$projectDir/src/resources/version.properties").withWriter { w ->
|
||||||
Properties p = new Properties()
|
Properties p = new Properties()
|
||||||
p['version'] = project.version.toString()
|
p['version'] = project.version.toString()
|
||||||
|
p['buildtime'] = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date())
|
||||||
p.store w, null
|
p.store w, null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* dead code...
|
||||||
|
*/
|
||||||
package com.wasteinformationserver;
|
package com.wasteinformationserver;
|
||||||
|
|
||||||
import com.wasteinformationserver.basicutils.Log;
|
import com.wasteinformationserver.basicutils.Log;
|
||||||
|
@ -1,35 +1,58 @@
|
|||||||
package com.wasteinformationserver.basicutils;
|
package com.wasteinformationserver.basicutils;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.text.NumberFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class Info {
|
public class Info {
|
||||||
public static String version="0.0";
|
private static String version="not init";
|
||||||
public static String builddate;
|
private static String builddate="not init";
|
||||||
|
private static String starttime="not init";
|
||||||
|
|
||||||
|
public static String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getBuilddate() {
|
||||||
|
return builddate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getStarttime() {
|
||||||
|
return starttime;
|
||||||
|
}
|
||||||
|
|
||||||
public static void init(){
|
public static void init(){
|
||||||
|
starttime = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date());
|
||||||
Properties prop = new Properties();
|
Properties prop = new Properties();
|
||||||
try {
|
try {
|
||||||
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
|
||||||
|
|
||||||
URL url = Info.class.getResource("/version.properties");
|
URL url = Info.class.getResource("/version.properties");
|
||||||
|
|
||||||
String builddatee = format.format(new Date(new File(url.toURI()).lastModified()));
|
|
||||||
builddate=builddatee;
|
|
||||||
|
|
||||||
prop.load(url.openStream());
|
prop.load(url.openStream());
|
||||||
version=(String)prop.get("version");
|
version=(String)prop.get("version");
|
||||||
|
builddate=(String)prop.get("buildtime");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (URISyntaxException e) {
|
}
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void getMemoryUsage(){
|
||||||
|
Runtime runtime = Runtime.getRuntime();
|
||||||
|
|
||||||
|
NumberFormat format = NumberFormat.getInstance();
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
long maxMemory = runtime.maxMemory();
|
||||||
|
long allocatedMemory = runtime.totalMemory();
|
||||||
|
long freeMemory = runtime.freeMemory();
|
||||||
|
|
||||||
|
sb.append("free memory: " + format.format(freeMemory / 1024) + "\n");
|
||||||
|
sb.append("allocated memory: " + format.format(allocatedMemory / 1024) + "\n");
|
||||||
|
sb.append("max memory: " + format.format(maxMemory / 1024) + "\n");
|
||||||
|
sb.append("total free memory: " + format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024) + "\n");
|
||||||
|
|
||||||
|
System.out.println(sb.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
package com.wasteinformationserver.db;
|
package com.wasteinformationserver.db;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
@ -19,7 +19,7 @@ public class MySQLConnector extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Connection getConnection() throws SQLException {
|
public Connection getConnection() throws SQLException {
|
||||||
DriverManager.setLoginTimeout(1); // TODO: 30.11.19 set higher maybe
|
DriverManager.setLoginTimeout(1);
|
||||||
return DriverManager.getConnection(
|
return DriverManager.getConnection(
|
||||||
"jdbc:mysql://" + host + ":" + port + "/" + dbName + "?useSSL=false",
|
"jdbc:mysql://" + host + ":" + port + "/" + dbName + "?useSSL=false",
|
||||||
user,
|
user,
|
||||||
|
@ -3,16 +3,17 @@ 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.JDCB;
|
||||||
import com.wasteinformationserver.mqtt.mqtt;
|
import com.wasteinformationserver.mqtt.MqttService;
|
||||||
import com.wasteinformationserver.website.Webserver;
|
import com.wasteinformationserver.website.Webserver;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class main {
|
public class main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
Log.setLevel(Log.DEBUG);
|
Log.setLevel(Log.DEBUG);
|
||||||
Log.info("startup of WasteInformationServer");
|
Info.init();
|
||||||
|
|
||||||
|
Log.info("startup of WasteInformationServer");
|
||||||
|
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
@ -25,13 +26,11 @@ public class main {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Info.init();
|
Log.info("Server version: " + Info.getVersion());
|
||||||
Log.info("Server version: "+Info.version);
|
Log.debug("Build date: " + Info.getBuilddate());
|
||||||
Log.debug("Build date: "+Info.builddate);
|
|
||||||
|
|
||||||
//initial connect to db
|
//initial connect to db
|
||||||
Log.message("initial login to db");
|
Log.message("initial login to db");
|
||||||
new Thread(() -> {
|
|
||||||
try {
|
try {
|
||||||
JDCB.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306);
|
JDCB.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306);
|
||||||
//JDCB.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306);
|
//JDCB.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306);
|
||||||
@ -39,7 +38,6 @@ public class main {
|
|||||||
//e.printStackTrace();
|
//e.printStackTrace();
|
||||||
Log.error("no connection to db");
|
Log.error("no connection to db");
|
||||||
}
|
}
|
||||||
}).start();
|
|
||||||
|
|
||||||
|
|
||||||
//startup web server
|
//startup web server
|
||||||
@ -50,10 +48,10 @@ public class main {
|
|||||||
//startup mqtt service
|
//startup mqtt service
|
||||||
Log.message("starting mqtt service");
|
Log.message("starting mqtt service");
|
||||||
try {
|
try {
|
||||||
mqtt m = new mqtt();
|
MqttService m = new MqttService("mqtt.heili.eu", "1883");
|
||||||
m.notifymessage();
|
m.startupService();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.debug("An error was happened in the class mqtt");
|
Log.error("An error occured in the class mqtt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +0,0 @@
|
|||||||
package com.wasteinformationserver.mqtt;
|
|
||||||
|
|
||||||
public class Database {
|
|
||||||
}
|
|
174
src/java/com/wasteinformationserver/mqtt/MqttService.java
Normal file
174
src/java/com/wasteinformationserver/mqtt/MqttService.java
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
package com.wasteinformationserver.mqtt;
|
||||||
|
|
||||||
|
import com.wasteinformationserver.basicutils.Log;
|
||||||
|
import com.wasteinformationserver.db.JDCB;
|
||||||
|
import org.eclipse.paho.client.mqttv3.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class MqttService {
|
||||||
|
private MqttClient client = null;
|
||||||
|
private String serveruri;
|
||||||
|
JDCB db;
|
||||||
|
|
||||||
|
public MqttService(String serverurl, String port) {
|
||||||
|
serveruri = "tcp://" + serverurl + ":" + port;
|
||||||
|
try {
|
||||||
|
db = JDCB.getInstance();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startupService() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
client = new MqttClient(serveruri, "JavaSample42");
|
||||||
|
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||||
|
connOpts.setCleanSession(true);
|
||||||
|
client.connect(connOpts);
|
||||||
|
|
||||||
|
client.setCallback(new MqttCallback() {
|
||||||
|
@Override
|
||||||
|
public void connectionLost(Throwable throwable) {
|
||||||
|
Log.error("connection lost");
|
||||||
|
// TODO: 12.01.20 reconnect
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void messageArrived(String s, MqttMessage mqttMessage) {
|
||||||
|
String message = new String(mqttMessage.getPayload());
|
||||||
|
Log.message("received Request from PCB");
|
||||||
|
|
||||||
|
ResultSet res = db.executeQuery("SELECT * from devices WHERE DeviceID=" + message);
|
||||||
|
try {
|
||||||
|
res.last();
|
||||||
|
if (res.getRow() != 0) {
|
||||||
|
//existing device
|
||||||
|
res.first();
|
||||||
|
int cityid = res.getInt("CityID");
|
||||||
|
if (cityid == -1) {
|
||||||
|
//device not configured yet
|
||||||
|
tramsmitMessage(message + ",-1");
|
||||||
|
} else {
|
||||||
|
checkDatabase(cityid, Integer.parseInt(message));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//new device
|
||||||
|
db.executeUpdate("INSERT INTO devices (DeviceID) VALUES (" + message + ")");
|
||||||
|
Log.info("new device registered to server");
|
||||||
|
tramsmitMessage(message + ",-1");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
client.subscribe("TopicIn");
|
||||||
|
} catch (MqttException e) {
|
||||||
|
Log.error("Connection to the Broker failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkDatabase(int citywastezoneid, int deviceid) {
|
||||||
|
int wastetype = -1;
|
||||||
|
ResultSet set2 = db.executeQuery("SELECT * FROM cities WHERE `id`='" + citywastezoneid + "'");
|
||||||
|
try {
|
||||||
|
set2.last();
|
||||||
|
if (set2.getRow() != 1) {
|
||||||
|
//error
|
||||||
|
} else {
|
||||||
|
String typ = set2.getString("wastetype");
|
||||||
|
wastetype = getIntTyp(typ);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ResultSet result = db.executeQuery("SELECT pickupdates.pickupdate FROM pickupdates WHERE pickupdates.citywastezoneid=" + citywastezoneid);
|
||||||
|
try {
|
||||||
|
result.last();
|
||||||
|
if (result.getRow() == 0) {
|
||||||
|
//if not found in db --> send zero
|
||||||
|
Log.debug("not found in db");
|
||||||
|
|
||||||
|
tramsmitMessage(deviceid + "," + wastetype + "," + 0);
|
||||||
|
} else {
|
||||||
|
Log.debug(result.getString("pickupdate"));
|
||||||
|
|
||||||
|
result.first();
|
||||||
|
do {
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
long timestamp = formatter.parse(result.getString("pickupdate")).getTime();
|
||||||
|
long timestampnow = formatter.parse(formatter.format(new Date())).getTime();
|
||||||
|
Log.debug("timestamp is :" + timestamp);
|
||||||
|
|
||||||
|
if (timestamp == timestampnow || timestamp == timestampnow + 86400000) { // 86400000 == one day
|
||||||
|
// valid time
|
||||||
|
tramsmitMessage(deviceid + "," + wastetype + "," + 1);
|
||||||
|
Log.debug("valid time");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} while (result.next());
|
||||||
|
tramsmitMessage(deviceid + "," + wastetype + "," + 0); //transmit zero if not returned before
|
||||||
|
}
|
||||||
|
} catch (SQLException | ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void tramsmitMessage(String temp) {
|
||||||
|
Log.debug("sending message >>>"+temp);
|
||||||
|
MqttMessage message = new MqttMessage(temp.getBytes());
|
||||||
|
message.setQos(2);
|
||||||
|
try {
|
||||||
|
client.publish("TopicOut", message);
|
||||||
|
} catch (MqttException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getTyp(int number) {
|
||||||
|
if (number == 1) {
|
||||||
|
return "Plastic";
|
||||||
|
} else if (number == 2) {
|
||||||
|
return "Metal";
|
||||||
|
} else if (number == 3) {
|
||||||
|
return "Residual waste";
|
||||||
|
} else if (number == 4) {
|
||||||
|
return "Biowaste";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getIntTyp(String temp) {
|
||||||
|
int number = 0;
|
||||||
|
switch (temp) {
|
||||||
|
case "Plastic":
|
||||||
|
number = 1;
|
||||||
|
break;
|
||||||
|
case "Metal":
|
||||||
|
number = 2;
|
||||||
|
break;
|
||||||
|
case "Residual waste":
|
||||||
|
number = 3;
|
||||||
|
break;
|
||||||
|
case "Biowaste":
|
||||||
|
number = 4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
}
|
@ -1,123 +0,0 @@
|
|||||||
package com.wasteinformationserver.mqtt;
|
|
||||||
|
|
||||||
import com.wasteinformationserver.basicutils.Log;
|
|
||||||
import com.wasteinformationserver.db.JDCB;
|
|
||||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
|
||||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
|
||||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.GregorianCalendar;
|
|
||||||
|
|
||||||
public class mqtt {
|
|
||||||
MqttClient client = null;
|
|
||||||
|
|
||||||
public mqtt() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void notifymessage() {
|
|
||||||
|
|
||||||
try {
|
|
||||||
client = new MqttClient("tcp://192.168.65.15:1883", "JavaSample");
|
|
||||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
|
||||||
connOpts.setCleanSession(true);
|
|
||||||
client.connect(connOpts);
|
|
||||||
|
|
||||||
} catch (MqttException e) {
|
|
||||||
Log.error("Connection to the ESB was failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
mqttreceiver mr = new mqttreceiver(client);
|
|
||||||
mr.addMessageReceivedListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
String temp = e.getActionCommand();
|
|
||||||
|
|
||||||
String[] split = temp.split(",");
|
|
||||||
getDatabasedata("SELECT pickupdates.pickupdate FROM pickupdates WHERE pickupdates.citywastezoneid=(SELECT cities.zone FROM cities WHERE cities.name='" + split[1] + "' AND cities.wastetype='" + split[2] + "' AND cities.zone=" + split[3] + ")", split[2], Integer.parseInt(split[0]));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
mr.getmessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getDatabasedata(String message, String wastetyp, int clientidentify) {
|
|
||||||
|
|
||||||
Log.debug(message);
|
|
||||||
JDCB Database = null;
|
|
||||||
try {
|
|
||||||
Database = JDCB.getInstance();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.error("No Connection to the databank");
|
|
||||||
}
|
|
||||||
//new JDCB("placeuser", "eaL956R6yFItQVBl", "wasteinformation");
|
|
||||||
ResultSet result = Database.executeQuery(message);
|
|
||||||
try {
|
|
||||||
if (!result.isBeforeFirst()) {
|
|
||||||
int abholtag = 0;
|
|
||||||
transmitmessageAbfallart(clientidentify + "," + wastetyp + "," + abholtag);
|
|
||||||
} else {
|
|
||||||
while (result.next()) {
|
|
||||||
String temptime = String.valueOf(result.getString("pickupdate"));
|
|
||||||
|
|
||||||
GregorianCalendar now = new GregorianCalendar();
|
|
||||||
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
|
|
||||||
String date = df.format(now.getTime());
|
|
||||||
String[] parts = temptime.split("-");
|
|
||||||
String tempyear = parts[0];
|
|
||||||
String[] yearsplit = tempyear.split("0");
|
|
||||||
String tempyearnew = yearsplit[1];
|
|
||||||
String newDate = parts[2] + "." + parts[1] + ".20" + tempyearnew;
|
|
||||||
String[] partstwo = date.split(" ");
|
|
||||||
String Datetomorrow = nexDayDate();
|
|
||||||
|
|
||||||
|
|
||||||
int abholtag;
|
|
||||||
if (partstwo[0].contains(newDate) || partstwo[0].contains(Datetomorrow)) {
|
|
||||||
abholtag = 1;
|
|
||||||
transmitmessageAbfallart(clientidentify + "," + wastetyp + "," + abholtag);
|
|
||||||
} else {
|
|
||||||
abholtag = 0;
|
|
||||||
transmitmessageAbfallart(clientidentify + "," + wastetyp + "," + abholtag);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
Log.error("No data from database");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void transmitmessageAbfallart(String temp) {
|
|
||||||
|
|
||||||
mqtttransmitter mt = new mqtttransmitter(client);
|
|
||||||
Log.debug(temp);
|
|
||||||
mt.sendmessage(temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String nexDayDate() {
|
|
||||||
|
|
||||||
final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
|
||||||
Date currentDate = new Date();
|
|
||||||
|
|
||||||
Calendar c = Calendar.getInstance();
|
|
||||||
c.setTime(currentDate);
|
|
||||||
c.add(Calendar.DATE, 1);
|
|
||||||
Date currentDatePlusOne = c.getTime();
|
|
||||||
|
|
||||||
String temp = dateFormat.format(currentDatePlusOne);
|
|
||||||
String split[] = temp.split("/");
|
|
||||||
String newDate = split[2] + "." + split[1] + "." + split[0];
|
|
||||||
return newDate;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
package com.wasteinformationserver.mqtt;
|
|
||||||
|
|
||||||
import com.wasteinformationserver.basicutils.Log;
|
|
||||||
import org.eclipse.paho.client.mqttv3.*;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class mqttreceiver {
|
|
||||||
|
|
||||||
private MqttClient client;
|
|
||||||
public ArrayList<ActionListener> mylisteners = new ArrayList<>();
|
|
||||||
public String message;
|
|
||||||
|
|
||||||
public mqttreceiver(MqttClient mqtt) {
|
|
||||||
this.client = mqtt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getmessage() {
|
|
||||||
|
|
||||||
try {
|
|
||||||
client.setCallback(new MqttCallback() {
|
|
||||||
@Override
|
|
||||||
public void connectionLost(Throwable throwable) {
|
|
||||||
Log.error("connection lost");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
|
||||||
message = new String(mqttMessage.getPayload());
|
|
||||||
notifylisteners(message);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
client.subscribe("TopicIn");
|
|
||||||
Log.debug("subscribed topic");
|
|
||||||
} catch (MqttException e) {
|
|
||||||
Log.error("Connection to the ESB was failed");
|
|
||||||
}
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void notifylisteners(String message) {
|
|
||||||
for (ActionListener ac : mylisteners) {
|
|
||||||
ac.actionPerformed(new ActionEvent(this, 0, message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addMessageReceivedListener(ActionListener l) {
|
|
||||||
mylisteners.add(l);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
|||||||
package com.wasteinformationserver.mqtt;
|
|
||||||
|
|
||||||
import com.wasteinformationserver.basicutils.Log;
|
|
||||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
|
||||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
|
||||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
|
||||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
|
||||||
|
|
||||||
|
|
||||||
public class mqtttransmitter {
|
|
||||||
MqttClient client;
|
|
||||||
|
|
||||||
public mqtttransmitter(MqttClient client) {
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendmessage(String temp) {
|
|
||||||
String topic = "TopicOut";
|
|
||||||
String content = temp;
|
|
||||||
int qos = 2;
|
|
||||||
MemoryPersistence persistence = new MemoryPersistence();
|
|
||||||
|
|
||||||
try {
|
|
||||||
Log.debug("Connected");
|
|
||||||
Log.debug("Publishing message: " + content);
|
|
||||||
MqttMessage message = new MqttMessage(content.getBytes());
|
|
||||||
message.setQos(qos);
|
|
||||||
client.publish(topic, message);
|
|
||||||
Log.debug("Message published");
|
|
||||||
|
|
||||||
|
|
||||||
} catch (MqttException me) {
|
|
||||||
Log.debug("reason " + me.getReasonCode());
|
|
||||||
Log.debug("msg " + me.getMessage());
|
|
||||||
Log.debug("loc " + me.getLocalizedMessage());
|
|
||||||
Log.debug("cause " + me.getCause());
|
|
||||||
Log.debug("excep " + me);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -53,7 +53,7 @@ public class MainPage implements HttpHandler {
|
|||||||
Log.warning("wrong page sending 404");
|
Log.warning("wrong page sending 404");
|
||||||
sendPage("/404Error.html", t);
|
sendPage("/404Error.html", t);
|
||||||
} else if (fs == null) {
|
} else if (fs == null) {
|
||||||
Log.warning("requested resource doesnt exist");
|
Log.warning("requested resource doesnt exist --> "+path);
|
||||||
} else {
|
} else {
|
||||||
// Object exists and is a file: accept with response code 200.
|
// Object exists and is a file: accept with response code 200.
|
||||||
String mime = "text/html";
|
String mime = "text/html";
|
||||||
|
@ -2,27 +2,21 @@ package com.wasteinformationserver.website;
|
|||||||
|
|
||||||
import com.sun.net.httpserver.HttpServer;
|
import com.sun.net.httpserver.HttpServer;
|
||||||
import com.wasteinformationserver.basicutils.Log;
|
import com.wasteinformationserver.basicutils.Log;
|
||||||
import com.wasteinformationserver.website.datarequests.AdminRequests;
|
import com.wasteinformationserver.website.datarequests.*;
|
||||||
import com.wasteinformationserver.website.datarequests.DataRequest;
|
|
||||||
import com.wasteinformationserver.website.datarequests.NewDateRequest;
|
|
||||||
import com.wasteinformationserver.website.datarequests.RegisterRequest;
|
|
||||||
import com.wasteinformationserver.website.datarequests.login.CheckLoginState;
|
import com.wasteinformationserver.website.datarequests.login.CheckLoginState;
|
||||||
import com.wasteinformationserver.website.datarequests.login.LoginRequest;
|
import com.wasteinformationserver.website.datarequests.login.LoginRequest;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.BindException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
|
|
||||||
public class Webserver {
|
public class Webserver {
|
||||||
public void startserver() {
|
public void startserver() {
|
||||||
Log.info("starting Webserver");
|
Log.info("starting Webserver");
|
||||||
HttpServer server = null;
|
|
||||||
try {
|
|
||||||
server = HttpServer.create(new InetSocketAddress(8000), 0);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
|
||||||
|
|
||||||
server.createContext("/", new MainPage());
|
server.createContext("/", new MainPage());
|
||||||
|
|
||||||
@ -32,68 +26,15 @@ public class Webserver {
|
|||||||
server.createContext("/senddata/wastedata", new DataRequest());
|
server.createContext("/senddata/wastedata", new DataRequest());
|
||||||
server.createContext("/senddata/admindata", new AdminRequests());
|
server.createContext("/senddata/admindata", new AdminRequests());
|
||||||
server.createContext("/senddata/newdate", new NewDateRequest());
|
server.createContext("/senddata/newdate", new NewDateRequest());
|
||||||
|
server.createContext("/senddata/Devicedata", new DeviceRequest());
|
||||||
|
|
||||||
server.setExecutor(null); // creates a default executor
|
server.setExecutor(null); // creates a default executor
|
||||||
server.start();
|
server.start();
|
||||||
Log.info("Server available at http://127.0.0.1:8000 now");
|
Log.info("Server available at http://127.0.0.1:8000 now");
|
||||||
|
} catch (BindException e) {
|
||||||
/*
|
Log.criticalerror("The Port 8000 is already in use!");
|
||||||
|
|
||||||
try {
|
|
||||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
|
||||||
|
|
||||||
// initialise the HTTPS server
|
|
||||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
|
||||||
|
|
||||||
// initialise the keystore
|
|
||||||
char[] password = "password".toCharArray();
|
|
||||||
KeyStore ks = KeyStore.getInstance("JKS");
|
|
||||||
FileInputStream fis = new FileInputStream("testkey.jks");
|
|
||||||
ks.load(fis, password);
|
|
||||||
|
|
||||||
// setup the key manager factory
|
|
||||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
|
|
||||||
kmf.init(ks, password);
|
|
||||||
|
|
||||||
// setup the trust manager factory
|
|
||||||
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
|
|
||||||
tmf.init(ks);
|
|
||||||
|
|
||||||
// setup the HTTPS context and parameters
|
|
||||||
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
|
|
||||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
|
|
||||||
public void configure(HttpsParameters params) {
|
|
||||||
try {
|
|
||||||
// initialise the SSL context
|
|
||||||
SSLContext context = getSSLContext();
|
|
||||||
SSLEngine engine = context.createSSLEngine();
|
|
||||||
params.setNeedClientAuth(false);
|
|
||||||
params.setCipherSuites(engine.getEnabledCipherSuites());
|
|
||||||
params.setProtocols(engine.getEnabledProtocols());
|
|
||||||
|
|
||||||
// Set the SSL parameters
|
|
||||||
SSLParameters sslParameters = context.getSupportedSSLParameters();
|
|
||||||
params.setSSLParameters(sslParameters);
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println("Failed to create HTTPS port");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (CertificateException e) {
|
}
|
||||||
e.printStackTrace();
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (UnrecoverableKeyException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (KeyStoreException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (KeyManagementException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.wasteinformationserver.website.datarequests;
|
package com.wasteinformationserver.website.datarequests;
|
||||||
|
|
||||||
|
import com.wasteinformationserver.basicutils.Log;
|
||||||
import com.wasteinformationserver.website.basicrequest.PostRequest;
|
import com.wasteinformationserver.website.basicrequest.PostRequest;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -27,7 +28,7 @@ public class AdminRequests extends PostRequest {
|
|||||||
|
|
||||||
/* is it a jar file? */
|
/* is it a jar file? */
|
||||||
if (!currentJar.getName().endsWith(".jar"))
|
if (!currentJar.getName().endsWith(".jar"))
|
||||||
System.out.println("not jar");
|
Log.warning("not jar --> cant restart");
|
||||||
|
|
||||||
/* Build command: java -jar application.jar */
|
/* Build command: java -jar application.jar */
|
||||||
final ArrayList<String> command = new ArrayList<String>();
|
final ArrayList<String> command = new ArrayList<String>();
|
||||||
|
@ -17,6 +17,8 @@ public class DataRequest 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();
|
||||||
|
ResultSet set = null;
|
||||||
|
int status = -1;
|
||||||
|
|
||||||
JDCB jdcb;
|
JDCB jdcb;
|
||||||
try {
|
try {
|
||||||
@ -33,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"));
|
||||||
ResultSet set = jdcb.executeQuery("select * from `cities` where `name`='" + params.get("cityname") + "' AND `wastetype`='" + params.get("wastetype") + "' AND `zone`='" + params.get("wastezone") + "'");
|
set = jdcb.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) {
|
||||||
@ -45,14 +47,12 @@ public class DataRequest extends PostRequest {
|
|||||||
}
|
}
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
//doesnt exist
|
//doesnt exist
|
||||||
System.out.println("doesnt exist");
|
|
||||||
int status = 0;
|
|
||||||
try {
|
try {
|
||||||
status = jdcb.executeUpdate("INSERT INTO `cities`(`userid`, `name`, `wastetype`, `zone`) VALUES ('0','" + params.get("cityname") + "','" + params.get("wastetype") + "','" + params.get("wastezone") + "');");
|
status = jdcb.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();
|
||||||
}
|
}
|
||||||
System.out.println(status);
|
|
||||||
if (status == 1) {
|
if (status == 1) {
|
||||||
sb.append("\"status\" : \"inserted\"");
|
sb.append("\"status\" : \"inserted\"");
|
||||||
} else {
|
} else {
|
||||||
@ -64,7 +64,6 @@ public class DataRequest extends PostRequest {
|
|||||||
sb.append("\"status\" : \"exists\"");
|
sb.append("\"status\" : \"exists\"");
|
||||||
} else {
|
} else {
|
||||||
//already exists
|
//already exists
|
||||||
System.out.println("already exists");
|
|
||||||
sb.append("\"status\" : \"exists\"");
|
sb.append("\"status\" : \"exists\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,20 +71,18 @@ public class DataRequest extends PostRequest {
|
|||||||
sb.append("}");
|
sb.append("}");
|
||||||
break;
|
break;
|
||||||
case "getAllCities":
|
case "getAllCities":
|
||||||
ResultSet sett = jdcb.executeQuery("select * from cities");
|
set = jdcb.executeQuery("select * from cities");
|
||||||
Log.debug(sett.toString());
|
Log.debug(set.toString());
|
||||||
sb.append("{\"data\":[");
|
sb.append("{\"data\":[");
|
||||||
try {
|
try {
|
||||||
while (sett.next()) {
|
while (set.next()) {
|
||||||
sb.append("{\"cityname\":\"" + sett.getString("name") + "\"");
|
sb.append("{\"cityname\":\"" + set.getString("name") + "\"");
|
||||||
sb.append(",\"wastetype\":\"" + sett.getString("wastetype") + "\"");
|
sb.append(",\"wastetype\":\"" + set.getString("wastetype") + "\"");
|
||||||
sb.append(",\"id\":\"" + sett.getString("id") + "\"");
|
sb.append(",\"id\":\"" + set.getString("id") + "\"");
|
||||||
sb.append(",\"zone\":\"" + sett.getString("zone") + "\"}");
|
sb.append(",\"zone\":\"" + set.getString("zone") + "\"}");
|
||||||
if (!sett.isLast()) {
|
if (!set.isLast()) {
|
||||||
sb.append(",");
|
sb.append(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
// System.out.println(sett.getString("name"));
|
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -97,8 +94,6 @@ public class DataRequest extends PostRequest {
|
|||||||
case "deletecity":
|
case "deletecity":
|
||||||
//DELETE FROM `cities` WHERE `id`=0
|
//DELETE FROM `cities` WHERE `id`=0
|
||||||
sb.append("{");
|
sb.append("{");
|
||||||
Log.debug(params.get("id"));
|
|
||||||
int status = 0;
|
|
||||||
try {
|
try {
|
||||||
status = jdcb.executeUpdate("DELETE FROM `cities` WHERE `id`='" + params.get("id") + "'");
|
status = jdcb.executeUpdate("DELETE FROM `cities` WHERE `id`='" + params.get("id") + "'");
|
||||||
if (status == 1) {
|
if (status == 1) {
|
||||||
@ -121,49 +116,41 @@ public class DataRequest extends PostRequest {
|
|||||||
sb.append("}");
|
sb.append("}");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "getcollectionnumber": //todo maybe combine all three to one
|
case "getAllDates":
|
||||||
sb.append("{");
|
set = jdcb.executeQuery("SELECT pickupdates.id,pickupdates.pickupdate,cities.userid,cities.name,cities.wastetype,cities.zone " +
|
||||||
|
"FROM `pickupdates` INNER JOIN `cities` ON pickupdates.citywastezoneid = cities.id");
|
||||||
|
sb.append("{\"data\":[");
|
||||||
try {
|
try {
|
||||||
ResultSet settt = jdcb.executeQuery("select * from pickupdates");
|
while (set.next()) {
|
||||||
settt.last();
|
sb.append("{\"date\":\"" + set.getString("pickupdate") + "\"");
|
||||||
sb.append("\"collectionnumber\":\"" + settt.getRow() + "\"");
|
sb.append(",\"cityname\":\"" + set.getString("name") + "\"");
|
||||||
} catch (SQLException e) {
|
sb.append(",\"wastetype\":\"" + set.getString("wastetype") + "\"");
|
||||||
Log.error("sql exception: " + e.getMessage());
|
sb.append(",\"id\":\"" + set.getString("id") + "\"");
|
||||||
sb.append("\"status\" : \"error\"");
|
sb.append(",\"zone\":\"" + set.getString("zone") + "\"}");
|
||||||
|
if (!set.isLast()) {
|
||||||
|
sb.append(",");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
sb.append("]");
|
||||||
sb.append(",\"query\":\"ok\"");
|
sb.append(",\"query\":\"ok\"");
|
||||||
sb.append("}");
|
sb.append("}");
|
||||||
break;
|
break;
|
||||||
case "getcollectioninfuture":
|
case "deletedate":
|
||||||
sb.append("{");
|
sb.append("{");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
status = jdcb.executeUpdate("DELETE FROM `pickupdates` WHERE `id`='" + params.get("id") + "'");
|
||||||
Date date = new Date();
|
if (status == 1) {
|
||||||
String time = sdf.format(date);
|
//success
|
||||||
ResultSet settt = jdcb.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '"+time+"' AND '2222-12-27'");
|
sb.append("\"status\" : \"success\"");
|
||||||
settt.last();
|
} else {
|
||||||
sb.append("\"collectionnumber\":\"" + settt.getRow() + "\"");
|
|
||||||
} catch (SQLException e) {
|
|
||||||
Log.error("sql exception: " + e.getMessage());
|
|
||||||
sb.append("\"status\" : \"error\"");
|
sb.append("\"status\" : \"error\"");
|
||||||
}
|
}
|
||||||
|
} catch (SQLIntegrityConstraintViolationException e) {
|
||||||
sb.append(",\"query\":\"ok\"");
|
Log.warning("dependencies of deletion exist");
|
||||||
sb.append("}");
|
sb.append("\"status\" : \"dependenciesnotdeleted\"");
|
||||||
break;
|
|
||||||
case "getfinishedcollections":
|
|
||||||
sb.append("{");
|
|
||||||
|
|
||||||
try {
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
||||||
Date date = new Date();
|
|
||||||
String time = sdf.format(date);
|
|
||||||
ResultSet settt = jdcb.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '0000-12-27' AND '"+time+"'");
|
|
||||||
settt.last();
|
|
||||||
sb.append("\"collectionnumber\":\"" + settt.getRow() + "\"");
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Log.error("sql exception: " + e.getMessage());
|
Log.error("sql exception: " + e.getMessage());
|
||||||
sb.append("\"status\" : \"error\"");
|
sb.append("\"status\" : \"error\"");
|
||||||
@ -175,10 +162,45 @@ public class DataRequest extends PostRequest {
|
|||||||
case "getversionandbuildtime":
|
case "getversionandbuildtime":
|
||||||
sb.append("{");
|
sb.append("{");
|
||||||
|
|
||||||
sb.append("\"version\" : \""+ Info.version+"\"");
|
sb.append("\"version\" : \""+ Info.getVersion()+"\"");
|
||||||
sb.append(",\"buildtime\" : \""+ Info.builddate+"\"");
|
sb.append(",\"buildtime\" : \""+ Info.getBuilddate()+"\"");
|
||||||
|
|
||||||
|
|
||||||
|
sb.append(",\"query\":\"ok\"");
|
||||||
|
sb.append("}");
|
||||||
|
break;
|
||||||
|
case "getStartHeaderData":
|
||||||
|
sb.append("{");
|
||||||
|
|
||||||
|
try {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
Date date = new Date();
|
||||||
|
String time = sdf.format(date);
|
||||||
|
set = jdcb.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '0000-12-27' AND '"+time+"'");
|
||||||
|
set.last();
|
||||||
|
sb.append("\"finshedcollections\":\"" + set.getRow() + "\"");
|
||||||
|
|
||||||
|
sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
date = new Date();
|
||||||
|
date = new Date(date.getTime()+1 * 24 * 60 * 60 * 1000);
|
||||||
|
|
||||||
|
time = sdf.format(date);
|
||||||
|
set = jdcb.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '"+time+"' AND '2222-12-27'");
|
||||||
|
set.last();
|
||||||
|
sb.append(",\"futurecollections\":\"" + set.getRow() + "\"");
|
||||||
|
|
||||||
|
set = jdcb.executeQuery("select * from pickupdates");
|
||||||
|
set.last();
|
||||||
|
sb.append(",\"collectionnumber\":\"" + set.getRow() + "\"");
|
||||||
|
|
||||||
|
set = jdcb.executeQuery("select * from `cities`");
|
||||||
|
set.last();
|
||||||
|
sb.append(",\"citynumber\":\"" + set.getRow() + "\"");
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Log.error("sql exception: " + e.getMessage());
|
||||||
|
sb.append("\"status\" : \"error\"");
|
||||||
|
}
|
||||||
|
|
||||||
sb.append(",\"query\":\"ok\"");
|
sb.append(",\"query\":\"ok\"");
|
||||||
sb.append("}");
|
sb.append("}");
|
||||||
break;
|
break;
|
||||||
|
@ -0,0 +1,139 @@
|
|||||||
|
package com.wasteinformationserver.website.datarequests;
|
||||||
|
|
||||||
|
import com.wasteinformationserver.basicutils.Log;
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
switch (params.get("action")) {
|
||||||
|
case "getdevices":
|
||||||
|
ResultSet set = jdcb.executeQuery("SELECT * from devices");
|
||||||
|
sb.append("{\"data\":[");
|
||||||
|
try {
|
||||||
|
while (set.next()) {
|
||||||
|
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("]}");
|
||||||
|
} 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("{");
|
||||||
|
try {
|
||||||
|
int prev = 42;
|
||||||
|
while (set.next()) {
|
||||||
|
if (prev == set.getInt("zone")) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
sb.append("\"" + set.getInt("zone") + "\":\"" + set.getInt("zone") + "\"");
|
||||||
|
if (!set.isLast()) {
|
||||||
|
sb.append(",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prev = set.getInt("zone");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
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("{");
|
||||||
|
try {
|
||||||
|
String prev = "42";
|
||||||
|
while (set.next()) {
|
||||||
|
if (prev == set.getString("wastetype")) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
sb.append("\"" + set.getString("wastetype") + "\":\"" + set.getString("wastetype") + "\"");
|
||||||
|
if (!set.isLast()) {
|
||||||
|
sb.append(",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prev = set.getString("wastetype");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
sb.append("}");
|
||||||
|
break;
|
||||||
|
case "savetodb":
|
||||||
|
set = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zonename") + "' AND `wastetype`='" + params.get("wastetype") + "'");
|
||||||
|
try {
|
||||||
|
set.last();
|
||||||
|
if (set.getRow() != 1) {
|
||||||
|
//error
|
||||||
|
} else {
|
||||||
|
int id = set.getInt("id");
|
||||||
|
jdcb.executeUpdate("UPDATE devices SET `CityID`='" + id + "',`DeviceName`='" + params.get("devicename") + "',`DeviceLocation`='" + params.get("devicelocation") + "' WHERE `DeviceID`='" + params.get("deviceid") + "'");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//'action=savetodb&cityname=' + cityname + '&zonename=' + zone+'&wastetype='+wastetype+'&devicename='+devicename+'&devicelocation='+devicelocation
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,7 @@ public class NewDateRequest extends PostRequest {
|
|||||||
public String request(HashMap<String, String> params) {
|
public String request(HashMap<String, String> params) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
JDCB jdcb;
|
JDCB jdcb;
|
||||||
|
ResultSet set;
|
||||||
try {
|
try {
|
||||||
jdcb = JDCB.getInstance();
|
jdcb = JDCB.getInstance();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -22,21 +23,21 @@ public class NewDateRequest extends PostRequest {
|
|||||||
}
|
}
|
||||||
switch (params.get("action")) {
|
switch (params.get("action")) {
|
||||||
case "getCitynames":
|
case "getCitynames":
|
||||||
ResultSet sett = jdcb.executeQuery("select * from cities");
|
set = jdcb.executeQuery("select * from cities");
|
||||||
Log.debug(sett.toString());
|
Log.debug(set.toString());
|
||||||
sb.append("{\"data\":[");
|
sb.append("{\"data\":[");
|
||||||
try {
|
try {
|
||||||
String prev = "";
|
String prev = "";
|
||||||
while (sett.next()) {
|
while (set.next()) {
|
||||||
if (prev.equals(sett.getString("name"))) {
|
if (prev.equals(set.getString("name"))) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!sett.isFirst()) {
|
if (!set.isFirst()) {
|
||||||
sb.append(",");
|
sb.append(",");
|
||||||
}
|
}
|
||||||
sb.append("{\"cityname\":\"" + sett.getString("name") + "\"}");
|
sb.append("{\"cityname\":\"" + set.getString("name") + "\"}");
|
||||||
}
|
}
|
||||||
prev = sett.getString("name");
|
prev = set.getString("name");
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -47,7 +48,7 @@ public class NewDateRequest extends PostRequest {
|
|||||||
Log.debug(sb.toString());
|
Log.debug(sb.toString());
|
||||||
break;
|
break;
|
||||||
case "getzones":
|
case "getzones":
|
||||||
ResultSet set = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' ORDER BY zone ASC");
|
set = jdcb.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 {
|
||||||
@ -70,16 +71,40 @@ public class NewDateRequest extends PostRequest {
|
|||||||
sb.append(",\"query\":\"ok\"");
|
sb.append(",\"query\":\"ok\"");
|
||||||
sb.append("}");
|
sb.append("}");
|
||||||
break;
|
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;
|
||||||
case "newdate":
|
case "newdate":
|
||||||
sb.append("{");
|
sb.append("{");
|
||||||
Log.debug(params);
|
Log.debug(params);
|
||||||
ResultSet seti = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zone") + "' AND `wastetype`='" + params.get("wastetype") + "'");
|
set = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zone") + "' AND `wastetype`='" + params.get("wastetype") + "'");
|
||||||
try {
|
try {
|
||||||
seti.last();
|
set.last();
|
||||||
if (seti.getRow() == 1) {
|
if (set.getRow() == 1) {
|
||||||
Log.debug(seti.getInt("id"));
|
Log.debug(set.getInt("id"));
|
||||||
|
|
||||||
int status = jdcb.executeUpdate("INSERT INTO `pickupdates`(`citywastezoneid`, `pickupdate`) VALUES ('" + seti.getInt("id") + "','" + params.get("date") + "')");
|
int status = jdcb.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 {
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<aside class="main-sidebar sidebar-dark-primary elevation-4">
|
<aside class="main-sidebar sidebar-dark-primary elevation-4">
|
||||||
<!-- Brand Logo -->
|
<!-- Brand Logo -->
|
||||||
<a href="dashboard.html" class="brand-link">
|
<a href="dashboard.html" class="brand-link">
|
||||||
<img src="lib/AdminLTE/dist/img/AdminLTELogo.png"
|
<img src="/favicon.png"
|
||||||
alt="AdminLTE Logo"
|
alt="AdminLTE Logo"
|
||||||
class="brand-image img-circle elevation-3"
|
class="brand-image img-circle elevation-3"
|
||||||
style="opacity: .8">
|
style="opacity: .8">
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
<aside class="main-sidebar sidebar-dark-primary elevation-4">
|
<aside class="main-sidebar sidebar-dark-primary elevation-4">
|
||||||
<!-- Brand Logo -->
|
<!-- Brand Logo -->
|
||||||
<a href="dashboard.html" class="brand-link">
|
<a href="dashboard.html" class="brand-link">
|
||||||
<img src="lib/AdminLTE/dist/img/AdminLTELogo.png" alt="AdminLTE Logo"
|
<img src="/favicon.png" alt="AdminLTE Logo"
|
||||||
class="brand-image img-circle elevation-3"
|
class="brand-image img-circle elevation-3"
|
||||||
style="opacity: .8">
|
style="opacity: .8">
|
||||||
<span class="brand-text font-weight-light">Waste Control</span>
|
<span class="brand-text font-weight-light">Waste Control</span>
|
||||||
@ -271,5 +271,7 @@
|
|||||||
|
|
||||||
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
|
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
|
||||||
|
|
||||||
|
<script src="js/userManager.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -37,6 +37,8 @@
|
|||||||
<link rel="stylesheet" type="text/css" href="css/dashboard.css">
|
<link rel="stylesheet" type="text/css" href="css/dashboard.css">
|
||||||
<link rel="stylesheet" type="text/css" href="css/general.css">
|
<link rel="stylesheet" type="text/css" href="css/general.css">
|
||||||
|
|
||||||
|
<link rel="icon" type="image/png" href="/favicon.png">
|
||||||
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body class="hold-transition sidebar-mini layout-fixed">
|
<body class="hold-transition sidebar-mini layout-fixed">
|
||||||
@ -45,7 +47,7 @@
|
|||||||
<aside class="main-sidebar sidebar-dark-primary elevation-4">
|
<aside class="main-sidebar sidebar-dark-primary elevation-4">
|
||||||
<!-- Brand Logo -->
|
<!-- Brand Logo -->
|
||||||
<a href="dashboard.html" class="brand-link">
|
<a href="dashboard.html" class="brand-link">
|
||||||
<img src="lib/AdminLTE/dist/img/AdminLTELogo.png" alt="AdminLTE Logo"
|
<img src="/favicon.png" alt="AdminLTE Logo"
|
||||||
class="brand-image img-circle elevation-3"
|
class="brand-image img-circle elevation-3"
|
||||||
style="opacity: .8">
|
style="opacity: .8">
|
||||||
<span class="brand-text font-weight-light">Waste Control</span>
|
<span class="brand-text font-weight-light">Waste Control</span>
|
||||||
@ -96,6 +98,15 @@
|
|||||||
</p>
|
</p>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li id="devicepanel" class="nav-item">
|
||||||
|
<a href="device.html" class="nav-link">
|
||||||
|
<i class="nav-icon fas fa-plus-circle"></i>
|
||||||
|
<p>
|
||||||
|
Devices
|
||||||
|
</p>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<!-- /.sidebar-menu -->
|
<!-- /.sidebar-menu -->
|
||||||
@ -145,14 +156,14 @@
|
|||||||
<!-- ./col -->
|
<!-- ./col -->
|
||||||
<div class="col-lg-3 col-6">
|
<div class="col-lg-3 col-6">
|
||||||
<!-- small box -->
|
<!-- small box -->
|
||||||
<div class="small-box bg-success">
|
<div class="small-box bg-gray">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<h3>53<sup style="font-size: 20px">%</sup></h3>
|
<h3 id="total-city-number-label">42</h3>
|
||||||
|
|
||||||
<p>Verbundene Clients</p>
|
<p>total collect zones</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="icon">
|
<div class="icon">
|
||||||
<i class="ion ion-stats-bars"></i>
|
<i class="ion ion-android-globe" style="color: lightgrey"></i>
|
||||||
</div>
|
</div>
|
||||||
<a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
|
<a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
|
||||||
</div>
|
</div>
|
||||||
@ -167,7 +178,7 @@
|
|||||||
<p>Planned Collections</p>
|
<p>Planned Collections</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="icon">
|
<div class="icon">
|
||||||
<i class="ion ion-person-add"></i>
|
<i class="ion ion-calendar"></i>
|
||||||
</div>
|
</div>
|
||||||
<a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
|
<a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
|
||||||
</div>
|
</div>
|
||||||
@ -175,14 +186,14 @@
|
|||||||
<!-- ./col -->
|
<!-- ./col -->
|
||||||
<div class="col-lg-3 col-6">
|
<div class="col-lg-3 col-6">
|
||||||
<!-- small box -->
|
<!-- small box -->
|
||||||
<div class="small-box bg-danger">
|
<div class="small-box bg-success">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<h3 id="finished-collection-label">65</h3>
|
<h3 id="finished-collection-label">65</h3>
|
||||||
|
|
||||||
<p>Finished Collections</p>
|
<p>Finished Collections</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="icon">
|
<div class="icon">
|
||||||
<i class="ion ion-pie-graph"></i>
|
<i class="ion ion-android-checkmark-circle"></i>
|
||||||
</div>
|
</div>
|
||||||
<a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
|
<a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
|
||||||
</div>
|
</div>
|
||||||
@ -311,11 +322,7 @@
|
|||||||
data-toggle="dropdown">
|
data-toggle="dropdown">
|
||||||
Select waste type
|
Select waste type
|
||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu">
|
<div id="dropdown-type-drops" class="dropdown-menu">
|
||||||
<a class="dropdown-item-wastetype dropdown-item" href="#">Plastic</a>
|
|
||||||
<a class="dropdown-item-wastetype dropdown-item" href="#">Metal</a>
|
|
||||||
<a class="dropdown-item-wastetype dropdown-item" href="#">Residual waste</a>
|
|
||||||
<a class="dropdown-item-wastetype dropdown-item" href="#">Biowaste</a>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<input id="input-wastetime" style="width: 50px;" class="form-control" id="date"
|
<input id="input-wastetime" style="width: 50px;" class="form-control" id="date"
|
||||||
@ -433,12 +440,16 @@
|
|||||||
<script type="text/javascript"
|
<script type="text/javascript"
|
||||||
src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
|
src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript" src="js/dashboard.js"></script>
|
|
||||||
<!-- DataTables -->
|
<!-- DataTables -->
|
||||||
<script src="lib/AdminLTE/plugins/datatables/jquery.dataTables.js"></script>
|
<script src="lib/AdminLTE/plugins/datatables/jquery.dataTables.js"></script>
|
||||||
<script src="lib/AdminLTE/plugins/datatables-bs4/js/dataTables.bootstrap4.js"></script>
|
<script src="lib/AdminLTE/plugins/datatables-bs4/js/dataTables.bootstrap4.js"></script>
|
||||||
|
|
||||||
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
|
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
|
||||||
|
|
||||||
|
<!-- OWN -->
|
||||||
|
|
||||||
|
<script type="text/javascript" src="js/dashboard.js"></script>
|
||||||
|
<script src="js/userManager.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
294
src/resources/wwwroot/device.html
Normal file
294
src/resources/wwwroot/device.html
Normal file
@ -0,0 +1,294 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<title>WasteInformation Server</title>
|
||||||
|
<!-- Tell the browser to be responsive to screen width -->
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<!-- Font Awesome -->
|
||||||
|
<link rel="stylesheet" href="lib/AdminLTE/plugins/fontawesome-free/css/all.min.css">
|
||||||
|
<!-- Ionicons -->
|
||||||
|
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
|
||||||
|
<!-- DataTables -->
|
||||||
|
<link rel="stylesheet" href="lib/AdminLTE/plugins/datatables-bs4/css/dataTables.bootstrap4.css">
|
||||||
|
<!-- Tempusdominus Bbootstrap 4 -->
|
||||||
|
<link rel="stylesheet" href="lib/AdminLTE/plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
|
||||||
|
<!-- iCheck -->
|
||||||
|
<link rel="stylesheet" href="lib/AdminLTE/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
|
||||||
|
<!-- JQVMap -->
|
||||||
|
<link rel="stylesheet" href="lib/AdminLTE/plugins/jqvmap/jqvmap.min.css">
|
||||||
|
<!-- Theme style -->
|
||||||
|
<link rel="stylesheet" href="lib/AdminLTE/dist/css/adminlte.min.css">
|
||||||
|
<!-- overlayScrollbars -->
|
||||||
|
<link rel="stylesheet" href="lib/AdminLTE/plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
|
||||||
|
<!-- Daterange picker -->
|
||||||
|
<link rel="stylesheet" href="lib/AdminLTE/plugins/daterangepicker/daterangepicker.css">
|
||||||
|
<!-- summernote -->
|
||||||
|
<link rel="stylesheet" href="lib/AdminLTE/plugins/summernote/summernote-bs4.css">
|
||||||
|
<!-- Google Font: Source Sans Pro -->
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
|
||||||
|
|
||||||
|
<!-- Bootstrap Date-Picker Plugin -->
|
||||||
|
|
||||||
|
<link rel="stylesheet"
|
||||||
|
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
|
||||||
|
|
||||||
|
<!-- <link rel="stylesheet" type="text/css" href="css/user.css">-->
|
||||||
|
<link rel="stylesheet" type="text/css" href="css/general.css">
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body class="hold-transition sidebar-mini layout-fixed">
|
||||||
|
<div class="wrapper">
|
||||||
|
<!-- Main Sidebar Container -->
|
||||||
|
<aside class="main-sidebar sidebar-dark-primary elevation-4">
|
||||||
|
<!-- Brand Logo -->
|
||||||
|
<a href="dashboard.html" class="brand-link">
|
||||||
|
<img src="/favicon.png" alt="AdminLTE Logo"
|
||||||
|
class="brand-image img-circle elevation-3"
|
||||||
|
style="opacity: .8">
|
||||||
|
<span class="brand-text font-weight-light">Waste Control</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<!-- Sidebar -->
|
||||||
|
<div class="sidebar">
|
||||||
|
<!-- Sidebar user panel (optional) -->
|
||||||
|
<div class="user-panel mt-3 pb-3 mb-3 d-flex">
|
||||||
|
<div class="image">
|
||||||
|
<!-- <img src="lib/AdminLTE/dist/img/user2-160x160.jpg" class="img-circle elevation-2" alt="User Image"> -->
|
||||||
|
<i class="nav-icon fas fa-user img-circle elevation-2" style="color:white"></i>
|
||||||
|
</div>
|
||||||
|
<!-- <i class="nav-icon fas fa-tachometer-alt"></i> -->
|
||||||
|
<div class="info">
|
||||||
|
<a href="user.html" class="d-block" id="userlabel">Username to set!</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Sidebar Menu -->
|
||||||
|
<nav class="mt-2">
|
||||||
|
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu"
|
||||||
|
data-accordion="false">
|
||||||
|
|
||||||
|
<li class="nav-item">
|
||||||
|
<a href="#todo" class="nav-link">
|
||||||
|
<i class="nav-icon fas fa-cog"></i>
|
||||||
|
<p>
|
||||||
|
Settings
|
||||||
|
</p>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="nav-item">
|
||||||
|
<a href="index.html" class="nav-link" id="logoutbtn">
|
||||||
|
<i class="nav-icon fas fa-sign-out-alt"></i>
|
||||||
|
<p>
|
||||||
|
Logout
|
||||||
|
</p>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li id="adminpanel" class="nav-item hideit">
|
||||||
|
<a href="adminpanel.html" class="nav-link">
|
||||||
|
<i class="nav-icon fas fa-plus-circle"></i>
|
||||||
|
<p>
|
||||||
|
Admin panel
|
||||||
|
</p>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li id="devicepanel" class="nav-item">
|
||||||
|
<a href="device.html" class="nav-link">
|
||||||
|
<i class="nav-icon fas fa-plus-circle"></i>
|
||||||
|
<p>
|
||||||
|
Devices
|
||||||
|
</p>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
<!-- /.sidebar-menu -->
|
||||||
|
</div>
|
||||||
|
<!-- /.sidebar -->
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<!-- Content Wrapper. Contains page content -->
|
||||||
|
<div class="content-wrapper">
|
||||||
|
<!-- Content Header (Page header) -->
|
||||||
|
<div class="content-header">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row mb-2">
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<h1 class="m-0 text-dark">Dashboard</h1>
|
||||||
|
</div><!-- /.col -->
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<ol class="breadcrumb float-sm-right">
|
||||||
|
<li class="breadcrumb-item"><a href="dashboard.html">Home</a></li>
|
||||||
|
<li class="breadcrumb-item active">Users</li>
|
||||||
|
</ol>
|
||||||
|
</div><!-- /.col -->
|
||||||
|
</div><!-- /.row -->
|
||||||
|
</div><!-- /.container-fluid -->
|
||||||
|
</div>
|
||||||
|
<!-- /.content-header -->
|
||||||
|
|
||||||
|
<!-- Main content -->
|
||||||
|
<section class="content">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<!-- Small boxes (Stat box) -->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-3 col-6">
|
||||||
|
<!-- small box -->
|
||||||
|
<div class="small-box bg-info">
|
||||||
|
<div class="inner">
|
||||||
|
<h3>150</h3>
|
||||||
|
|
||||||
|
<p>Todo</p>
|
||||||
|
</div>
|
||||||
|
<div class="icon">
|
||||||
|
<i class="ion ion-bag"></i>
|
||||||
|
</div>
|
||||||
|
<a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- ./col -->
|
||||||
|
<div class="col-lg-3 col-6">
|
||||||
|
<!-- small box -->
|
||||||
|
<div class="small-box bg-success">
|
||||||
|
<div class="inner">
|
||||||
|
<h3>42</h3>
|
||||||
|
|
||||||
|
<p>Devices</p>
|
||||||
|
</div>
|
||||||
|
<div class="icon">
|
||||||
|
<i class="ion ion-stats-bars"></i>
|
||||||
|
</div>
|
||||||
|
<a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- ./col -->
|
||||||
|
</div>
|
||||||
|
<!-- /.row -->
|
||||||
|
<!-- Main row -->
|
||||||
|
<div class="row">
|
||||||
|
<!-- Left col -->
|
||||||
|
<section class="col-lg-7 connectedSortable">
|
||||||
|
<!-- Custom tabs (Charts with tabs)-->
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h3 class="card-title">
|
||||||
|
<i class="fas fa-chart-pie mr-1"></i>
|
||||||
|
All Devices
|
||||||
|
</h3>
|
||||||
|
</div><!-- /.card-header -->
|
||||||
|
<div class="card-body">
|
||||||
|
<table id="table-devices" class="table table-bordered table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Device ID</th>
|
||||||
|
<th>Devicename</th>
|
||||||
|
<th>Devicelocation</th>
|
||||||
|
<th>Zone</th>
|
||||||
|
<th>X</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="devices-tablebody">
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th>Device ID</th>
|
||||||
|
<th>Devicename</th>
|
||||||
|
<th>Devicelocation</th>
|
||||||
|
<th>Zone</th>
|
||||||
|
<th>X</th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
</div><!-- /.card-body -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- /.Left col -->
|
||||||
|
<!-- right col (We are only adding the ID to make the widgets sortable)-->
|
||||||
|
<section class="col-lg-5 connectedSortable">
|
||||||
|
|
||||||
|
<!-- /.card -->
|
||||||
|
</section>
|
||||||
|
<!-- right col -->
|
||||||
|
</div>
|
||||||
|
<!-- /.row (main row) -->
|
||||||
|
</div><!-- /.container-fluid -->
|
||||||
|
</section>
|
||||||
|
<!-- /.content -->
|
||||||
|
</div>
|
||||||
|
<!-- /.content-wrapper -->
|
||||||
|
<footer class="main-footer">
|
||||||
|
<strong>By Gregor Dutzler & Lukas Heiligenbrunner & Emil Meindl</strong>
|
||||||
|
<div class="float-right d-none d-sm-inline-block">
|
||||||
|
<b>Version</b> 3.0.0
|
||||||
|
<b>Build</b> 2019-8-8 9:30
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<!-- Control Sidebar -->
|
||||||
|
<aside class="control-sidebar control-sidebar-dark">
|
||||||
|
<!-- Control sidebar content goes here -->
|
||||||
|
</aside>
|
||||||
|
<!-- /.control-sidebar -->
|
||||||
|
</div>
|
||||||
|
<!-- ./wrapper -->
|
||||||
|
|
||||||
|
<!-- jQuery -->
|
||||||
|
<script src="lib/AdminLTE/plugins/jquery/jquery.min.js"></script>
|
||||||
|
<!-- jQuery UI 1.11.4 -->
|
||||||
|
<script src="lib/AdminLTE/plugins/jquery-ui/jquery-ui.min.js"></script>
|
||||||
|
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
|
||||||
|
<script>
|
||||||
|
$.widget.bridge('uibutton', $.ui.button)
|
||||||
|
</script>
|
||||||
|
<!-- Bootstrap 4 -->
|
||||||
|
<script src="lib/AdminLTE/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<!-- ChartJS -->
|
||||||
|
<script src="lib/AdminLTE/plugins/chart.js/Chart.min.js"></script>
|
||||||
|
<!-- Sparkline -->
|
||||||
|
<script src="lib/AdminLTE/plugins/sparklines/sparkline.js"></script>
|
||||||
|
<!-- JQVMap -->
|
||||||
|
<script src="lib/AdminLTE/plugins/jqvmap/jquery.vmap.min.js"></script>
|
||||||
|
<script src="lib/AdminLTE/plugins/jqvmap/maps/jquery.vmap.usa.js"></script>
|
||||||
|
<!-- jQuery Knob Chart -->
|
||||||
|
<script src="lib/AdminLTE/plugins/jquery-knob/jquery.knob.min.js"></script>
|
||||||
|
<!-- daterangepicker -->
|
||||||
|
<script src="lib/AdminLTE/plugins/moment/moment.min.js"></script>
|
||||||
|
<script src="lib/AdminLTE/plugins/daterangepicker/daterangepicker.js"></script>
|
||||||
|
<!-- Tempusdominus Bootstrap 4 -->
|
||||||
|
<script src="lib/AdminLTE/plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
|
||||||
|
<!-- Summernote -->
|
||||||
|
<script src="lib/AdminLTE/plugins/summernote/summernote-bs4.min.js"></script>
|
||||||
|
<!-- overlayScrollbars -->
|
||||||
|
<script src="lib/AdminLTE/plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
|
||||||
|
<!-- AdminLTE App -->
|
||||||
|
<script src="lib/AdminLTE/dist/js/adminlte.js"></script>
|
||||||
|
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
|
||||||
|
<script src="lib/AdminLTE/dist/js/pages/dashboard.js"></script>
|
||||||
|
<!-- AdminLTE for demo purposes -->
|
||||||
|
<script src="lib/AdminLTE/dist/js/demo.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript"
|
||||||
|
src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
|
||||||
|
|
||||||
|
<!--<script type="text/javascript" src="js/user.js"></script>-->
|
||||||
|
<!-- DataTables -->
|
||||||
|
<script src="lib/AdminLTE/plugins/datatables/jquery.dataTables.js"></script>
|
||||||
|
<script src="lib/AdminLTE/plugins/datatables-bs4/js/dataTables.bootstrap4.js"></script>
|
||||||
|
|
||||||
|
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
|
||||||
|
|
||||||
|
<script src="js/userManager.js"></script>
|
||||||
|
<script src="js/device.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
@ -18,7 +18,8 @@
|
|||||||
<script src="lib/bootstrap.min.js"></script>
|
<script src="lib/bootstrap.min.js"></script>
|
||||||
|
|
||||||
<!--Fontawesome CDN-->
|
<!--Fontawesome CDN-->
|
||||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
|
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css"
|
||||||
|
integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
|
||||||
|
|
||||||
<!--Custom styles-->
|
<!--Custom styles-->
|
||||||
<link rel="stylesheet" type="text/css" href="css/index.css">
|
<link rel="stylesheet" type="text/css" href="css/index.css">
|
||||||
@ -28,6 +29,8 @@
|
|||||||
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
|
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
|
||||||
|
|
||||||
<link rel="manifest" href="/manifest.json">
|
<link rel="manifest" href="/manifest.json">
|
||||||
|
|
||||||
|
<link rel="icon" type="image/png" href="/favicon.png">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@ -1,33 +1,14 @@
|
|||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
console.log("page loaded");
|
|
||||||
$.post('/senddata/checkloginstate', 'action=getloginstate', function (data) {
|
|
||||||
console.log(data);
|
|
||||||
if (data.loggedin == true) {
|
|
||||||
$("#userlabel").html(" " + data.username);
|
|
||||||
if (data.permission > 0) {
|
|
||||||
$("#adminpanel").show();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$("#userlabel").html(" not logged in!!");
|
|
||||||
}
|
|
||||||
}, 'json');
|
|
||||||
|
|
||||||
//load total collections
|
//load total collections
|
||||||
$.post('/senddata/wastedata', 'action=getcollectionnumber', function (data) {
|
$.post('/senddata/wastedata', 'action=getStartHeaderData', function (data) {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
$("#total-connection-labels").html(data.collectionnumber);
|
$("#total-connection-labels").html(data.collectionnumber);
|
||||||
}, 'json');
|
|
||||||
|
|
||||||
//load future collections
|
$("#planed-collection-label").html(data.futurecollections);
|
||||||
$.post('/senddata/wastedata', 'action=getcollectioninfuture', function (data) {
|
|
||||||
console.log(data);
|
|
||||||
$("#planed-collection-label").html(data.collectionnumber);
|
|
||||||
}, 'json');
|
|
||||||
|
|
||||||
//load future collections
|
$("#finished-collection-label").html(data.finshedcollections);
|
||||||
$.post('/senddata/wastedata', 'action=getfinishedcollections', function (data) {
|
|
||||||
console.log(data);
|
$("#total-city-number-label").html(data.citynumber);
|
||||||
$("#finished-collection-label").html(data.collectionnumber);
|
|
||||||
}, 'json');
|
}, 'json');
|
||||||
|
|
||||||
//load version footer
|
//load version footer
|
||||||
@ -38,6 +19,7 @@ $(document).ready(function () {
|
|||||||
|
|
||||||
|
|
||||||
var citytable;
|
var citytable;
|
||||||
|
var datetable;
|
||||||
|
|
||||||
function reloadtable() {
|
function reloadtable() {
|
||||||
$.post('/senddata/wastedata', 'action=getAllCities', function (data) {
|
$.post('/senddata/wastedata', 'action=getAllCities', function (data) {
|
||||||
@ -108,14 +90,63 @@ $(document).ready(function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var DataTable;
|
|
||||||
function reloadDateTable() {
|
function reloadDateTable() {
|
||||||
$.post('/senddata/wastedata', 'action=getAllDates', function (data) {
|
$.post('/senddata/wastedata', 'action=getAllDates', function (data) {
|
||||||
if (DataTable != null) {
|
if (datetable != null) {
|
||||||
DataTable.destroy(); //delete table if already created
|
datetable.destroy(); //delete table if already created
|
||||||
|
}
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
if (data.query == "ok") {
|
||||||
|
$('#picupdates-tablebody').html("");
|
||||||
|
$(".delbtndate").off();
|
||||||
|
|
||||||
|
for (var i = 0; i < data.data.length; i++) {
|
||||||
|
$('#picupdates-tablebody').append("<tr>" +
|
||||||
|
"<td>" + data.data[i].cityname + "</td>" +
|
||||||
|
"<td>" + data.data[i].zone + "</td>" +
|
||||||
|
"<td>" + data.data[i].wastetype + "</td>" +
|
||||||
|
"<td>" + data.data[i].date + "</td>" +
|
||||||
|
"<td>" + "<button dataid='" + data.data[i].id + "' type='button' class='delbtndate btn btn-danger'>X</button>" + "</td>" +
|
||||||
|
"</tr>");
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo
|
$(".delbtndate").click(function (event) {
|
||||||
|
var id = event.target.getAttribute("dataid");
|
||||||
|
console.log("clicked btn data " + id);
|
||||||
|
$.post('/senddata/wastedata', 'action=deletedate&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. ')
|
||||||
|
|
||||||
|
});
|
||||||
|
reloadDateTable();
|
||||||
|
} 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");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
datetable = $("#table-pickupdates").DataTable({
|
||||||
|
"order": [[3, "asc"]]
|
||||||
|
});
|
||||||
|
|
||||||
|
//todo picupdates-tablebody
|
||||||
}, "json");
|
}, "json");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,10 +254,31 @@ $(document).ready(function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".dropdown-item-wastetype").click(function (event) {
|
$("#dropdown-type-data").click(function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
|
var dropdata = $("#dropdown-type-drops");
|
||||||
|
dropdata.html("");
|
||||||
|
console.log("clickeeeed");
|
||||||
|
|
||||||
|
$.post('/senddata/newdate', 'action=gettypes&cityname=' + $("#dropdown-city").html() + '&zonename=' + $("#dropdown-zone").html(), function (data) {
|
||||||
|
console.log(data);
|
||||||
|
if (data.query == "ok") {
|
||||||
|
for (var i = 0; i < data.data.length; i++) {
|
||||||
|
var type = data.data[i].wastetype;
|
||||||
|
dropdata.append("<a class=\"dropdown-data-typename dropdown-item\" href=\"#\">" + type + "</a>");
|
||||||
|
}
|
||||||
|
|
||||||
|
$(".dropdown-data-typename").off();
|
||||||
|
$(".dropdown-data-typename").click(function (evnt) {
|
||||||
|
evnt.preventDefault();
|
||||||
$("#dropdown-type-data").html($(this).html());
|
$("#dropdown-type-data").html($(this).html());
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
$('.btn-savelist').click(function () {
|
$('.btn-savelist').click(function () {
|
||||||
@ -253,6 +305,7 @@ $(document).ready(function () {
|
|||||||
zone.html("Select Zone");
|
zone.html("Select Zone");
|
||||||
wastetype.html("Select waste type");
|
wastetype.html("Select waste type");
|
||||||
date.val("");
|
date.val("");
|
||||||
|
reloadDateTable();
|
||||||
} else if (data.status == "citydoesntexist") {
|
} else if (data.status == "citydoesntexist") {
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
type: "warning",
|
type: "warning",
|
||||||
|
127
src/resources/wwwroot/js/device.js
Normal file
127
src/resources/wwwroot/js/device.js
Normal file
@ -0,0 +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("<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();
|
||||||
|
//devices-tablebody
|
||||||
|
|
||||||
|
}
|
||||||
|
$(".configuredevicebutton").click(function (event) {
|
||||||
|
var id = event.target.getAttribute("deviceid");
|
||||||
|
var cityname;
|
||||||
|
var zone;
|
||||||
|
var wastetype;
|
||||||
|
var devicename;
|
||||||
|
var devicelocation;
|
||||||
|
|
||||||
|
$.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);
|
||||||
|
cityname = result.value[2];
|
||||||
|
devicename = result.value[0];
|
||||||
|
devicelocation = result.value[1];
|
||||||
|
|
||||||
|
console.log("cityname=" + cityname);
|
||||||
|
$.post('/senddata/Devicedata', 'action=getzones&cityname=' + cityname, function (data) {
|
||||||
|
Swal.mixin({
|
||||||
|
input: 'text',
|
||||||
|
confirmButtonText: 'Next →',
|
||||||
|
showCancelButton: true,
|
||||||
|
progressSteps: ['1']
|
||||||
|
}).queue([
|
||||||
|
{
|
||||||
|
title: 'City',
|
||||||
|
text: 'Select your City',
|
||||||
|
input: 'select',
|
||||||
|
inputOptions: data
|
||||||
|
}
|
||||||
|
]).then((result) => {
|
||||||
|
if (result.value) {
|
||||||
|
console.log(result.value);
|
||||||
|
zone = result.value[0];
|
||||||
|
$.post('/senddata/Devicedata', 'action=gettypes&cityname=' + cityname + '&zonename=' + zone, function (data) {
|
||||||
|
Swal.mixin({
|
||||||
|
input: 'text',
|
||||||
|
confirmButtonText: 'Next →',
|
||||||
|
showCancelButton: true,
|
||||||
|
progressSteps: ['1']
|
||||||
|
}).queue([
|
||||||
|
{
|
||||||
|
title: 'City',
|
||||||
|
text: 'Select your City',
|
||||||
|
input: 'select',
|
||||||
|
inputOptions: data
|
||||||
|
}
|
||||||
|
]).then((result) => {
|
||||||
|
if (result.value) {
|
||||||
|
console.log(result.value);
|
||||||
|
wastetype = result.value[0];
|
||||||
|
|
||||||
|
$.post('/senddata/Devicedata', 'action=savetodb&deviceid=' + id + '&cityname=' + cityname + '&zonename=' + zone + '&wastetype=' + wastetype + '&devicename=' + devicename + '&devicelocation=' + devicelocation, function (data) {
|
||||||
|
if (data.success) {
|
||||||
|
Swal.fire({
|
||||||
|
type: "success",
|
||||||
|
title: 'Successfully configured!',
|
||||||
|
html: 'This alert closes automatically.',
|
||||||
|
timer: 1000,
|
||||||
|
}).then((result) => {
|
||||||
|
console.log('Popup closed. ')
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
console.log("click..." + id);
|
||||||
|
});
|
||||||
|
var test = $('#table-devices').DataTable();
|
||||||
|
}, 'json');
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
14
src/resources/wwwroot/js/userManager.js
Normal file
14
src/resources/wwwroot/js/userManager.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
$(document).ready(function () {
|
||||||
|
console.log("page loaded");
|
||||||
|
$.post('/senddata/checkloginstate', 'action=getloginstate', function (data) {
|
||||||
|
console.log(data);
|
||||||
|
if (data.loggedin == true) {
|
||||||
|
$("#userlabel").html(" " + data.username);
|
||||||
|
if (data.permission > 0) {
|
||||||
|
$("#adminpanel").show();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$("#userlabel").html(" not logged in!!");
|
||||||
|
}
|
||||||
|
}, 'json');
|
||||||
|
});
|
@ -7,7 +7,7 @@
|
|||||||
"description": "A web app to manage waste pickups",
|
"description": "A web app to manage waste pickups",
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
"src": "wasteicon.png",
|
"src": "favicon.png",
|
||||||
"sizes": "512x512",
|
"sizes": "512x512",
|
||||||
"type": "image/png"
|
"type": "image/png"
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ const staticAssets = [
|
|||||||
'/lib/jquery.min.js',
|
'/lib/jquery.min.js',
|
||||||
'/lib/popper.min.js',
|
'/lib/popper.min.js',
|
||||||
'/rsc/login2.jpg',
|
'/rsc/login2.jpg',
|
||||||
'/wasteicon.png'
|
'/favicon.png'
|
||||||
];
|
];
|
||||||
|
|
||||||
self.addEventListener('install', async e => {
|
self.addEventListener('install', async e => {
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
<aside class="main-sidebar sidebar-dark-primary elevation-4">
|
<aside class="main-sidebar sidebar-dark-primary elevation-4">
|
||||||
<!-- Brand Logo -->
|
<!-- Brand Logo -->
|
||||||
<a href="dashboard.html" class="brand-link">
|
<a href="dashboard.html" class="brand-link">
|
||||||
<img src="lib/AdminLTE/dist/img/AdminLTELogo.png" alt="AdminLTE Logo"
|
<img src="/favicon.png" alt="AdminLTE Logo"
|
||||||
class="brand-image img-circle elevation-3"
|
class="brand-image img-circle elevation-3"
|
||||||
style="opacity: .8">
|
style="opacity: .8">
|
||||||
<span class="brand-text font-weight-light">Waste Control</span>
|
<span class="brand-text font-weight-light">Waste Control</span>
|
||||||
@ -289,5 +289,7 @@
|
|||||||
|
|
||||||
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
|
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
|
||||||
|
|
||||||
|
<script src="js/userManager.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Reference in New Issue
Block a user