11 Commits

Author SHA1 Message Date
ce44ee5d17 version 0.3.0-Beta 2020-01-16 21:24:21 +01:00
23f75cae4f correctly configure new devices
edit data in db correctly
response correctly to requests
2020-01-16 21:12:05 +01:00
b9ba0dbcef load devices in table
configure popup for devices
2020-01-16 17:27:16 +01:00
92ef4cc0c6 * added table to device page
* request devices from js from db
2020-01-13 21:00:33 +01:00
ac02e4bd62 * added some todos 2020-01-12 14:05:28 +01:00
c3fb92d6eb * changed city zone handling to server instead of pcb 2020-01-12 13:22:31 +01:00
05b15a1ea2 * style improvements in mqtt 2020-01-12 11:32:33 +01:00
86dc38a8da * Waste logo on every page
* username displayed right on every page
2020-01-12 11:23:47 +01:00
7c8a0d3018 * mqtt service cleanup
* removed unused methods
2020-01-12 11:23:05 +01:00
4b96ad576d cleanup in mqtt methods
deleted unneccessary classes
2020-01-10 18:45:32 +01:00
f7383474ac * fixed multiple username bug
* added table to devices page
2020-01-10 18:18:06 +01:00
21 changed files with 609 additions and 479 deletions

2
.idea/misc.xml generated
View File

@ -4,7 +4,7 @@
<component name="JavaScriptSettings"> <component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" /> <option name="languageLevel" value="ES6" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_13" default="true" project-jdk-name="13" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -5,7 +5,7 @@ plugins {
} }
group 'com.wasteinformationserver' group 'com.wasteinformationserver'
version '0.2.1-Beta' version '0.3.0-Beta'
sourceCompatibility = 1.8 sourceCompatibility = 1.8

View File

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

View File

@ -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,

View File

@ -3,19 +3,18 @@ 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);
Info.init();
Log.setLevel(Log.INFO);
Log.info("startup of WasteInformationServer"); Log.info("startup of WasteInformationServer");
Log.info("mem: "+Runtime.getRuntime().totalMemory());
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try { try {
Thread.sleep(200); Thread.sleep(200);
@ -27,21 +26,18 @@ public class main {
} }
})); }));
Info.init();
Log.info("Server version: " + Info.getVersion()); Log.info("Server version: " + Info.getVersion());
Log.debug("Build date: " + Info.getBuilddate()); Log.debug("Build date: " + Info.getBuilddate());
//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("users", "admin0", "wasteinformation", "192.168.65.15", 1883); //JDCB.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306);
JDCB.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"); }
}
}).start();
//startup web server //startup web server
@ -52,12 +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.error("An error occured in the class mqtt"); Log.error("An error occured in the class mqtt");
} }
Log.info("mem: "+Runtime.getRuntime().totalMemory());
} }
} }

View 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;
}
}

View File

@ -1,154 +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", "JavaSample42");
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) {
Log.debug("received message");
String[] split = e.getActionCommand().split(",");
String wastetyp = getTyp(Integer.parseInt(split[2]));
getDatabasedata("SELECT pickupdates.pickupdate FROM pickupdates WHERE pickupdates.citywastezoneid=(SELECT cities.zone FROM cities WHERE cities.name='" + split[1] + "' AND cities.wastetype='" + wastetyp + "' AND cities.zone=" + split[3] + ")", wastetyp, Integer.parseInt(split[0]));
}
});
mr.getmessage();
}
public void getDatabasedata(String message, String wastetyp, int clientidentify) {
Log.debug(message);
Log.debug(wastetyp);
Log.debug(clientidentify);
JDCB Database = null;
try {
Database = JDCB.getInstance();
} catch (IOException e) {
Log.error("No Connection to the databank");
}
int wastenumber = getIntTyp(wastetyp);
ResultSet result = Database.executeQuery(message);
try {
result.last();
if (result.getFetchSize() == 0){
//if not found in db --> send zero
transmitmessageAbfallart(clientidentify + "," + wastenumber + "," + 0);
}
result.first();
while (result.next()) {
String newDate = getDateDatabase(String.valueOf(result.getString("pickupdate")));
String currentDate = getcurrentDate();
String Datetomorrow = nexDayDate();
if (currentDate.equals(newDate) || currentDate.equals(Datetomorrow)) {
transmitmessageAbfallart(clientidentify + "," + wastenumber + "," + 1);
} else {
transmitmessageAbfallart(clientidentify + "," + wastenumber + "," + 0);
}
}
} catch (SQLException e) {
Log.error("No data from database");
}
}
private void transmitmessageAbfallart(String temp) {
Log.debug("sending message >>>"+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("/");
return split[2] + "." + split[1] + "." + split[0];
}
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;
if (temp.equals("Plastic")) {
number = 1;
} else if (temp.equals("Metal")) {
number = 2;
} else if (temp.equals("Residual waste")) {
number = 3;
} else if (temp.equals("Biowaste")) {
number = 4;
}
return number;
}
private String getDateDatabase(String temptime) {
String[] parts = temptime.split("-");
String tempyear = parts[0];
String[] yearsplit = tempyear.split("0");
String tempyearnew = yearsplit[1];
return parts[2] + "." + parts[1] + "." + tempyearnew;
}
private String getcurrentDate() {
GregorianCalendar now = new GregorianCalendar();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
String date = df.format(now.getTime());
String[] partstwo = date.split(",");
return partstwo[0];
}
}

View File

@ -1,62 +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());
Log.info("received Request from PCB");
notifylisteners(message);
}
@Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
}
});
client.subscribe("TopicIn");
Log.debug("subscribed topic");
} catch (MqttException e) {
Log.error("Connection to the ESB 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);
}
}

View File

@ -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);
}
}
}

View File

@ -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";

View File

@ -2,10 +2,7 @@ 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;
@ -29,6 +26,7 @@ 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();

View File

@ -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();
}
}

View File

@ -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">

View File

@ -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>

View File

@ -47,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>
@ -440,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>

View File

@ -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>
@ -65,64 +65,50 @@
</div> </div>
</div> </div>
<!-- Sidebar --> <!-- Sidebar Menu -->
<div class="sidebar"> <nav class="mt-2">
<!-- Sidebar user panel (optional) --> <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu"
<div class="user-panel mt-3 pb-3 mb-3 d-flex"> data-accordion="false">
<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 --> <li class="nav-item">
<nav class="mt-2"> <a href="#todo" class="nav-link">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" <i class="nav-icon fas fa-cog"></i>
data-accordion="false"> <p>
Settings
</p>
</a>
</li>
<li class="nav-item"> <li class="nav-item">
<a href="#todo" class="nav-link"> <a href="index.html" class="nav-link" id="logoutbtn">
<i class="nav-icon fas fa-cog"></i> <i class="nav-icon fas fa-sign-out-alt"></i>
<p> <p>
Settings Logout
</p> </p>
</a> </a>
</li> </li>
<li class="nav-item"> <li id="adminpanel" class="nav-item hideit">
<a href="index.html" class="nav-link" id="logoutbtn"> <a href="adminpanel.html" class="nav-link">
<i class="nav-icon fas fa-sign-out-alt"></i> <i class="nav-icon fas fa-plus-circle"></i>
<p> <p>
Logout Admin panel
</p> </p>
</a> </a>
</li> </li>
<li id="adminpanel" class="nav-item hideit"> <li id="devicepanel" class="nav-item">
<a href="adminpanel.html" class="nav-link"> <a href="device.html" class="nav-link">
<i class="nav-icon fas fa-plus-circle"></i> <i class="nav-icon fas fa-plus-circle"></i>
<p> <p>
Admin panel Devices
</p> </p>
</a> </a>
</li> </li>
</ul>
<li id="devicepanel" class="nav-item"> </nav>
<a href="device.html" class="nav-link"> <!-- /.sidebar-menu -->
<i class="nav-icon fas fa-plus-circle"></i> </div>
<p>
Devices
</p>
</a>
</li>
</ul>
</nav>
<!-- /.sidebar-menu -->
</div>
<!-- /.sidebar --> <!-- /.sidebar -->
</aside> </aside>
@ -193,42 +179,32 @@
<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>
User Data All Devices
</h3> </h3>
<button id="btn-newdevice" type="button" class="btn btn-success"
style="float:right;">Save
</button>
</div><!-- /.card-header --> </div><!-- /.card-header -->
<div class="card-body"> <div class="card-body">
<div class="form-group" style="margin-top: 15px; width: 10cm;"> <table id="table-devices" class="table table-bordered table-hover">
<!-- todo todo --> <thead>
<label for="new_city_cityname">City/Village name</label> <tr>
<input type="email" class="form-control" id="new_city_cityname" <th>Device ID</th>
aria-describedby="emailHelp" placeholder="Enter city name here"> <th>Devicename</th>
<small class="form-text text-muted">Please try to use no special <th>Devicelocation</th>
characters</small> <th>Zone</th>
</div> <th>X</th>
<div class="form-group" style="width: 10cm;"> </tr>
<label for="new_city_zonename">Zone Name</label> </thead>
<input type="email" class="form-control" id="new_city_zonename" <tbody id="devices-tablebody">
aria-describedby="emailHelp" placeholder="Enter Zone name here"> </tbody>
<small class="form-text text-muted">Please try to use no special <tfoot>
characters</small> <tr>
</div> <th>Device ID</th>
<th>Devicename</th>
<div class="input-group-prepend"> <th>Devicelocation</th>
<button id="dropdown-wastetype" type="button" <th>Zone</th>
class="btn btn-outline-dark dropdown-toggle" <th>X</th>
data-toggle="dropdown"> </tr>
Select waste type </tfoot>
</button> </table>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Plastic</a>
<a class="dropdown-item" href="#">Metal</a>
<a class="dropdown-item" href="#">Residual waste</a>
<a class="dropdown-item" href="#">Biowaste</a>
</div>
</div>
</div><!-- /.card-body --> </div><!-- /.card-body -->
</div> </div>
@ -312,6 +288,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>
<script src="js/device.js"></script> <script src="js/device.js"></script>
</body> </body>
</html> </html>

View File

@ -1,74 +1,77 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" dir="ltr"> <html lang="en" dir="ltr">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Login Page</title> <title>Login Page</title>
<!--Made with love by Mutiullah Samim --> <!--Made with love by Mutiullah Samim -->
<!-- Latest compiled and minified CSS --> <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="lib/bootstrap.min.css"> <link rel="stylesheet" href="lib/bootstrap.min.css">
<!-- jQuery library --> <!-- jQuery library -->
<script src="lib/jquery.min.js"></script> <script src="lib/jquery.min.js"></script>
<!-- Popper JS --> <!-- Popper JS -->
<script src="lib/popper.min.js"></script> <script src="lib/popper.min.js"></script>
<!-- Latest compiled JavaScript --> <!-- Latest compiled JavaScript -->
<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">
<script type="text/javascript" src="js/index.js"></script> <script type="text/javascript" src="js/index.js"></script>
<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">
<div class="d-flex justify-content-center h-100"> <div class="d-flex justify-content-center h-100">
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<h3>Sign In</h3> <h3>Sign In</h3>
</div> </div>
<div class="card-body"> <div class="card-body">
<form> <form>
<div class="input-group form-group"> <div class="input-group form-group">
<div class="input-group-prepend"> <div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-user"></i></span> <span class="input-group-text"><i class="fas fa-user"></i></span>
</div> </div>
<input type="text" class="form-control" placeholder="username" id="userfield"> <input type="text" class="form-control" placeholder="username" id="userfield">
</div> </div>
<div class="input-group form-group"> <div class="input-group form-group">
<div class="input-group-prepend"> <div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-key"></i></span> <span class="input-group-text"><i class="fas fa-key"></i></span>
</div> </div>
<input type="password" class="form-control" placeholder="password" id="passfield"> <input type="password" class="form-control" placeholder="password" id="passfield">
</div> </div>
<div class="row align-items-center remember"> <div class="row align-items-center remember">
<input type="checkbox">Remember Me <input type="checkbox">Remember Me
</div> </div>
<div class="form-group"> <div class="form-group">
<input type="submit" value="Login" class="btn float-right login_btn" id="loginbtn"> <input type="submit" value="Login" class="btn float-right login_btn" id="loginbtn">
</div> </div>
</form> </form>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<div class="d-flex justify-content-center links"> <div class="d-flex justify-content-center links">
Don't have an account?<a href="register.html">Sign Up</a> Don't have an account?<a href="register.html">Sign Up</a>
</div> </div>
<div class="d-flex justify-content-center"> <div class="d-flex justify-content-center">
<a href="#">Forgot your password?</a> <a href="#">Forgot your password?</a>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</body> </body>
</html> </html>

View File

@ -1,17 +1,4 @@
$(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=getStartHeaderData', function (data) { $.post('/senddata/wastedata', 'action=getStartHeaderData', function (data) {
console.log(data); console.log(data);
@ -27,7 +14,7 @@ $(document).ready(function () {
//load version footer //load version footer
// //
$.post('/senddata/wastedata', 'action=getversionandbuildtime', function (data) { $.post('/senddata/wastedata', 'action=getversionandbuildtime', function (data) {
$("#version-footer-label").html("<b>Version</b> "+data.version+" <b>Build</b> "+data.buildtime); $("#version-footer-label").html("<b>Version</b> " + data.version + " <b>Build</b> " + data.buildtime);
}, 'json'); }, 'json');
@ -112,7 +99,7 @@ $(document).ready(function () {
if (data.query == "ok") { if (data.query == "ok") {
$('#picupdates-tablebody').html(""); $('#picupdates-tablebody').html("");
$(".delbtndate").off(); $(".delbtndate").off();
for (var i = 0; i < data.data.length; i++) { for (var i = 0; i < data.data.length; i++) {
$('#picupdates-tablebody').append("<tr>" + $('#picupdates-tablebody').append("<tr>" +
@ -156,11 +143,11 @@ $(document).ready(function () {
}); });
} }
datetable = $("#table-pickupdates").DataTable({ datetable = $("#table-pickupdates").DataTable({
"order": [[ 3, "asc" ]] "order": [[3, "asc"]]
} ); });
//todo picupdates-tablebody //todo picupdates-tablebody
},"json"); }, "json");
} }
reloadtable(); reloadtable();
@ -274,7 +261,7 @@ $(document).ready(function () {
dropdata.html(""); dropdata.html("");
console.log("clickeeeed"); console.log("clickeeeed");
$.post('/senddata/newdate', 'action=gettypes&cityname=' + $("#dropdown-city").html()+'&zonename='+$("#dropdown-zone").html(), function (data) { $.post('/senddata/newdate', 'action=gettypes&cityname=' + $("#dropdown-city").html() + '&zonename=' + $("#dropdown-zone").html(), function (data) {
console.log(data); console.log(data);
if (data.query == "ok") { if (data.query == "ok") {
for (var i = 0; i < data.data.length; i++) { for (var i = 0; i < data.data.length; i++) {
@ -291,7 +278,6 @@ $(document).ready(function () {
}); });
}); });

View File

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

View 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');
});

View File

@ -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>