* add city animation
* delete city button * reload table data
This commit is contained in:
parent
e292df8bb8
commit
07a4035195
9
.idea/libraries/gson_2_8_6.xml
Normal file
9
.idea/libraries/gson_2_8_6.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="gson-2.8.6">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/gson-2.8.6.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
9
.idea/libraries/gson_2_8_6_sources.xml
Normal file
9
.idea/libraries/gson_2_8_6_sources.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="gson-2.8.6-sources">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/gson-2.8.6-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -1,9 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectPlainTextFileTypeManager">
|
||||
<file url="file://$PROJECT_DIR$/resources/wwwroot/settings.html" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="13" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -12,7 +12,6 @@
|
||||
<orderEntry type="library" name="mysql-connector-java-5.1.44-bin" level="project" />
|
||||
<orderEntry type="library" name="mysql-connector-java-5.1.44-bin" level="project" />
|
||||
<orderEntry type="library" name="org.eclipse.paho.client.mqttv3-1.2.1" level="project" />
|
||||
<orderEntry type="library" name="gson-2.8.6-javadoc" level="project" />
|
||||
<orderEntry type="library" name="gson-2.8.6" level="project" />
|
||||
<orderEntry type="library" name="gson-2.8.6-sources" level="project" />
|
||||
</component>
|
||||
|
BIN
lib/gson-2.8.6-sources.jar
Normal file
BIN
lib/gson-2.8.6-sources.jar
Normal file
Binary file not shown.
BIN
lib/gson-2.8.6.jar
Normal file
BIN
lib/gson-2.8.6.jar
Normal file
Binary file not shown.
@ -332,6 +332,7 @@
|
||||
<th>City</th>
|
||||
<th>Zone</th>
|
||||
<th>Waste Type</th>
|
||||
<th>X</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="location-table-data">
|
||||
@ -341,6 +342,7 @@
|
||||
<th>City</th>
|
||||
<th>Zone</th>
|
||||
<th>Waste Type</th>
|
||||
<th>X</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
@ -419,5 +421,7 @@
|
||||
<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>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,5 +1,4 @@
|
||||
$(document).ready(function () {
|
||||
// TODO: check login state
|
||||
console.log("page loaded");
|
||||
$.post('/senddata/checkloginstate', 'action=getloginstate', function (data) {
|
||||
console.log(data);
|
||||
@ -10,27 +9,45 @@ $(document).ready(function () {
|
||||
}
|
||||
}, 'json');
|
||||
|
||||
var table;
|
||||
|
||||
function reloadtable() {
|
||||
$.post('/senddata/wastedata', 'action=getAllCities', function (data) {
|
||||
console.log(data);
|
||||
$('#location-table-data').html("");
|
||||
for (var i = 0; i < data.data.length; i++) {
|
||||
$('#location-table-data').append("<tr>" +
|
||||
"<td>" + data.data[i].cityname + "</td>" +
|
||||
"<td>" + data.data[i].zone + "</td>" +
|
||||
"<td>" + data.data[i].wastetype + "</td>" +
|
||||
"<td>" + "<button dataid='" + data.data[i].id + "' type='button' class='delbtn btn btn-danger'>X</button>" + "</td>" +
|
||||
"</tr>");
|
||||
$(".delbtn").click(function (event) {
|
||||
var id = event.target.getAttribute("dataid");
|
||||
console.log("clicked btn data " + id);
|
||||
$.post('/senddata/wastedata', 'action=deletecity&id=' + id, function (data) {
|
||||
console.log(data);
|
||||
reloadtable();
|
||||
});
|
||||
});
|
||||
}
|
||||
//todo entweda 1 od 2
|
||||
$("#example2").DataTable();
|
||||
$('#example1').DataTable({
|
||||
"paging": true,
|
||||
"lengthChange": false,
|
||||
"searching": false,
|
||||
"ordering": true,
|
||||
"info": true,
|
||||
"autoWidth": false,
|
||||
});
|
||||
// $("#example2").reload();
|
||||
table = $("#example2").DataTable();
|
||||
|
||||
// $('#example1').DataTable({
|
||||
// "paging": true,
|
||||
// "lengthChange": false,
|
||||
// "searching": false,
|
||||
// "ordering": true,
|
||||
// "info": true,
|
||||
// "autoWidth": false,
|
||||
// });
|
||||
|
||||
}, 'json');
|
||||
}
|
||||
|
||||
reloadtable();
|
||||
|
||||
|
||||
//btn listeners
|
||||
@ -52,12 +69,39 @@ $(document).ready(function () {
|
||||
|
||||
$.post('/senddata/wastedata', 'action=newCity&wastetype=' + wastetype + "&cityname=" + cityname + "&wastezone=" + zonename, function (data) {
|
||||
console.log(data);
|
||||
if (data.status == "inserted") {
|
||||
Swal.fire({
|
||||
type: "success",
|
||||
title: 'Successfully created city!',
|
||||
html: 'This alert closes automatically.',
|
||||
timer: 1000,
|
||||
}).then((result) => {
|
||||
console.log('Popup closed. ')
|
||||
|
||||
});
|
||||
table.destroy();
|
||||
reloadtable();
|
||||
} else if (data.status == "exists") {
|
||||
Swal.fire({
|
||||
type: "warning",
|
||||
title: 'Name already exists in db',
|
||||
html: 'Close popup.',
|
||||
}).then((result) => {
|
||||
console.log('Popup closed. ')
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}, 'json');
|
||||
|
||||
//clear form data
|
||||
var cityname = $("#new_city_cityname").val("");
|
||||
var zonename = $("#new_city_zonename").val("");
|
||||
var wastetype = $("#dropdown-wastetype").html("select waste type");
|
||||
$("#new_city_cityname").val("");
|
||||
$("#new_city_zonename").val("");
|
||||
$("#dropdown-wastetype").html("select waste type");
|
||||
|
||||
|
||||
//todo reload table.
|
||||
|
||||
});
|
||||
|
||||
|
@ -25,8 +25,13 @@ public class main {
|
||||
|
||||
Log.message("thread started");
|
||||
|
||||
try{
|
||||
mqtt m = new mqtt();
|
||||
m.notifymessage();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,16 @@
|
||||
// Dear programmer:
|
||||
// When I wrote this code, only god and
|
||||
// I knew how it worked.
|
||||
// Now, only god knows it!
|
||||
//
|
||||
// Therefore, if you are trying to optimize
|
||||
// this routine and it fails (most surely),
|
||||
// please increase this counter as a
|
||||
// warning for the next person:
|
||||
//
|
||||
// total hours wasted here = 254
|
||||
//
|
||||
|
||||
package com.wasteinformationserver.website;
|
||||
|
||||
import com.sun.net.httpserver.Headers;
|
||||
|
@ -21,19 +21,38 @@ public class DataRequest extends PostRequest {
|
||||
|
||||
JDCB jdcb = new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation");
|
||||
|
||||
ResultSet set = jdcb.executeQuery("select * from cities where name='" + params.get("cityname") + "' AND wastetype='" + params.get("wastetype") + "' AND zone='" + 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") + "'");
|
||||
int size = 0;
|
||||
try {
|
||||
if (set.getFetchSize() == 0) {
|
||||
//doesnt exist
|
||||
System.out.println("doesnt exist");
|
||||
jdcb.executeUpdate("INSERT INTO `cities`(`userid`, `name`, `wastetype`, `zone`) VALUES ('0','" + params.get("cityname") + "','" + params.get("wastetype") + "','" + params.get("wastezone") + "');");
|
||||
} else {
|
||||
//already exists
|
||||
System.out.println("already exists");
|
||||
if (set != null) {
|
||||
set.last(); // moves cursor to the last row
|
||||
size = set.getRow(); // get row id
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (size == 0) {
|
||||
//doesnt exist
|
||||
System.out.println("doesnt exist");
|
||||
int status = jdcb.executeUpdate("INSERT INTO `cities`(`userid`, `name`, `wastetype`, `zone`) VALUES ('0','" + params.get("cityname") + "','" + params.get("wastetype") + "','" + params.get("wastezone") + "');");
|
||||
System.out.println(status);
|
||||
if (status == 1) {
|
||||
result = "{\"status\" : \"inserted\"}";
|
||||
} else {
|
||||
result = "{\"status\" : \"inserterror\"}";
|
||||
}
|
||||
|
||||
} else if (size > 1) {
|
||||
Log.warning("more than one entry in db!!!");
|
||||
result = "{\"status\" : \"exists\"}";
|
||||
} else {
|
||||
//already exists
|
||||
System.out.println("already exists");
|
||||
result = "{\"status\" : \"exists\"}";
|
||||
}
|
||||
|
||||
Log.debug(result);
|
||||
break;
|
||||
case "getAllCities":
|
||||
|
||||
@ -50,6 +69,7 @@ public class DataRequest extends PostRequest {
|
||||
while (sett.next()) {
|
||||
builder.append("{\"cityname\":\"" + sett.getString("name") + "\"");
|
||||
builder.append(",\"wastetype\":\"" + sett.getString("wastetype") + "\"");
|
||||
builder.append(",\"id\":\"" + sett.getString("id") + "\"");
|
||||
builder.append(",\"zone\":\"" + sett.getString("zone") + "\"}");
|
||||
if (!sett.isLast()) {
|
||||
builder.append(",");
|
||||
@ -63,6 +83,16 @@ public class DataRequest extends PostRequest {
|
||||
builder.append("]}");
|
||||
result = builder.toString();
|
||||
Log.debug(result);
|
||||
break;
|
||||
case "deletecity":
|
||||
//DELETE FROM `cities` WHERE `id`=0
|
||||
|
||||
JDCB jdcbcc = new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation");
|
||||
|
||||
Log.debug(params.get("id"));
|
||||
int status= jdcbcc.executeUpdate("DELETE FROM `cities` WHERE `id`='" + params.get("id")+"'");
|
||||
Log.debug(status);
|
||||
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
|
@ -19,7 +19,7 @@ public class LoginRequest extends PostRequest {
|
||||
String username = params.get("username");
|
||||
|
||||
ResultSet s = new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation").executeQuery("select * from user where username ='" + username + "'");
|
||||
|
||||
Log.debug("successfully logged in to db");
|
||||
String response = "{\"accept\": false}";
|
||||
try {
|
||||
s.last();
|
||||
|
Loading…
Reference in New Issue
Block a user