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(); + }); +} +