From a883a556beb0c864dbe12a111af05a1a458fa1f6 Mon Sep 17 00:00:00 2001 From: Niko Reunanen Date: Sat, 1 Mar 2025 10:06:48 +0200 Subject: [PATCH] Show only the total daily hours per project in summary view instead of the times --- front-end/src/components/EntryTable.vue | 62 +++++++++++-------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/front-end/src/components/EntryTable.vue b/front-end/src/components/EntryTable.vue index 88c9057..f38dd67 100644 --- a/front-end/src/components/EntryTable.vue +++ b/front-end/src/components/EntryTable.vue @@ -49,39 +49,36 @@ onMounted(async () => { }); const summaries = computed(() => { - const e = entries.value.filter((el) => { - return el.end !== null && el.end.getTime() > el.start.getTime() && el.project !== ""; - }); + const hours: { [key: string]: number } = {}; - const minutes: { [key: string]: number } = {}; - - for (const el of e) { - if (el.end !== null) { - const pid = el.project; - if (!(pid in minutes)) { - minutes[pid] = 0; - } - const end = new Date(el.end).getTime(); - const start = new Date(el.start).getTime(); - const elapsed = Math.round((end - start) / (1000 * 60)); - minutes[pid] = minutes[pid] + elapsed; + for (const entry of entries.value) { + if ( + entry.end === null || + entry.end.getTime() <= entry.start.getTime() || + entry.project === "" + ) { + continue; } + + const project_id = entry.project; + + if (!(project_id in hours)) { + hours[project_id] = 0; + } + + const end = new Date(entry.end).getTime(); + const start = new Date(entry.start).getTime(); + const elapsed = Math.round(((end - start) / (1000 * 60 * 60)) * 100.0) / 100.0; + hours[project_id] = hours[project_id] + elapsed; } - const result: { key: string; start: Date; end: Date }[] = []; - let cumulative_sum = 0; - for (const key in minutes) { - const start = new Date(props.date.getTime()); - start.setHours(8, 0, 0); - start.setMinutes(start.getMinutes() + cumulative_sum); - cumulative_sum += minutes[key]; - const end = new Date(props.date.getTime()); - end.setHours(8, 0, 0); - end.setMinutes(end.getMinutes() + cumulative_sum); - result.push({ key, start, end }); + const out: { project_id: string; hours: number }[] = []; + + for (const [project_id, total] of Object.entries(hours)) { + out.push({ project_id, hours: total }); } - return result; + return out; }); const isEditorActive = computed(() => { @@ -299,17 +296,12 @@ function projectTitleFormat(project: Project, titleLimit: number): string { - + - - -