Merge remote-tracking branch 'origin/master'

This commit is contained in:
Gregor_Dutzler 2019-12-13 15:05:39 +01:00
commit 3a82f81c1a
7 changed files with 208 additions and 96 deletions

View File

@ -6,6 +6,7 @@
<GradleProjectSettings>
<option name="delegatedBuild" value="true" />
<option name="testRunner" value="GRADLE" />
<option name="disableWrapperSourceDistributionNotification" value="true" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="11" />

View File

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

View File

@ -1,5 +1,6 @@
package com.wasteinformationserver.website.datarequests;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.website.basicrequest.PostRequest;
import java.io.File;
@ -27,7 +28,7 @@ public class AdminRequests extends PostRequest {
/* is it a jar file? */
if (!currentJar.getName().endsWith(".jar"))
System.out.println("not jar");
Log.warning("not jar --> cant restart");
/* Build command: java -jar application.jar */
final ArrayList<String> command = new ArrayList<String>();

View File

@ -17,6 +17,8 @@ public class DataRequest extends PostRequest {
@Override
public String request(HashMap<String, String> params) {
StringBuilder sb = new StringBuilder();
ResultSet set = null;
int status = -1;
JDCB jdcb;
try {
@ -33,7 +35,7 @@ public class DataRequest extends PostRequest {
// check if wastezone and wasteregion already exists
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;
try {
if (set != null) {
@ -45,14 +47,12 @@ public class DataRequest extends PostRequest {
}
if (size == 0) {
//doesnt exist
System.out.println("doesnt exist");
int status = 0;
try {
status = jdcb.executeUpdate("INSERT INTO `cities`(`userid`, `name`, `wastetype`, `zone`) VALUES ('0','" + params.get("cityname") + "','" + params.get("wastetype") + "','" + params.get("wastezone") + "');");
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println(status);
if (status == 1) {
sb.append("\"status\" : \"inserted\"");
} else {
@ -64,7 +64,6 @@ public class DataRequest extends PostRequest {
sb.append("\"status\" : \"exists\"");
} else {
//already exists
System.out.println("already exists");
sb.append("\"status\" : \"exists\"");
}
@ -72,20 +71,18 @@ public class DataRequest extends PostRequest {
sb.append("}");
break;
case "getAllCities":
ResultSet sett = jdcb.executeQuery("select * from cities");
Log.debug(sett.toString());
set = jdcb.executeQuery("select * from cities");
Log.debug(set.toString());
sb.append("{\"data\":[");
try {
while (sett.next()) {
sb.append("{\"cityname\":\"" + sett.getString("name") + "\"");
sb.append(",\"wastetype\":\"" + sett.getString("wastetype") + "\"");
sb.append(",\"id\":\"" + sett.getString("id") + "\"");
sb.append(",\"zone\":\"" + sett.getString("zone") + "\"}");
if (!sett.isLast()) {
while (set.next()) {
sb.append("{\"cityname\":\"" + set.getString("name") + "\"");
sb.append(",\"wastetype\":\"" + set.getString("wastetype") + "\"");
sb.append(",\"id\":\"" + set.getString("id") + "\"");
sb.append(",\"zone\":\"" + set.getString("zone") + "\"}");
if (!set.isLast()) {
sb.append(",");
}
// System.out.println(sett.getString("name"));
}
} catch (SQLException e) {
e.printStackTrace();
@ -97,8 +94,6 @@ public class DataRequest extends PostRequest {
case "deletecity":
//DELETE FROM `cities` WHERE `id`=0
sb.append("{");
Log.debug(params.get("id"));
int status = 0;
try {
status = jdcb.executeUpdate("DELETE FROM `cities` WHERE `id`='" + params.get("id") + "'");
if (status == 1) {
@ -121,49 +116,41 @@ public class DataRequest extends PostRequest {
sb.append("}");
break;
case "getcollectionnumber": //todo maybe combine all three to one
sb.append("{");
case "getAllDates":
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 {
ResultSet settt = jdcb.executeQuery("select * from pickupdates");
settt.last();
sb.append("\"collectionnumber\":\"" + settt.getRow() + "\"");
} catch (SQLException e) {
Log.error("sql exception: " + e.getMessage());
sb.append("\"status\" : \"error\"");
while (set.next()) {
sb.append("{\"date\":\"" + set.getString("pickupdate") + "\"");
sb.append(",\"cityname\":\"" + set.getString("name") + "\"");
sb.append(",\"wastetype\":\"" + set.getString("wastetype") + "\"");
sb.append(",\"id\":\"" + set.getString("id") + "\"");
sb.append(",\"zone\":\"" + set.getString("zone") + "\"}");
if (!set.isLast()) {
sb.append(",");
}
}
} catch (SQLException e) {
e.printStackTrace();
}
sb.append("]");
sb.append(",\"query\":\"ok\"");
sb.append("}");
break;
case "getcollectioninfuture":
case "deletedate":
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 '"+time+"' AND '2222-12-27'");
settt.last();
sb.append("\"collectionnumber\":\"" + settt.getRow() + "\"");
} catch (SQLException e) {
Log.error("sql exception: " + e.getMessage());
status = jdcb.executeUpdate("DELETE FROM `pickupdates` WHERE `id`='" + params.get("id") + "'");
if (status == 1) {
//success
sb.append("\"status\" : \"success\"");
} else {
sb.append("\"status\" : \"error\"");
}
sb.append(",\"query\":\"ok\"");
sb.append("}");
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 (SQLIntegrityConstraintViolationException e) {
Log.warning("dependencies of deletion exist");
sb.append("\"status\" : \"dependenciesnotdeleted\"");
} catch (SQLException e) {
Log.error("sql exception: " + e.getMessage());
sb.append("\"status\" : \"error\"");
@ -179,6 +166,41 @@ public class DataRequest extends PostRequest {
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("}");
break;

View File

@ -14,6 +14,7 @@ public class NewDateRequest extends PostRequest {
public String request(HashMap<String, String> params) {
StringBuilder sb = new StringBuilder();
JDCB jdcb;
ResultSet set;
try {
jdcb = JDCB.getInstance();
} catch (IOException e) {
@ -22,21 +23,21 @@ public class NewDateRequest extends PostRequest {
}
switch (params.get("action")) {
case "getCitynames":
ResultSet sett = jdcb.executeQuery("select * from cities");
Log.debug(sett.toString());
set = jdcb.executeQuery("select * from cities");
Log.debug(set.toString());
sb.append("{\"data\":[");
try {
String prev = "";
while (sett.next()) {
if (prev.equals(sett.getString("name"))) {
while (set.next()) {
if (prev.equals(set.getString("name"))) {
} else {
if (!sett.isFirst()) {
if (!set.isFirst()) {
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) {
e.printStackTrace();
@ -47,7 +48,7 @@ public class NewDateRequest extends PostRequest {
Log.debug(sb.toString());
break;
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());
sb.append("{\"data\":[");
try {
@ -70,16 +71,40 @@ public class NewDateRequest extends PostRequest {
sb.append(",\"query\":\"ok\"");
sb.append("}");
break;
case "gettypes":
set = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='"+params.get("zonename")+"' ORDER BY zone ASC");
Log.debug(set.toString());
sb.append("{\"data\":[");
try {
String prev = "42";
while (set.next()) {
if (prev == set.getString("wastetype")) {
} else {
sb.append("{\"wastetype\":\"" + set.getString("wastetype") + "\"}");
if (!set.isLast()) {
sb.append(",");
}
}
prev = set.getString("wastetype");
}
} catch (SQLException e) {
e.printStackTrace();
}
sb.append("]");
sb.append(",\"query\":\"ok\"");
sb.append("}");
break;
case "newdate":
sb.append("{");
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 {
seti.last();
if (seti.getRow() == 1) {
Log.debug(seti.getInt("id"));
set.last();
if (set.getRow() == 1) {
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) {
sb.append("\"status\" : \"success\"");
} else {

View File

@ -145,14 +145,14 @@
<!-- ./col -->
<div class="col-lg-3 col-6">
<!-- small box -->
<div class="small-box bg-success">
<div class="small-box bg-gray">
<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 class="icon">
<i class="ion ion-stats-bars"></i>
<i class="ion ion-android-globe" style="color: lightgrey"></i>
</div>
<a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
</div>
@ -167,7 +167,7 @@
<p>Planned Collections</p>
</div>
<div class="icon">
<i class="ion ion-person-add"></i>
<i class="ion ion-calendar"></i>
</div>
<a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
</div>
@ -175,14 +175,14 @@
<!-- ./col -->
<div class="col-lg-3 col-6">
<!-- small box -->
<div class="small-box bg-danger">
<div class="small-box bg-success">
<div class="inner">
<h3 id="finished-collection-label">65</h3>
<p>Finished Collections</p>
</div>
<div class="icon">
<i class="ion ion-pie-graph"></i>
<i class="ion ion-android-checkmark-circle"></i>
</div>
<a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
</div>
@ -311,11 +311,7 @@
data-toggle="dropdown">
Select waste type
</button>
<div 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 id="dropdown-type-drops" class="dropdown-menu">
</div>
</div>
<input id="input-wastetime" style="width: 50px;" class="form-control" id="date"

View File

@ -13,21 +13,15 @@ $(document).ready(function () {
}, 'json');
//load total collections
$.post('/senddata/wastedata', 'action=getcollectionnumber', function (data) {
$.post('/senddata/wastedata', 'action=getStartHeaderData', function (data) {
console.log(data);
$("#total-connection-labels").html(data.collectionnumber);
}, 'json');
//load future collections
$.post('/senddata/wastedata', 'action=getcollectioninfuture', function (data) {
console.log(data);
$("#planed-collection-label").html(data.collectionnumber);
}, 'json');
$("#planed-collection-label").html(data.futurecollections);
//load future collections
$.post('/senddata/wastedata', 'action=getfinishedcollections', function (data) {
console.log(data);
$("#finished-collection-label").html(data.collectionnumber);
$("#finished-collection-label").html(data.finshedcollections);
$("#total-city-number-label").html(data.citynumber);
}, 'json');
//load version footer
@ -38,6 +32,7 @@ $(document).ready(function () {
var citytable;
var datetable;
function reloadtable() {
$.post('/senddata/wastedata', 'action=getAllCities', function (data) {
@ -108,14 +103,63 @@ $(document).ready(function () {
}
var DataTable;
function reloadDateTable() {
$.post('/senddata/wastedata', 'action=getAllDates', function (data) {
if (DataTable != null) {
DataTable.destroy(); //delete table if already created
if (datetable != null) {
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");
}
@ -223,10 +267,32 @@ $(document).ready(function () {
});
});
$(".dropdown-item-wastetype").click(function (event) {
$("#dropdown-type-data").click(function (event) {
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());
});
}
});
});
$('.btn-savelist').click(function () {
@ -253,6 +319,7 @@ $(document).ready(function () {
zone.html("Select Zone");
wastetype.html("Select waste type");
date.val("");
reloadDateTable();
} else if (data.status == "citydoesntexist") {
Swal.fire({
type: "warning",