working leantime widget 114

This commit is contained in:
Alma 2025-04-12 22:41:25 +02:00
parent 9b235a9785
commit 52f165ba91

View File

@ -95,40 +95,21 @@ export function Flow() {
return;
}
// Log the complete first task to see its structure
console.log('First task from API:', JSON.stringify(data.tasks[0], null, 2));
// Log all tasks with their date fields
data.tasks.forEach((task: Task) => {
console.log(`Task ${task.id} - ${task.headline}:`, {
dateToFinish: task.dateToFinish || 'not set',
date: task.date || 'not set',
status: task.status,
projectName: task.projectName
});
});
// Process tasks - exclude completed tasks and get valid dates
const processedTasks = data.tasks
.filter((task: Task) => task.status !== 5) // Exclude completed tasks
.map((task: Task): TaskWithDate => {
let validDate: Date | undefined;
// First try dateToFinish if it's a valid date
// Only use dateToFinish
if (task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00') {
const date = new Date(task.dateToFinish);
if (!isNaN(date.getTime())) {
validDate = date;
console.log(`Task ${task.id} - Valid dateToFinish:`, task.dateToFinish);
}
}
// If no valid dateToFinish, try date field
if (!validDate && task.date && task.date !== '0000-00-00 00:00:00') {
const date = new Date(task.date);
if (!isNaN(date.getTime())) {
validDate = date;
console.log(`Task ${task.id} - Using date field:`, task.date);
const dateToFinish = new Date(task.dateToFinish);
if (!isNaN(dateToFinish.getTime())) {
validDate = dateToFinish;
console.log(`Task ${task.id} - ${task.headline}:`, {
dateToFinish: task.dateToFinish,
status: task.status
});
}
}
@ -136,40 +117,28 @@ export function Flow() {
});
// Sort tasks: first by status (4 before 3), then by date
const sortedTasks = processedTasks
.sort((a: TaskWithDate, b: TaskWithDate) => {
// First sort by status (4 before 3)
if (a.status !== b.status) {
return b.status - a.status; // Higher status numbers first
}
// Then sort by date
if (a.validDate && b.validDate) {
return a.validDate.getTime() - b.validDate.getTime();
}
if (a.validDate) return -1;
if (b.validDate) return 1;
return 0;
});
const sortedTasks = processedTasks.sort((a: TaskWithDate, b: TaskWithDate) => {
// First sort by status (4 before 3)
if (a.status !== b.status) {
return b.status - a.status;
}
// Then sort by date
if (a.validDate && b.validDate) {
return a.validDate.getTime() - b.validDate.getTime();
}
if (a.validDate) return -1;
if (b.validDate) return 1;
return 0;
});
console.log('Sorted tasks before slice:', sortedTasks.map((t: TaskWithDate) => ({
id: t.id,
headline: t.headline,
status: t.status,
dateToFinish: t.dateToFinish,
date: t.date,
validDate: t.validDate?.toISOString()
})));
// Take the first 12 tasks
// Take first 12 tasks
const finalTasks = sortedTasks.slice(0, 12);
console.log('Final tasks to display:', finalTasks.map((t: TaskWithDate) => ({
id: t.id,
headline: t.headline,
status: t.status,
dateToFinish: t.dateToFinish,
date: t.date,
validDate: t.validDate?.toISOString()
})));
@ -199,24 +168,24 @@ export function Flow() {
const today = new Date();
today.setHours(0, 0, 0, 0);
const isPastDue = task.validDate < today;
const textColorClass = isPastDue ? 'text-red-600' : 'text-blue-600';
const boldColorClass = isPastDue ? 'text-red-700' : 'text-blue-700';
try {
const month = task.validDate.toLocaleString('fr-FR', { month: 'short' }).toUpperCase();
const day = task.validDate.getDate();
return (
<>
<span className={`text-xs ${textColorClass} font-medium uppercase`}>
{new Intl.DateTimeFormat('fr-FR', { month: 'short' }).format(task.validDate)}
<span className={`text-xs font-medium uppercase ${isPastDue ? 'text-red-600' : 'text-blue-600'}`}>
{month}
</span>
<span className={`text-lg ${boldColorClass} font-bold`}>
{task.validDate.getDate()}
<span className={`text-lg font-bold ${isPastDue ? 'text-red-700' : 'text-blue-700'}`}>
{day}
</span>
</>
);
} catch (error) {
console.error('Error formatting date:', error);
console.error('Error formatting date for task', task.id, error);
return (
<>
<span className="text-xs text-gray-600 font-medium">ERR</span>