parent
cf7500f472
commit
d237b78ba1
|
@ -9,18 +9,11 @@ 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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* changes data from shopping times diagram into a readable format for chart.js
|
||||
|
@ -48,15 +41,16 @@ public class ShoppingTimesDiagram extends HttpServlet {
|
|||
|
||||
Gson gson = new Gson();
|
||||
|
||||
SavedFile file = Data.getFiles().peek();
|
||||
if (file == null) {
|
||||
|
||||
if (req.getParameter("id") == null) {
|
||||
result.put("labels", definedOrder);
|
||||
out.print(gson.toJson(result));
|
||||
return;
|
||||
}
|
||||
UUID uuid = UUID.fromString(req.getParameter("id"));
|
||||
File file = Data.get(uuid);
|
||||
|
||||
assert file.getUuid() != null;
|
||||
ShoppingTimes shoppingTimes = new ShoppingTimes(Data.get(file.getUuid()));
|
||||
ShoppingTimes shoppingTimes = new ShoppingTimes(file);
|
||||
Map<DayHour, Integer> map = shoppingTimes.getResult();
|
||||
|
||||
Set<String> days = new TreeSet<>();
|
||||
|
|
|
@ -8,15 +8,11 @@ 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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* changes data from week overview into readable format for chart.js
|
||||
|
@ -43,16 +39,19 @@ public class WeekOverviewDiagram extends HttpServlet {
|
|||
|
||||
Gson gson = new Gson();
|
||||
|
||||
SavedFile file = Data.getFiles().peek();
|
||||
if (file == null) {
|
||||
|
||||
if (req.getParameter("id") == null) {
|
||||
result.put("labels", definedOrder);
|
||||
result.put("count", new ArrayList<>());
|
||||
result.put("revenue", new ArrayList<>());
|
||||
out.print(gson.toJson(result));
|
||||
return;
|
||||
}
|
||||
assert file.getUuid() != null;
|
||||
WeekOverview overview = new WeekOverview(Data.get(file.getUuid()));
|
||||
|
||||
UUID uuid = UUID.fromString(req.getParameter("id"));
|
||||
File file = Data.get(uuid);
|
||||
|
||||
WeekOverview overview = new WeekOverview(file);
|
||||
|
||||
List<String> count = new ArrayList<>();
|
||||
List<String> revenue = new ArrayList<>();
|
||||
|
|
|
@ -7,7 +7,11 @@
|
|||
<!--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>
|
||||
<script type="text/javascript" src="js/materialize_components.js"></script>
|
||||
<script>
|
||||
M.AutoInit();
|
||||
</script>
|
||||
|
||||
<script src="js/cache.js"></script>
|
||||
|
||||
<script src="js/week_overview.js"></script>
|
||||
<script src="js/shopping_times.js"></script>
|
||||
|
|
|
@ -79,15 +79,9 @@
|
|||
</li>
|
||||
<li>
|
||||
<div class="input-field container">
|
||||
<label>Datensatzauswahl</label>
|
||||
<label for="dataset">Datensatzauswahl</label>
|
||||
<br>
|
||||
<select>
|
||||
<option value="0">aktuell</option>
|
||||
<option value="1">Datensatz 1</option>
|
||||
<option value="2">Datensatz 2</option>
|
||||
<option value="3">Datensatz 3</option>
|
||||
<option value="4">Datensatz 4</option>
|
||||
<option value="5">Datensatz 5</option>
|
||||
<select id="dataset" onChange="updateCache()">
|
||||
</select>
|
||||
<br>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
$(document).ready(function () {
|
||||
let dataset = $('#dataset');
|
||||
$.ajax({
|
||||
url: 'files',
|
||||
dataType: 'json'
|
||||
}).done(function (results) {
|
||||
dataset.empty();
|
||||
for (const result of results) {
|
||||
dataset.append($("<option></option>")
|
||||
.attr("value", result.uuid)
|
||||
.text(result.name));
|
||||
}
|
||||
dataset.formSelect();
|
||||
});
|
||||
updateWeekOverviewChart();
|
||||
updateShoppingTimesChart();
|
||||
});
|
||||
|
||||
function updateCache() {
|
||||
let selected = $('#dataset :selected');
|
||||
|
||||
if (selected.index() !== -1) {
|
||||
updateWeekOverviewChart(selected.val());
|
||||
updateShoppingTimesChart(selected.val());
|
||||
}
|
||||
}
|
||||
|
||||
function request(url, id) {
|
||||
return new Promise(((resolve, reject) => {
|
||||
if (typeof id !== 'undefined') {
|
||||
requestInternal(url + '?id=' + id).then(function (data) {
|
||||
resolve(data);
|
||||
});
|
||||
} else {
|
||||
requestInternal(url).then(function (data) {
|
||||
resolve(data);
|
||||
});
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
function requestInternal(url) {
|
||||
return new Promise(((resolve, reject) => {
|
||||
$.ajax({
|
||||
url: url,
|
||||
dataType: 'json'
|
||||
}).done(function (results) {
|
||||
resolve(results);
|
||||
});
|
||||
}));
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
$(".dropdown-trigger").dropdown();
|
||||
$('.tabs').tabs();
|
||||
$(document).ready(function(){
|
||||
$('.sidenav').sidenav();
|
||||
});
|
||||
$(document).ready(function(){
|
||||
$('select').formSelect();
|
||||
});
|
||||
$(document).ready(function(){
|
||||
$('.collapsible').collapsible();
|
||||
});
|
||||
$(document).ready(function() {
|
||||
M.updateTextFields();
|
||||
});
|
|
@ -52,13 +52,18 @@ let shopping_chart = new Chart(document.getElementById("shopping_times_chart"),
|
|||
}
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: 'shopping_times',
|
||||
dataType: 'json'
|
||||
}).done(function (results) {
|
||||
shopping_result = results;
|
||||
updateDays();
|
||||
});
|
||||
function updateShoppingTimesChart(id) {
|
||||
if(typeof id !== 'undefined') {
|
||||
request('shopping_times', id).then(function (data) {
|
||||
shopping_result = data;
|
||||
updateDays();
|
||||
});
|
||||
}else request('shopping_times').then(function(data) {
|
||||
shopping_result = data;
|
||||
updateDays();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function updateDays() {
|
||||
if(typeof shopping_result["Montag"] !== 'undefined') {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
let week_result;
|
||||
|
||||
let week_overview = new Chart(document.getElementById("overview_chart"), {
|
||||
type: 'line',
|
||||
data: {
|
||||
|
@ -52,14 +54,23 @@ let week_overview = new Chart(document.getElementById("overview_chart"), {
|
|||
}
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: 'week_overview',
|
||||
dataType: 'json'
|
||||
}).done(function (results) {
|
||||
week_overview.data.labels = results.labels;
|
||||
week_overview.data.datasets[0].data = results.count;
|
||||
week_overview.data.datasets[1].data = results.revenue;
|
||||
function updateWeekOverviewChart(id) {
|
||||
|
||||
if(typeof id !== 'undefined') {
|
||||
request('week_overview', id).then(function (data) {
|
||||
week_result = data;
|
||||
updateWeekOverview();
|
||||
});
|
||||
}else request('week_overview').then(function(data) {
|
||||
week_result = data;
|
||||
updateWeekOverview();
|
||||
});
|
||||
}
|
||||
function updateWeekOverview() {
|
||||
|
||||
week_overview.data.labels = week_result.labels;
|
||||
week_overview.data.datasets[0].data = week_result.count;
|
||||
week_overview.data.datasets[1].data = week_result.revenue;
|
||||
week_overview.update();
|
||||
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue