From 36caaa214bd9f78c813cf1b65b72a051657d8609 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Fri, 15 Nov 2019 11:23:51 +0100 Subject: [PATCH] improved ui, added panel to add new city and zone parts of displaying cities fromdb --- .idea/misc.xml | 3 + resources/wwwroot/dashboard.html | 144 +++++++++++++---- resources/wwwroot/js/dashboard.js | 31 ++++ resources/wwwroot/js/index.js | 30 ++-- resources/wwwroot/settings.html | 146 ------------------ src/com/wasteinformationserver/main.java | 2 +- .../website/MainPage.java | 7 +- .../website/Webserver.java | 5 +- .../website/datarequests/DataRequest.java | 17 +- .../{ => login}/CheckLoginState.java | 2 +- .../{ => login}/LoginRequest.java | 4 +- .../datarequests/{ => login}/LoginState.java | 2 +- 12 files changed, 186 insertions(+), 207 deletions(-) delete mode 100644 resources/wwwroot/settings.html rename src/com/wasteinformationserver/website/datarequests/{ => login}/CheckLoginState.java (93%) rename src/com/wasteinformationserver/website/datarequests/{ => login}/LoginRequest.java (93%) rename src/com/wasteinformationserver/website/datarequests/{ => login}/LoginState.java (93%) diff --git a/.idea/misc.xml b/.idea/misc.xml index b7148e8..5a7f62a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,8 @@ + + + diff --git a/resources/wwwroot/dashboard.html b/resources/wwwroot/dashboard.html index 1a80b02..82ccbe6 100644 --- a/resources/wwwroot/dashboard.html +++ b/resources/wwwroot/dashboard.html @@ -10,6 +10,8 @@ + + @@ -206,13 +208,55 @@ +
+
+

+ + New City +

+ +
+
+
+ + + Please try to use no special + characters +
+
+ + + Please try to use no special + characters +
+ +
+ + +
+
+
+

- Create new Date + New Pick up date

-

General options:

-
- - -
-
- - - Please try to use no special - characters -
-
- - - Please try to use no special - characters -

Add Data:

+ + + + +
-
- - - - @@ -286,10 +312,55 @@ +
+
+
+

+ + Pick up locations +

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
CityZoneWaste Type
TridentInternet + Explorer 4.0 + Win 95+
TridentInternet + Explorer 5.0 + Win 95+
CityZoneWaste Type
+
+ +
@@ -358,5 +429,22 @@ src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"> + + + + + diff --git a/resources/wwwroot/js/dashboard.js b/resources/wwwroot/js/dashboard.js index c26fe80..5a2f8f2 100644 --- a/resources/wwwroot/js/dashboard.js +++ b/resources/wwwroot/js/dashboard.js @@ -10,7 +10,18 @@ $(document).ready(function () { } }, 'json'); + $.post('/senddata/wastedata', 'action=getAllCities', function (data) { + for (var i = 0; i < data.size; i++) { + $('#location-table-data').append("" + + "" + data[i].city + "" + + "" + data[i].zone + "" + + "" + data[i].wastetype + "" + + ""); + } + }, 'json'); + + //btn listeners $('#logoutbtn').click(function () { $.post('/senddata/checkloginstate', 'action=logout', function (data) { console.log(data); @@ -21,6 +32,26 @@ $(document).ready(function () { $('#dropdown-wastetype').html($(this).html()); }); + $('#btn-savecity').click(function () { + var cityname = $("#new_city_cityname").val(); + var zonename = $("#new_city_zonename").val(); + var wastetype = $("#dropdown-wastetype").html(); + console.log("storing: "+cityname + "--" + wastetype + "in db"); + + $.post('/senddata/wastedata', 'action=newCity&wastetype=' + wastetype +"&cityname="+cityname+"&wastezone="+zonename, function (data) { + console.log(data); + }, 'json'); + + //clear form data + var cityname = $("#new_city_cityname").val(""); + var zonename = $("#new_city_zonename").val(""); + var wastetype = $("#dropdown-wastetype").html("select waste type"); + + }); + + + + $('.btn-addtolist').click(function () { console.log("added new row to table"); $('#addtable-body').append("" + diff --git a/resources/wwwroot/js/index.js b/resources/wwwroot/js/index.js index 0ac8fb9..172423e 100644 --- a/resources/wwwroot/js/index.js +++ b/resources/wwwroot/js/index.js @@ -1,18 +1,18 @@ -$(document).ready(function() { - $('#loginbtn').click(function(e) { - e.preventDefault(); - console.log("clicked login button"); - var username = $("#userfield")[0].value; - var password = $("#passfield")[0].value; +$(document).ready(function () { + $('#loginbtn').click(function (e) { + e.preventDefault(); + console.log("clicked login button"); + var username = $("#userfield")[0].value; + var password = $("#passfield")[0].value; - $.post('/senddata/loginget','username='+username+'&password='+password,function(data){ + $.post('/senddata/loginget', 'username=' + username + '&password=' + password, function (data) { - console.log(data); - if (data.accept == true) { - console.log("successfully logged in!"); - document.cookie = "username="+username; - window.location = 'settings.html'; - } - },'json'); - }); + console.log(data); + if (data.accept == true) { + console.log("successfully logged in!"); + document.cookie = "username=" + username; + window.location = 'dashboard.html'; + } + }, 'json'); + }); }); diff --git a/resources/wwwroot/settings.html b/resources/wwwroot/settings.html deleted file mode 100644 index 5d95b1e..0000000 --- a/resources/wwwroot/settings.html +++ /dev/null @@ -1,146 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
- -
Add new Table
-
-
-
- - -

General options:

-
- - -
-
- - - Please try to use no special characters -
-
- - - Please try to use no special characters -
- -

Add Data:

-
-
- - -
- - - - - - - - -
- -

Your Data:

- - - - - - - - - - - -
Waste typeDateRegionZone
- -
- -
-
- -
-
- - - - diff --git a/src/com/wasteinformationserver/main.java b/src/com/wasteinformationserver/main.java index 2869882..35da912 100644 --- a/src/com/wasteinformationserver/main.java +++ b/src/com/wasteinformationserver/main.java @@ -21,7 +21,7 @@ public class main { })); Thread mythread = new Thread(() -> new Webserver().startserver()); - //mythread.start(); + mythread.start(); Log.message("thread started"); diff --git a/src/com/wasteinformationserver/website/MainPage.java b/src/com/wasteinformationserver/website/MainPage.java index e378331..7756d32 100644 --- a/src/com/wasteinformationserver/website/MainPage.java +++ b/src/com/wasteinformationserver/website/MainPage.java @@ -4,12 +4,9 @@ import com.sun.net.httpserver.Headers; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.wasteinformationserver.basicutils.Log; -import com.wasteinformationserver.website.datarequests.LoginState; +import com.wasteinformationserver.website.datarequests.login.LoginState; -import java.awt.*; import java.io.*; -import java.net.URI; -import java.net.URL; public class MainPage implements HttpHandler { @Override @@ -29,7 +26,7 @@ public class MainPage implements HttpHandler { Log.warning("user not logged in --> redirecting to login page"); sendPage("/index.html",t); } - }else { + }else { //only detect login state on html pages sendPage(path, t); } } diff --git a/src/com/wasteinformationserver/website/Webserver.java b/src/com/wasteinformationserver/website/Webserver.java index 25aa16a..60282c6 100644 --- a/src/com/wasteinformationserver/website/Webserver.java +++ b/src/com/wasteinformationserver/website/Webserver.java @@ -2,9 +2,9 @@ package com.wasteinformationserver.website; import com.sun.net.httpserver.HttpServer; import com.wasteinformationserver.basicutils.Log; -import com.wasteinformationserver.website.datarequests.CheckLoginState; +import com.wasteinformationserver.website.datarequests.login.CheckLoginState; import com.wasteinformationserver.website.datarequests.DataRequest; -import com.wasteinformationserver.website.datarequests.LoginRequest; +import com.wasteinformationserver.website.datarequests.login.LoginRequest; import com.wasteinformationserver.website.datarequests.RegisterRequest; import java.io.IOException; @@ -22,6 +22,7 @@ public class Webserver { } server.createContext("/", new MainPage()); + server.createContext("/senddata/loginget", new LoginRequest()); server.createContext("/senddata/registerpost",new RegisterRequest()); server.createContext("/senddata/checkloginstate",new CheckLoginState()); diff --git a/src/com/wasteinformationserver/website/datarequests/DataRequest.java b/src/com/wasteinformationserver/website/datarequests/DataRequest.java index 2ce4f20..daf8a9c 100644 --- a/src/com/wasteinformationserver/website/datarequests/DataRequest.java +++ b/src/com/wasteinformationserver/website/datarequests/DataRequest.java @@ -11,29 +11,32 @@ import java.util.HashMap; public class DataRequest extends PostRequest { @Override public String request(HashMap params) { - switch (params.get("action")){ - case "senddata": + switch (params.get("action")) { + case "newCity": Log.debug(params.toString()); // check if wastezone and wasteregion already exists JDCB jdcb = new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation"); - ResultSet set = jdcb.executeQuery("select * from cities where name='"+params.get("wasteregion")+"' AND wastetype='"+params.get("wastetype")+"' AND zone='"+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") + "'"); try { - if (set.getFetchSize() == 0){ + if (set.getFetchSize() == 0) { //doesnt exist System.out.println("doesnt exist"); - jdcb.executeUpdate("INSERT INTO `cities`(`userid`, `name`, `wastetype`, `zone`) VALUES (0,'"+params.get("wasteregion")+"','"+params.get("wastetype")+"','"+params.get("wastezone")+"'"); - }else { + 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"); } } catch (SQLException e) { e.printStackTrace(); } + break; + case "getAllCities": - // TODO: 11.10.19 store data in database + // TODO: 15.11.19 database call to get all data and store it as json. + break; } return ""; diff --git a/src/com/wasteinformationserver/website/datarequests/CheckLoginState.java b/src/com/wasteinformationserver/website/datarequests/login/CheckLoginState.java similarity index 93% rename from src/com/wasteinformationserver/website/datarequests/CheckLoginState.java rename to src/com/wasteinformationserver/website/datarequests/login/CheckLoginState.java index 655e458..3caeca8 100644 --- a/src/com/wasteinformationserver/website/datarequests/CheckLoginState.java +++ b/src/com/wasteinformationserver/website/datarequests/login/CheckLoginState.java @@ -1,4 +1,4 @@ -package com.wasteinformationserver.website.datarequests; +package com.wasteinformationserver.website.datarequests.login; import com.wasteinformationserver.basicutils.Log; import com.wasteinformationserver.website.basicrequest.PostRequest; diff --git a/src/com/wasteinformationserver/website/datarequests/LoginRequest.java b/src/com/wasteinformationserver/website/datarequests/login/LoginRequest.java similarity index 93% rename from src/com/wasteinformationserver/website/datarequests/LoginRequest.java rename to src/com/wasteinformationserver/website/datarequests/login/LoginRequest.java index d2d8ef5..83a2d63 100644 --- a/src/com/wasteinformationserver/website/datarequests/LoginRequest.java +++ b/src/com/wasteinformationserver/website/datarequests/login/LoginRequest.java @@ -1,4 +1,4 @@ -package com.wasteinformationserver.website.datarequests; +package com.wasteinformationserver.website.datarequests.login; import com.wasteinformationserver.basicutils.Log; import com.wasteinformationserver.db.JDCB; @@ -13,6 +13,8 @@ public class LoginRequest extends PostRequest { @Override public String request(HashMap params) { + Log.message("new login request"); + String password = params.get("password"); String username = params.get("username"); diff --git a/src/com/wasteinformationserver/website/datarequests/LoginState.java b/src/com/wasteinformationserver/website/datarequests/login/LoginState.java similarity index 93% rename from src/com/wasteinformationserver/website/datarequests/LoginState.java rename to src/com/wasteinformationserver/website/datarequests/login/LoginState.java index 6bf0dd2..2e7b4da 100644 --- a/src/com/wasteinformationserver/website/datarequests/LoginState.java +++ b/src/com/wasteinformationserver/website/datarequests/login/LoginState.java @@ -1,4 +1,4 @@ -package com.wasteinformationserver.website.datarequests; +package com.wasteinformationserver.website.datarequests.login; public class LoginState { private LoginState() {}