feat(DiaryView): enhance time calculation for group activities
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 43s
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 43s
- 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.
This commit is contained in:
@@ -255,7 +255,7 @@
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div v-if="addNewItem || addNewTimeblock" class="plan-composer-field">
|
||||
<div v-if="addNewItem || addNewTimeblock || addNewGroupActivity" class="plan-composer-field">
|
||||
<label>{{ $t('diary.durationMinutes') }}</label>
|
||||
<div class="plan-composer-duration">
|
||||
<input type="text" v-model="newPlanItem.durationText" @input="calculateDuration" :placeholder="$t('diary.durationExampleLong')" />
|
||||
@@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user