+ documentation
Signed-off-by: Johannes Theiner <j.theiner@live.de> #SPM-28: add work 1h documentation
This commit is contained in:
parent
d237b78ba1
commit
e67c305322
|
@ -34,7 +34,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="center">
|
<div class="center">
|
||||||
<div class="input-field col s12">
|
<div class="input-field col s12">
|
||||||
<select id="day" onchange="updateDays()">
|
<select id="day" onchange="changeDay()">
|
||||||
<option value="0">Montag</option>
|
<option value="0">Montag</option>
|
||||||
<option value="1">Dienstag</option>
|
<option value="1">Dienstag</option>
|
||||||
<option value="2">Mittwoch</option>
|
<option value="2">Mittwoch</option>
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
let dataset = $('#dataset');
|
let dataset = $('#dataset');
|
||||||
$.ajax({
|
request('files').then(results => {
|
||||||
url: 'files',
|
|
||||||
dataType: 'json'
|
|
||||||
}).done(function (results) {
|
|
||||||
dataset.empty();
|
dataset.empty();
|
||||||
for (const result of results) {
|
for (const result of results) {
|
||||||
dataset.append($("<option></option>")
|
dataset.append($("<option></option>")
|
||||||
|
@ -16,15 +13,24 @@ $(document).ready(function () {
|
||||||
updateShoppingTimesChart();
|
updateShoppingTimesChart();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update all charts with correct values for dataset
|
||||||
|
*/
|
||||||
function updateCache() {
|
function updateCache() {
|
||||||
let selected = $('#dataset :selected');
|
let selected = $('#dataset :selected');
|
||||||
|
|
||||||
if (selected.index() !== -1) {
|
if (selected.index() !== -1) {
|
||||||
updateWeekOverviewChart(selected.val());
|
updateWeekOverviewChart(selected.val());
|
||||||
updateShoppingTimesChart(selected.val());
|
updateShoppingTimesChart(selected.val());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* request json data
|
||||||
|
* @param url base url
|
||||||
|
* @param id dataset id
|
||||||
|
* @returns {Promise<result>}
|
||||||
|
*/
|
||||||
function request(url, id) {
|
function request(url, id) {
|
||||||
return new Promise(((resolve, reject) => {
|
return new Promise(((resolve, reject) => {
|
||||||
if (typeof id !== 'undefined') {
|
if (typeof id !== 'undefined') {
|
||||||
|
@ -36,10 +42,14 @@ function request(url, id) {
|
||||||
resolve(data);
|
resolve(data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* only for use inside this file, javascript has no better way
|
||||||
|
* @param url url
|
||||||
|
* @returns {Promise<result>}
|
||||||
|
*/
|
||||||
function requestInternal(url) {
|
function requestInternal(url) {
|
||||||
return new Promise(((resolve, reject) => {
|
return new Promise(((resolve, reject) => {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
|
|
@ -56,16 +56,15 @@ function updateShoppingTimesChart(id) {
|
||||||
if(typeof id !== 'undefined') {
|
if(typeof id !== 'undefined') {
|
||||||
request('shopping_times', id).then(function (data) {
|
request('shopping_times', id).then(function (data) {
|
||||||
shopping_result = data;
|
shopping_result = data;
|
||||||
updateDays();
|
changeDay();
|
||||||
});
|
});
|
||||||
}else request('shopping_times').then(function(data) {
|
}else request('shopping_times').then(function(data) {
|
||||||
shopping_result = data;
|
shopping_result = data;
|
||||||
updateDays();
|
changeDay();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function changeDay() {
|
||||||
function updateDays() {
|
|
||||||
if(typeof shopping_result["Montag"] !== 'undefined') {
|
if(typeof shopping_result["Montag"] !== 'undefined') {
|
||||||
let e = document.getElementById("day");
|
let e = document.getElementById("day");
|
||||||
let value = e.options[e.selectedIndex].text;
|
let value = e.options[e.selectedIndex].text;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
let week_result;
|
let week_result;
|
||||||
|
|
||||||
let week_overview = new Chart(document.getElementById("overview_chart"), {
|
let week_overview = new Chart($("#overview_chart"), {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: {
|
data: {
|
||||||
labels: [0, 0, 0, 0, 0],
|
labels: [0, 0, 0, 0, 0],
|
||||||
|
@ -55,19 +55,18 @@ let week_overview = new Chart(document.getElementById("overview_chart"), {
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateWeekOverviewChart(id) {
|
function updateWeekOverviewChart(id) {
|
||||||
|
if (typeof id !== 'undefined') {
|
||||||
if(typeof id !== 'undefined') {
|
|
||||||
request('week_overview', id).then(function (data) {
|
request('week_overview', id).then(function (data) {
|
||||||
week_result = data;
|
week_result = data;
|
||||||
updateWeekOverview();
|
updateWeekOverview();
|
||||||
});
|
});
|
||||||
}else request('week_overview').then(function(data) {
|
} else request('week_overview').then(function (data) {
|
||||||
week_result = data;
|
week_result = data;
|
||||||
updateWeekOverview();
|
updateWeekOverview();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function updateWeekOverview() {
|
|
||||||
|
|
||||||
|
function updateWeekOverview() {
|
||||||
week_overview.data.labels = week_result.labels;
|
week_overview.data.labels = week_result.labels;
|
||||||
week_overview.data.datasets[0].data = week_result.count;
|
week_overview.data.datasets[0].data = week_result.count;
|
||||||
week_overview.data.datasets[1].data = week_result.revenue;
|
week_overview.data.datasets[1].data = week_result.revenue;
|
||||||
|
|
Loading…
Reference in New Issue