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