working leantime widget 54

This commit is contained in:
Alma 2025-04-12 15:26:56 +02:00
parent eb09ffbaf5
commit 1a41f773eb

View File

@ -12,7 +12,13 @@ interface Task {
projectId: number;
status: number;
type: string;
dateToFinish: string | null;
dateToFinish: string;
date: string;
editFrom: string;
editTo: string;
authorFirstname?: string;
authorLastname?: string;
tags?: string;
}
interface ProjectSummary {
@ -58,6 +64,18 @@ export function Flow() {
}
};
const getDateToSort = (task: Task): number => {
// Try different date fields in order of preference
const dates = [
task.date,
task.dateToFinish,
task.editFrom,
task.editTo
].filter(date => date && date !== '0000-00-00 00:00:00');
return dates.length > 0 ? new Date(dates[0]).getTime() : 0;
};
const fetchTasks = async (isRefresh = false) => {
try {
if (isRefresh) setRefreshing(true);
@ -71,19 +89,9 @@ export function Flow() {
return;
}
// Sort tasks by status (prioritizing in-progress and new tasks) and date
// Sort tasks by date (oldest first)
const sortedTasks = data.tasks.sort((a: Task, b: Task) => {
const statusA = getStatusLabel(a.status);
const statusB = getStatusLabel(b.status);
// Prioritize INPROGRESS, then NEW, then DONE
const statusPriority: Record<string, number> = {
'INPROGRESS': 0,
'NEW': 1,
'DONE': 2,
'UNKNOWN': 3
};
return (statusPriority[statusA] ?? 3) - (statusPriority[statusB] ?? 3);
return getDateToSort(a) - getDateToSort(b);
});
// Limit to 6 tasks
@ -138,9 +146,16 @@ export function Flow() {
{getStatusLabel(task.status)}
</span>
</div>
<p className="text-xs text-gray-500 mt-1 truncate">
{task.projectName}
</p>
<div className="flex items-center justify-between mt-1">
<p className="text-xs text-gray-500 truncate">
{task.projectName}
</p>
{task.tags && (
<p className="text-xs text-blue-500 truncate">
{task.tags}
</p>
)}
</div>
</div>
</div>
))}