replaced souts with log.debug

This commit is contained in:
Lukas-Heiligenbrunner 2019-10-11 16:16:28 +02:00
parent 660207485a
commit 08fd25124c
13 changed files with 120 additions and 104 deletions

View File

@ -57,7 +57,8 @@ justify-content: center;
}
.create-table-window-content{
overflow:scroll;
height: calc(100% - 90px);
overflow: auto;
}
.create-table-window-settings{

View File

@ -11,7 +11,6 @@ $(document).ready(function() {
}, 'json');
$('#logoutbtn').click(function () {
$.post('/senddata/checkloginstate', 'action=logout', function (data) {
console.log(data);
@ -26,4 +25,34 @@ $(document).ready(function() {
$('.exit-icon').click(function () {
$('.create-table').hide();
});
$('.dropdown-item').click(function () {
$('#dropdown-wastetype').html($(this).html());
});
$('.btn-addtolist').click(function () {
console.log("added new row to table");
$('#addtable-body').append("<tr>" +
"<td class='td-dropdown-wastetype'>" + $('#dropdown-wastetype').html() + "</td>" +
"<td class='td-input-wastetime'>" + $('#input-wastetime').val() + "</td>" +
"<td class='td-input-wasteregion'>" + $('#input-wasteregion').val() + "</td>" +
"<td class='td-input-wastezone'>" + $('#input-wastezone').val() + "</td>" +
"</tr>");
});
$('#btn-savelist').click(function () {
console.log("saving list");
var wastetypearr = $('.td-dropdown-wastetype');
var wastetime = $('.td-input-wastetime');
var wasteregionarr = $('.td-input-wasteregion');
var wastezonearr = $('.td-input-wastezone');
for (var i = 0; i < wastetypearr.length; i++) {
console.log(wastetypearr[i].innerHTML);
$.post('/senddata/wastedata', 'action=senddata&wastetype=' + wastetypearr[i].innerHTML +"&wastetime="+wastetime[i].innerHTML+"&wasteregion="+wasteregionarr[i].innerHTML+"&wastezone="+wastezonearr[i].innerHTML, function (data) {
console.log(data);
}, 'text');
}
});
});

View File

@ -87,7 +87,7 @@
<h4>Add Data:</h4>
<div class="input-group mt-3 mb-3" style="width: 50%;">
<div class="input-group-prepend">
<button type="button" class="btn btn-outline-light dropdown-toggle" data-toggle="dropdown">
<button id="dropdown-wastetype" type="button" class="btn btn-outline-light dropdown-toggle" data-toggle="dropdown">
Select waste type
</button>
<div class="dropdown-menu">
@ -98,7 +98,7 @@
</div>
</div>
<input style="width: 50px;" class="form-control" id="date" name="date" placeholder="MM/DD/YYY" type="text"/>
<input id="input-wastetime" style="width: 50px;" class="form-control" id="date" name="date" placeholder="MM/DD/YYY" type="text"/>
<script>
$(document).ready(function(){
@ -114,65 +114,22 @@
})
</script>
<input type="text" class="form-control" placeholder="Region">
<button type="button" class="btn btn-success" style="float:right;">Add to list</button>
<input id="input-wasteregion" type="text" class="form-control" placeholder="Region">
<input id="input-wastezone" type="text" class="form-control" placeholder="Zone">
<button type="button" class="btn-addtolist btn btn-success" style="float:right;">Add to list</button>
</div>
<h4>Your Data:</h4>
<table class="table table-dark table-hover" style="width: 50%;">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Waste type</th>
<th>Date</th>
<th>Region</th>
<th>Zone</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
<tbody id="addtable-body">
</tbody>
</table>
</form>
@ -180,7 +137,7 @@
</div>
<div class="create-table-window-bottom">
<button type="button" class="btn btn-success" style="float:right;">Save</button>
<button id="btn-savelist" type="button" class="btn btn-success" style="float:right;">Save</button>
</div>
</div>

View File

@ -1,5 +1,7 @@
package com.wasteinformationserver;
import com.wasteinformationserver.basicutils.Log;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
@ -47,13 +49,13 @@ public class Date {
public void printList() {
for (int n = 0; n < list.size(); n++) {
System.out.println(list.get(n));
Log.debug(list.get(n));
}
}
public void printListnew() {
for (int n = 0; n < listnew.size(); n++) {
System.out.println(listnew.get(n));
Log.debug(listnew.get(n));
}
}

View File

@ -1,5 +1,7 @@
package com.wasteinformationserver.db;
import com.wasteinformationserver.basicutils.Log;
import javax.swing.table.DefaultTableModel;
import java.sql.Connection;
import java.sql.ResultSet;
@ -49,7 +51,7 @@ Database {
}
}
System.out.println(row);
Log.debug(row);
}
} catch (SQLException e) {

View File

@ -1,5 +1,6 @@
package com.wasteinformationserver.mqtt;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.jdcb;
import java.awt.event.ActionEvent;
@ -26,11 +27,11 @@ public class mqtt {
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
String date = df.format(now.getTime());
System.out.println(date);
Log.debug(date);
String[] parts = date.split(" ");
String temp2=parts[0];
System.out.println(temp2);
Log.debug(temp2);
String[] partstwo=temp2.split("\\.");
String newDate="20"+partstwo[2]+"-"+partstwo[1]+"-"+partstwo[0];
@ -38,7 +39,7 @@ public class mqtt {
mqttreceiver mr = new mqttreceiver();
// System.out.println(message);
// Log.debug(message);
mr.addMessageReceivedListener(new ActionListener() {
@Override
@ -61,7 +62,7 @@ public class mqtt {
String temp;
System.out.println(message);
Log.debug(message);
jdcb Database = new jdcb("placeuser", "eaL956R6yFItQVBl", "wasteinformation");
ResultSet result = Database.executeQuery(message);
try {
@ -96,7 +97,7 @@ public class mqtt {
if (temp != null) {
transmitmessageAbfallart(temp);
} else {
System.out.println("NO Connection");
Log.debug("NO Connection");
}
}
} catch (SQLException e) {
@ -110,7 +111,7 @@ public class mqtt {
private void transmitmessageAbfallart(String temp) {
mqtttransmitter mt = new mqtttransmitter();
System.out.println(temp);
Log.debug(temp);
mt.sendmessage(temp);
}
}

View File

@ -1,5 +1,6 @@
package com.wasteinformationserver.mqtt;
import com.wasteinformationserver.basicutils.Log;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
@ -47,7 +48,7 @@ public class mqttreceiver {
}
});
client.subscribe("TopicIn");
System.out.println("subscribed topic");
Log.debug("subscribed topic");
} catch (MqttException e) {
e.printStackTrace();
}

View File

@ -1,5 +1,6 @@
package com.wasteinformationserver.mqtt;
import com.wasteinformationserver.basicutils.Log;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
@ -29,24 +30,24 @@ public class mqtttransmitter {
MqttClient sampleClient = new MqttClient(broker, clientId, persistence);
MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setCleanSession(true);
System.out.println("Connecting to broker: " + broker);
Log.debug("Connecting to broker: " + broker);
sampleClient.connect(connOpts);
System.out.println("Connected");
System.out.println("Publishing message: " + content);
Log.debug("Connected");
Log.debug("Publishing message: " + content);
MqttMessage message = new MqttMessage(content.getBytes());
message.setQos(qos);
sampleClient.publish(topic, message);
System.out.println("Message published");
Log.debug("Message published");
sampleClient.disconnect();
System.out.println("Disconnected");
Log.debug("Disconnected");
} catch (MqttException me) {
System.out.println("reason " + me.getReasonCode());
System.out.println("msg " + me.getMessage());
System.out.println("loc " + me.getLocalizedMessage());
System.out.println("cause " + me.getCause());
System.out.println("excep " + 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);
me.printStackTrace();
}
}

View File

@ -15,7 +15,7 @@ public class CheckLoginState extends PostRequest {
return "{\"loggedin\":false}";
}
}else if ((params.get("action")).equals("logout")){
System.out.println("logging out");
Log.debug("logging out");
LoginState.getObject().logOut();
return "{\"loggedin\":false}";
}

View File

@ -0,0 +1,19 @@
package com.wasteinformationserver.website;
import com.wasteinformationserver.basicutils.Log;
import java.util.HashMap;
public class DataRequest extends PostRequest {
@Override
public String request(HashMap<String, String> params) {
switch (params.get("action")){
case "senddata":
Log.debug(params.toString());
// TODO: 11.10.19 store data in database
break;
}
return "";
}
}

View File

@ -1,5 +1,6 @@
package com.wasteinformationserver.website;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.jdcb;
import java.sql.ResultSet;
@ -21,20 +22,20 @@ public class LoginRequest extends PostRequest {
if (s.getRow() == 1) {
//success
if (HttpTools.StringToMD5(password).equals(s.getString("password"))) {
System.out.println("login success");
Log.debug("login success");
LoginState.getObject().logIn();
LoginState.getObject().setAccountData(username,"","","");
response = "{\"accept\": true}";
} else {
System.out.println("wrong password");
Log.debug("wrong password");
}
} else if (s.getRow() == 0) {
//user not found
System.out.println("user not found");
Log.debug("user not found");
} else {
//internal error two users with same name...?
}
System.out.println("rowcount: " + s.getRow());
Log.debug("rowcount: " + s.getRow());
} catch (SQLException e) {
e.printStackTrace();
}

View File

@ -1,5 +1,6 @@
package com.wasteinformationserver.website;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.jdcb;
import java.util.HashMap;
@ -7,7 +8,7 @@ import java.util.HashMap;
public class RegisterRequest extends PostRequest {
@Override
public String request(HashMap<String, String> params) {
System.out.println(params.toString());
Log.debug(params.toString());
String passhash = HttpTools.StringToMD5(params.get("password"));

View File

@ -21,6 +21,7 @@ public class Webserver {
server.createContext("/senddata/loginget", new LoginRequest());
server.createContext("/senddata/registerpost",new RegisterRequest());
server.createContext("/senddata/checkloginstate",new CheckLoginState());
server.createContext("/senddata/wastedata",new DataRequest());
server.setExecutor(null); // creates a default executor
server.start();