From 810ad07b96c0fd069ce506849a3906e8f2b99bf9 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Fri, 8 May 2026 12:59:30 +0200 Subject: [PATCH] feat(DiaryView): enhance time calculation for group activities - Updated the `calculateAllItemTimes` method to improve handling of group activities, ensuring accurate start and end times based on groupId. - Introduced a global cursor for managing time across individual and group activities, enhancing the overall scheduling logic. - Modified the template to include a new condition for displaying the plan composer field, allowing for better activity management. --- frontend/src/views/DiaryView.vue | 58 ++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/frontend/src/views/DiaryView.vue b/frontend/src/views/DiaryView.vue index 0dfb6267..377cd1dc 100644 --- a/frontend/src/views/DiaryView.vue +++ b/frontend/src/views/DiaryView.vue @@ -255,7 +255,7 @@ -
+
@@ -2317,36 +2317,42 @@ export default { return minutes1 > minutes2; }, calculateAllItemTimes() { - let currentTime = this.trainingStart; - let index = 0; - const trainingPlanLength = this.trainingPlan.length; + const initialTime = this.trainingStart || '00:00'; + let globalCursor = initialTime; + const groupCursorMap = new Map(); + const items = Array.isArray(this.trainingPlan) ? this.trainingPlan : []; - while (index < trainingPlanLength) { - const currentItem = this.trainingPlan[index]; + for (const item of items) { + const hasGroup = Number.isFinite(Number(item?.groupId)) && Number(item.groupId) > 0; + const duration = Number.isFinite(Number(item?.duration)) ? Number(item.duration) : 0; - if (!currentItem.groupId) { - currentItem.startTime = currentTime; - currentItem.endTime = this.addDurationToTime(currentItem.startTime, currentItem.duration); - currentTime = currentItem.endTime; - index += 1; - } else { - const groupActivities = []; - while (index < trainingPlanLength && this.trainingPlan[index].groupId) { - groupActivities.push(this.trainingPlan[index]); - index += 1; - } - for (const item of groupActivities) { - item.startTime = currentTime; - item.endTime = this.addDurationToTime(item.startTime, item.duration); - } - let latestEndTime = currentTime; - for (const item of groupActivities) { - if (this.isTimeGreater(item.endTime, latestEndTime)) { - latestEndTime = item.endTime; + if (!hasGroup) { + let maxGroupCursor = globalCursor; + for (const cursor of groupCursorMap.values()) { + if (this.isTimeGreater(cursor, maxGroupCursor)) { + maxGroupCursor = cursor; } } - currentTime = latestEndTime; + const startTime = this.isTimeGreater(maxGroupCursor, globalCursor) ? maxGroupCursor : globalCursor; + item.startTime = startTime; + item.endTime = this.addDurationToTime(startTime, duration); + globalCursor = item.endTime; + for (const [groupId, cursor] of groupCursorMap.entries()) { + if (this.isTimeGreater(globalCursor, cursor)) { + groupCursorMap.set(groupId, globalCursor); + } + } + continue; } + + const groupId = Number(item.groupId); + if (!groupCursorMap.has(groupId)) { + groupCursorMap.set(groupId, globalCursor); + } + const groupCursor = groupCursorMap.get(groupId) || globalCursor; + item.startTime = groupCursor; + item.endTime = this.addDurationToTime(groupCursor, duration); + groupCursorMap.set(groupId, item.endTime); } },