Show only the total daily hours per project in summary view instead of the times

This commit is contained in:
Niko Reunanen 2025-03-01 10:06:48 +02:00
parent 1ab7fbd12e
commit a883a556be
Signed by: nreunane
GPG key ID: D192625387DB0F16

View file

@ -49,39 +49,36 @@ onMounted(async () => {
}); });
const summaries = computed(() => { const summaries = computed(() => {
const e = entries.value.filter((el) => { const hours: { [key: string]: number } = {};
return el.end !== null && el.end.getTime() > el.start.getTime() && el.project !== "";
});
const minutes: { [key: string]: number } = {}; for (const entry of entries.value) {
if (
for (const el of e) { entry.end === null ||
if (el.end !== null) { entry.end.getTime() <= entry.start.getTime() ||
const pid = el.project; entry.project === ""
if (!(pid in minutes)) { ) {
minutes[pid] = 0; continue;
}
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;
} }
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 }[] = []; const out: { project_id: string; hours: number }[] = [];
let cumulative_sum = 0;
for (const key in minutes) { for (const [project_id, total] of Object.entries(hours)) {
const start = new Date(props.date.getTime()); out.push({ project_id, hours: total });
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 });
} }
return result; return out;
}); });
const isEditorActive = computed(() => { const isEditorActive = computed(() => {
@ -299,17 +296,12 @@ function projectTitleFormat(project: Project, titleLimit: number): string {
<DataTable v-if="summaries.length > 0" :value="summaries"> <DataTable v-if="summaries.length > 0" :value="summaries">
<Column header="Project"> <Column header="Project">
<template #body="slotProps"> <template #body="slotProps">
{{ projectTitleFormat(getProjectById(slotProps.data.key), 60) }} {{ projectTitleFormat(getProjectById(slotProps.data.project_id), 60) }}
</template> </template>
</Column> </Column>
<Column header="Start"> <Column header="Hours">
<template #body="slotProps"> <template #body="slotProps">
{{ getDateFmt(slotProps.data.start) }} {{ slotProps.data.hours }}
</template>
</Column>
<Column header="End">
<template #body="slotProps">
{{ getDateFmt(slotProps.data.end) }}
</template> </template>
</Column> </Column>
</DataTable> </DataTable>