From 1b9e4884dcddca41ed5d7dd2f1abc60a8e890f66 Mon Sep 17 00:00:00 2001 From: Karsten Date: Sun, 26 May 2019 20:35:50 +0200 Subject: [PATCH 1/3] GUI for Shopping Cart Analysis done --- .../java/de/hsel/spm/baudas/web/Columns.java | 11 ++++ .../spm/baudas/web/ShoppingCartDiagram.java | 65 +++++++++++++++++++ src/main/webapp/footer.jsp | 2 + src/main/webapp/header.jsp | 1 + src/main/webapp/index.jsp | 11 ++-- src/main/webapp/js/cache.js | 1 + src/main/webapp/js/shopping_cart.js | 19 ++++++ 7 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 src/main/java/de/hsel/spm/baudas/web/Columns.java create mode 100644 src/main/java/de/hsel/spm/baudas/web/ShoppingCartDiagram.java create mode 100644 src/main/webapp/js/shopping_cart.js diff --git a/src/main/java/de/hsel/spm/baudas/web/Columns.java b/src/main/java/de/hsel/spm/baudas/web/Columns.java new file mode 100644 index 0000000..9b00650 --- /dev/null +++ b/src/main/java/de/hsel/spm/baudas/web/Columns.java @@ -0,0 +1,11 @@ +package de.hsel.spm.baudas.web; + +public class Columns { + private String col1; //NOPMD + private String col2; //NOPMD + + public Columns(String col1, String col2){ + this.col1 = col1; + this.col2 = col2; + } +} diff --git a/src/main/java/de/hsel/spm/baudas/web/ShoppingCartDiagram.java b/src/main/java/de/hsel/spm/baudas/web/ShoppingCartDiagram.java new file mode 100644 index 0000000..33f8f8c --- /dev/null +++ b/src/main/java/de/hsel/spm/baudas/web/ShoppingCartDiagram.java @@ -0,0 +1,65 @@ +package de.hsel.spm.baudas.web; + +import com.google.gson.Gson; +import de.hsel.spm.baudas.analysis.ShoppingCart; +import org.jetbrains.annotations.NotNull; + +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; +import java.util.*; + +/** + * Changes data to readable format for Tabulator + * + * @author Karsten Eden + * @version 0.1 + * @since 0.1 + */ +@WebServlet("/shopping_cart") +public class ShoppingCartDiagram extends HttpServlet { + + private static final long serialVersionUID = 5026732432605473505L; + + protected void doGet(@NotNull HttpServletRequest req, @NotNull HttpServletResponse resp) throws IOException { + req.setCharacterEncoding(StandardCharsets.UTF_8.name()); + resp.setCharacterEncoding(StandardCharsets.UTF_8.name()); + resp.setContentType("application/json"); + PrintWriter out = resp.getWriter(); + + Gson gson = new Gson(); + + List colList = new ArrayList<>(); + + if (req.getParameter("id") == null) { + out.print(gson.toJson(colList)); + return; + } + + UUID uuid = UUID.fromString(req.getParameter("id")); + File file = Data.get(uuid); + + ShoppingCart cart = new ShoppingCart(file); + + Map, List> map = cart.getResult(); + + List col1 = new ArrayList<>(); + List col2 = new ArrayList<>(); + + for(Map.Entry, List> entry : map.entrySet()){ + col1.add(entry.getKey().toString()); + col2.add(entry.getValue().toString()); + } + + for(int i = 0; i < col1.size(); i++ ){ + colList.add(new Columns(col1.get(i).replaceAll("\\[", "").replaceAll("\\]", ""), col2.get(i).replaceAll("\\[", "").replaceAll("\\]", ""))); + } + + out.print(gson.toJson(colList)); + } +} diff --git a/src/main/webapp/footer.jsp b/src/main/webapp/footer.jsp index 5e91340..c00e169 100644 --- a/src/main/webapp/footer.jsp +++ b/src/main/webapp/footer.jsp @@ -3,6 +3,7 @@ + @@ -16,6 +17,7 @@ + <%----%> diff --git a/src/main/webapp/header.jsp b/src/main/webapp/header.jsp index 5cd9784..9daab49 100644 --- a/src/main/webapp/header.jsp +++ b/src/main/webapp/header.jsp @@ -12,6 +12,7 @@ media="screen,projection"/> + diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index 6879491..2365169 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -64,14 +64,13 @@ -
+
+
+ Warenkorbanalyse +
-
- Warenkorbanalyse -
-
-

Coming Soon

+
diff --git a/src/main/webapp/js/cache.js b/src/main/webapp/js/cache.js index 8876e59..16e1c2e 100644 --- a/src/main/webapp/js/cache.js +++ b/src/main/webapp/js/cache.js @@ -38,6 +38,7 @@ function updateAll(uuid) { updateWeekOverviewChart(uuid); updateShoppingTimesChart(uuid); updateTopFlopChart(uuid); + updateShoppingCartTable(uuid); //add new charts here. } diff --git a/src/main/webapp/js/shopping_cart.js b/src/main/webapp/js/shopping_cart.js new file mode 100644 index 0000000..1ea2d35 --- /dev/null +++ b/src/main/webapp/js/shopping_cart.js @@ -0,0 +1,19 @@ +let table = new Tabulator("#shopping_cart_table", { + layout:"fitColumns", + columns:[ + {title:"Produkte", field:"col1", headerSort:false}, + {title:"zusammen mit", field:"col2", headerSort:false}, + ], +}); + + +function updateShoppingCartTable(id) { + if (typeof id !== 'undefined') { + request('shopping_cart', id).then(function () { + table.setData("/bauDas/shopping_cart?id="+id); + }); + } else request('shopping_cart').then(function () { + table.setData(); + }); +} + From f05c267efc47677b3ca169f74a6edd1ba3ea03a9 Mon Sep 17 00:00:00 2001 From: Karsten Date: Tue, 28 May 2019 15:08:43 +0200 Subject: [PATCH 2/3] GUI for Shopping Cart Analysis rewritten --- .../spm/baudas/web/ShoppingCartDiagram.java | 9 ++--- src/main/webapp/footer.jsp | 2 - src/main/webapp/header.jsp | 1 - src/main/webapp/index.jsp | 4 +- src/main/webapp/js/shopping_cart.js | 39 ++++++++++++++++++- 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/hsel/spm/baudas/web/ShoppingCartDiagram.java b/src/main/java/de/hsel/spm/baudas/web/ShoppingCartDiagram.java index 33f8f8c..9e62281 100644 --- a/src/main/java/de/hsel/spm/baudas/web/ShoppingCartDiagram.java +++ b/src/main/java/de/hsel/spm/baudas/web/ShoppingCartDiagram.java @@ -15,7 +15,7 @@ import java.nio.charset.StandardCharsets; import java.util.*; /** - * Changes data to readable format for Tabulator + * Changes data to readable format for table * * @author Karsten Eden * @version 0.1 @@ -33,7 +33,6 @@ public class ShoppingCartDiagram extends HttpServlet { PrintWriter out = resp.getWriter(); Gson gson = new Gson(); - List colList = new ArrayList<>(); if (req.getParameter("id") == null) { @@ -45,13 +44,13 @@ public class ShoppingCartDiagram extends HttpServlet { File file = Data.get(uuid); ShoppingCart cart = new ShoppingCart(file); - - Map, List> map = cart.getResult(); + Map, List> result = new HashMap<>(); + result = cart.getResult(); List col1 = new ArrayList<>(); List col2 = new ArrayList<>(); - for(Map.Entry, List> entry : map.entrySet()){ + for(Map.Entry, List> entry : result.entrySet()){ col1.add(entry.getKey().toString()); col2.add(entry.getValue().toString()); } diff --git a/src/main/webapp/footer.jsp b/src/main/webapp/footer.jsp index c00e169..d9ff19f 100644 --- a/src/main/webapp/footer.jsp +++ b/src/main/webapp/footer.jsp @@ -3,8 +3,6 @@ - - diff --git a/src/main/webapp/header.jsp b/src/main/webapp/header.jsp index 9daab49..5cd9784 100644 --- a/src/main/webapp/header.jsp +++ b/src/main/webapp/header.jsp @@ -12,7 +12,6 @@ media="screen,projection"/> - diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index 2365169..2f6c639 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -70,8 +70,8 @@ Warenkorbanalyse
-
-
+ +
diff --git a/src/main/webapp/js/shopping_cart.js b/src/main/webapp/js/shopping_cart.js index 1ea2d35..0365594 100644 --- a/src/main/webapp/js/shopping_cart.js +++ b/src/main/webapp/js/shopping_cart.js @@ -1,4 +1,4 @@ -let table = new Tabulator("#shopping_cart_table", { +/*let table = new Tabulator("#shopping_cart_table", { layout:"fitColumns", columns:[ {title:"Produkte", field:"col1", headerSort:false}, @@ -15,5 +15,42 @@ function updateShoppingCartTable(id) { } else request('shopping_cart').then(function () { table.setData(); }); +}*/ + +let shopping_cart_result; + +function updateShoppingCartTable(id) { + if(typeof id !== 'undefined') { + request('shopping_cart', id).then(function (data) { + shopping_cart_result = data; + drawShoppingCartTable(); + }); + }else request('shopping_cart_result').then(function(data) { + shopping_cart_result = data; + drawShoppingCartTable(); + }); +} + +function drawShoppingCartTable(){ + let table = document.getElementById("shopping_cart_table"); + while(table.hasChildNodes()){ + table.removeChild(table.firstChild); + } + + let row = $(""); + row.append(""); + row.append("Artikel"); + row.append("Wird häufig zusammen gekauft mit") + row.append(""); + row.append(""); + row.append(""); + for (x in shopping_cart_result){ + row.append(""); + row.append("" + shopping_cart_result[x].col1 + ""); + row.append("" + shopping_cart_result[x].col2 + ""); + row.append(""); + } + row.append(""); + $("#shopping_cart_table").append(row); } From aa0a170ef6dcaa86142e4bdef7f9a125395105ed Mon Sep 17 00:00:00 2001 From: Karsten Date: Tue, 28 May 2019 15:10:43 +0200 Subject: [PATCH 3/3] Unused Code removed --- src/main/webapp/js/shopping_cart.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/main/webapp/js/shopping_cart.js b/src/main/webapp/js/shopping_cart.js index 0365594..8edb9c5 100644 --- a/src/main/webapp/js/shopping_cart.js +++ b/src/main/webapp/js/shopping_cart.js @@ -1,22 +1,3 @@ -/*let table = new Tabulator("#shopping_cart_table", { - layout:"fitColumns", - columns:[ - {title:"Produkte", field:"col1", headerSort:false}, - {title:"zusammen mit", field:"col2", headerSort:false}, - ], -}); - - -function updateShoppingCartTable(id) { - if (typeof id !== 'undefined') { - request('shopping_cart', id).then(function () { - table.setData("/bauDas/shopping_cart?id="+id); - }); - } else request('shopping_cart').then(function () { - table.setData(); - }); -}*/ - let shopping_cart_result; function updateShoppingCartTable(id) {