feat(DiaryView): improve sorting of training plan items by start time
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 42s
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 42s
- Introduced a new `toMinutes` function to convert time strings into minutes for accurate sorting. - Enhanced the `filteredTrainingPlan` computed property to sort items by start time, orderId, and id, ensuring a more organized display of training plans. - Maintained existing filtering logic while integrating the new sorting functionality for improved user experience.
This commit is contained in:
@@ -1049,14 +1049,37 @@ export default {
|
||||
},
|
||||
filteredTrainingPlan() {
|
||||
const allItems = Array.isArray(this.trainingPlan) ? this.trainingPlan : [];
|
||||
const toMinutes = (timeValue) => {
|
||||
if (!timeValue || typeof timeValue !== 'string' || !timeValue.includes(':')) {
|
||||
return Number.MAX_SAFE_INTEGER;
|
||||
}
|
||||
const [h, m] = timeValue.split(':').map((part) => parseInt(part, 10));
|
||||
if (!Number.isFinite(h) || !Number.isFinite(m)) {
|
||||
return Number.MAX_SAFE_INTEGER;
|
||||
}
|
||||
return (h * 60) + m;
|
||||
};
|
||||
|
||||
const sortByStartTime = (items) => items.slice().sort((a, b) => {
|
||||
const startA = toMinutes(a?.startTime);
|
||||
const startB = toMinutes(b?.startTime);
|
||||
if (startA !== startB) return startA - startB;
|
||||
|
||||
const orderA = Number.isFinite(Number(a?.orderId)) ? Number(a.orderId) : Number.MAX_SAFE_INTEGER;
|
||||
const orderB = Number.isFinite(Number(b?.orderId)) ? Number(b.orderId) : Number.MAX_SAFE_INTEGER;
|
||||
if (orderA !== orderB) return orderA - orderB;
|
||||
|
||||
return Number(a?.id || 0) - Number(b?.id || 0);
|
||||
});
|
||||
|
||||
if (this.planGroupFilter === '__all__') {
|
||||
return allItems;
|
||||
return sortByStartTime(allItems);
|
||||
}
|
||||
const selectedGroupId = Number(this.planGroupFilter);
|
||||
if (!Number.isFinite(selectedGroupId)) {
|
||||
return allItems;
|
||||
return sortByStartTime(allItems);
|
||||
}
|
||||
return allItems.filter((item) => {
|
||||
const filtered = allItems.filter((item) => {
|
||||
if (!item) return false;
|
||||
if (item.isTimeblock) {
|
||||
return this.getVisibleGroupActivities(item).length > 0;
|
||||
@@ -1067,6 +1090,7 @@ export default {
|
||||
}
|
||||
return Number(item.groupId) === selectedGroupId;
|
||||
});
|
||||
return sortByStartTime(filtered);
|
||||
},
|
||||
activePlanEditorType() {
|
||||
if (this.editingActivityId) return 'activity';
|
||||
|
||||
Reference in New Issue
Block a user