From e67c30532292d2d8cfe171a4e3575b47ef0908d8 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Wed, 15 May 2019 20:41:09 +0200 Subject: [PATCH] + documentation Signed-off-by: Johannes Theiner #SPM-28: add work 1h documentation --- src/main/webapp/index.jsp | 2 +- src/main/webapp/js/cache.js | 22 ++++++++++++++++------ src/main/webapp/js/shopping_times.js | 7 +++---- src/main/webapp/js/week_overview.js | 9 ++++----- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index c0ccd3c..8cf6ee5 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -34,7 +34,7 @@
- diff --git a/src/main/webapp/js/cache.js b/src/main/webapp/js/cache.js index 23d1187..6f5f803 100644 --- a/src/main/webapp/js/cache.js +++ b/src/main/webapp/js/cache.js @@ -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($("") @@ -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} + */ 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} + */ function requestInternal(url) { return new Promise(((resolve, reject) => { $.ajax({ diff --git a/src/main/webapp/js/shopping_times.js b/src/main/webapp/js/shopping_times.js index 02f8047..c5d85dc 100644 --- a/src/main/webapp/js/shopping_times.js +++ b/src/main/webapp/js/shopping_times.js @@ -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; diff --git a/src/main/webapp/js/week_overview.js b/src/main/webapp/js/week_overview.js index dc5bc92..ee3d77c 100644 --- a/src/main/webapp/js/week_overview.js +++ b/src/main/webapp/js/week_overview.js @@ -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;