* finished date table
* proper selection when creating new date
This commit is contained in:
parent
23bffc4c6e
commit
f32dbd802b
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@ -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" />
|
||||
|
@ -5,7 +5,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'com.wasteinformationserver'
|
||||
version '0.1-Beta'
|
||||
version '0.2-Beta'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
|
||||
|
@ -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,8 +47,6 @@ 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) {
|
||||
@ -72,16 +72,16 @@ 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(",");
|
||||
}
|
||||
|
||||
@ -97,8 +97,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) {
|
||||
@ -120,14 +118,57 @@ public class DataRequest extends PostRequest {
|
||||
sb.append(",\"query\":\"ok\"");
|
||||
sb.append("}");
|
||||
|
||||
break;
|
||||
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 {
|
||||
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 "deletedate":
|
||||
sb.append("{");
|
||||
try {
|
||||
status = jdcb.executeUpdate("DELETE FROM `pickupdates` WHERE `id`='" + params.get("id") + "'");
|
||||
if (status == 1) {
|
||||
//success
|
||||
sb.append("\"status\" : \"success\"");
|
||||
} else {
|
||||
sb.append("\"status\" : \"error\"");
|
||||
}
|
||||
} 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\"");
|
||||
}
|
||||
|
||||
sb.append(",\"query\":\"ok\"");
|
||||
sb.append("}");
|
||||
break;
|
||||
case "getcollectionnumber": //todo maybe combine all three to one
|
||||
sb.append("{");
|
||||
|
||||
try {
|
||||
ResultSet settt = jdcb.executeQuery("select * from pickupdates");
|
||||
settt.last();
|
||||
sb.append("\"collectionnumber\":\"" + settt.getRow() + "\"");
|
||||
set = jdcb.executeQuery("select * from pickupdates");
|
||||
set.last();
|
||||
sb.append("\"collectionnumber\":\"" + set.getRow() + "\"");
|
||||
} catch (SQLException e) {
|
||||
Log.error("sql exception: " + e.getMessage());
|
||||
sb.append("\"status\" : \"error\"");
|
||||
@ -142,10 +183,12 @@ public class DataRequest extends PostRequest {
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date = new Date();
|
||||
date = new Date(date.getTime()+1 * 24 * 60 * 60 * 1000);
|
||||
|
||||
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() + "\"");
|
||||
set = jdcb.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '"+time+"' AND '2222-12-27'");
|
||||
set.last();
|
||||
sb.append("\"collectionnumber\":\"" + set.getRow() + "\"");
|
||||
} catch (SQLException e) {
|
||||
Log.error("sql exception: " + e.getMessage());
|
||||
sb.append("\"status\" : \"error\"");
|
||||
@ -161,9 +204,9 @@ public class DataRequest extends PostRequest {
|
||||
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() + "\"");
|
||||
set = jdcb.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '0000-12-27' AND '"+time+"'");
|
||||
set.last();
|
||||
sb.append("\"collectionnumber\":\"" + set.getRow() + "\"");
|
||||
} catch (SQLException e) {
|
||||
Log.error("sql exception: " + e.getMessage());
|
||||
sb.append("\"status\" : \"error\"");
|
||||
|
@ -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 {
|
||||
|
@ -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"
|
||||
|
@ -38,6 +38,7 @@ $(document).ready(function () {
|
||||
|
||||
|
||||
var citytable;
|
||||
var datetable;
|
||||
|
||||
function reloadtable() {
|
||||
$.post('/senddata/wastedata', 'action=getAllCities', function (data) {
|
||||
@ -108,14 +109,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);
|
||||
|
||||
//todo
|
||||
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>");
|
||||
}
|
||||
|
||||
$(".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");
|
||||
});
|
||||
}
|
||||
citytable = $("#table-pickupdates").DataTable({
|
||||
"order": [[ 3, "desc" ]]
|
||||
} );
|
||||
|
||||
//todo picupdates-tablebody
|
||||
},"json");
|
||||
}
|
||||
|
||||
@ -223,9 +273,31 @@ $(document).ready(function () {
|
||||
});
|
||||
});
|
||||
|
||||
$(".dropdown-item-wastetype").click(function (event) {
|
||||
$("#dropdown-type-data").click(function (event) {
|
||||
event.preventDefault();
|
||||
$("#dropdown-type-data").html($(this).html());
|
||||
|
||||
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());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
@ -253,6 +325,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",
|
||||
|
Loading…
Reference in New Issue
Block a user