GUI for Shopping Cart Analysis rewritten

This commit is contained in:
Karsten 2019-05-28 15:08:43 +02:00
parent 1b9e4884dc
commit f05c267efc
5 changed files with 44 additions and 11 deletions

View File

@ -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<Columns> 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<String>, List<String>> map = cart.getResult();
Map<List<String>, List<String>> result = new HashMap<>();
result = cart.getResult();
List<String> col1 = new ArrayList<>();
List<String> col2 = new ArrayList<>();
for(Map.Entry<List<String>, List<String>> entry : map.entrySet()){
for(Map.Entry<List<String>, List<String>> entry : result.entrySet()){
col1.add(entry.getKey().toString());
col2.add(entry.getValue().toString());
}

View File

@ -3,8 +3,6 @@
<!--Script für Diagramme-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.bundle.min.js" integrity="sha256-xKeoJ50pzbUGkpQxDYHD7o7hxe0LaOGeguUidbq6vis=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://unpkg.com/tabulator-tables@4.2.7/dist/js/tabulator.min.js"></script>
<!--Script für Materlialize-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>

View File

@ -12,7 +12,6 @@
media="screen,projection"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.css"
integrity="sha256-aa0xaJgmK/X74WM224KMQeNQC2xYKwlAt08oZqjeF0E=" crossorigin="anonymous"/>
<link href="https://unpkg.com/tabulator-tables@4.2.7/dist/css/tabulator.min.css" rel="stylesheet">
<meta charset="UTF-8">
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8">

View File

@ -70,8 +70,8 @@
<span class="card-title center">Warenkorbanalyse</span>
</div>
<div class="card-content">
<div id="shopping_cart_table">
</div>
<table id="shopping_cart_table">
</table>
</div>
</div>
</div>

View File

@ -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 = $("<thead>");
row.append("<tr>");
row.append("<th>Artikel</th>");
row.append("<th>Wird häufig zusammen gekauft mit</th>")
row.append("</tr>");
row.append("</thead>");
row.append("<tbody>");
for (x in shopping_cart_result){
row.append("<tr>");
row.append("<td>" + shopping_cart_result[x].col1 + "</td>");
row.append("<td>" + shopping_cart_result[x].col2 + "</td>");
row.append("</tr>");
}
row.append("</tbody>");
$("#shopping_cart_table").append(row);
}