Reworked statistics interface

This commit is contained in:
Maximilian Giller 2022-02-02 11:50:34 +01:00
parent 9145059e46
commit a18f1b0fb2
2 changed files with 44 additions and 11 deletions

View file

@ -244,18 +244,51 @@ export const juggl = {
commit("setRecords", allRecords); commit("setRecords", allRecords);
}); });
}, },
loadTodaysStatistics({ dispatch }) { loadDailyStatistics({ dispatch }, { date }) {
dispatch("loadStatistics", { from: new Date(), until: new Date() }); dispatch("loadStatistics", [{ from: date, until: date }]);
}, },
loadStatistics({ commit }, { from, until }) { loadMonthlyStatistics(
var options = { { dispatch },
from: from, { startYear, startMonth, endYear, endMonth }
until: until ) {
}; var frames = [];
return jugglService.getStatistics(options).then(r => { // Count all the months until end year and month
commit("setStatistics", r.data.statistics); while (
}); startYear < endYear ||
(startYear == endYear && startMonth <= endMonth)
) {
// Create frame
frames.push({
from: new Date(startYear, startMonth, 1),
until: new Date(startYear, startMonth, 0) // 0 leads to the last day of the given month
});
// Count up
if (startMonth >= 12) {
startMonth = 1;
startYear++;
} else {
startMonth++;
}
}
dispatch("loadStatistics", frames);
},
async loadStatistics({ commit }, frames) {
var statistics = [];
for (const frame of frames) {
var result = Object.values(
(await jugglService.getStatistics(frame)).data.statistics
);
if (result.length > 0) {
statistics = [...statistics, ...result];
}
}
commit("setStatistics", statistics);
}, },
loadRunningRecords({ commit, getters }) { loadRunningRecords({ commit, getters }) {
return jugglService.getRunningRecords().then(r => { return jugglService.getRunningRecords().then(r => {

View file

@ -26,7 +26,7 @@ export default {
}; };
}, },
created: function() { created: function() {
store.dispatch("loadTodaysStatistics"); store.dispatch("loadDailyStatistics", { date: new Date() });
}, },
computed: { computed: {
visibleStatistics: () => { visibleStatistics: () => {