Reworked statistics interface
This commit is contained in:
parent
9145059e46
commit
a18f1b0fb2
2 changed files with 44 additions and 11 deletions
|
@ -244,18 +244,51 @@ export const juggl = {
|
|||
commit("setRecords", allRecords);
|
||||
});
|
||||
},
|
||||
loadTodaysStatistics({ dispatch }) {
|
||||
dispatch("loadStatistics", { from: new Date(), until: new Date() });
|
||||
loadDailyStatistics({ dispatch }, { date }) {
|
||||
dispatch("loadStatistics", [{ from: date, until: date }]);
|
||||
},
|
||||
loadStatistics({ commit }, { from, until }) {
|
||||
var options = {
|
||||
from: from,
|
||||
until: until
|
||||
};
|
||||
loadMonthlyStatistics(
|
||||
{ dispatch },
|
||||
{ startYear, startMonth, endYear, endMonth }
|
||||
) {
|
||||
var frames = [];
|
||||
|
||||
return jugglService.getStatistics(options).then(r => {
|
||||
commit("setStatistics", r.data.statistics);
|
||||
});
|
||||
// Count all the months until end year and month
|
||||
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 }) {
|
||||
return jugglService.getRunningRecords().then(r => {
|
||||
|
|
|
@ -26,7 +26,7 @@ export default {
|
|||
};
|
||||
},
|
||||
created: function() {
|
||||
store.dispatch("loadTodaysStatistics");
|
||||
store.dispatch("loadDailyStatistics", { date: new Date() });
|
||||
},
|
||||
computed: {
|
||||
visibleStatistics: () => {
|
||||
|
|
Loading…
Reference in a new issue