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; 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 // Process tasks - exclude completed tasks and get valid dates
const processedTasks = data.tasks const processedTasks = data.tasks
.filter((task: Task) => task.status !== 5) // Exclude completed tasks .filter((task: Task) => task.status !== 5) // Exclude completed tasks
.map((task: Task): TaskWithDate => { .map((task: Task): TaskWithDate => {
let validDate: Date | undefined; 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') { if (task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00') {
const date = new Date(task.dateToFinish); const dateToFinish = new Date(task.dateToFinish);
if (!isNaN(date.getTime())) { if (!isNaN(dateToFinish.getTime())) {
validDate = date; validDate = dateToFinish;
console.log(`Task ${task.id} - Valid dateToFinish:`, task.dateToFinish); console.log(`Task ${task.id} - ${task.headline}:`, {
} dateToFinish: task.dateToFinish,
} status: task.status
});
// 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);
} }
} }
@ -136,11 +117,10 @@ export function Flow() {
}); });
// Sort tasks: first by status (4 before 3), then by date // Sort tasks: first by status (4 before 3), then by date
const sortedTasks = processedTasks const sortedTasks = processedTasks.sort((a: TaskWithDate, b: TaskWithDate) => {
.sort((a: TaskWithDate, b: TaskWithDate) => {
// First sort by status (4 before 3) // First sort by status (4 before 3)
if (a.status !== b.status) { if (a.status !== b.status) {
return b.status - a.status; // Higher status numbers first return b.status - a.status;
} }
// Then sort by date // Then sort by date
@ -152,24 +132,13 @@ export function Flow() {
return 0; return 0;
}); });
console.log('Sorted tasks before slice:', sortedTasks.map((t: TaskWithDate) => ({ // Take first 12 tasks
id: t.id,
headline: t.headline,
status: t.status,
dateToFinish: t.dateToFinish,
date: t.date,
validDate: t.validDate?.toISOString()
})));
// Take the first 12 tasks
const finalTasks = sortedTasks.slice(0, 12); const finalTasks = sortedTasks.slice(0, 12);
console.log('Final tasks to display:', finalTasks.map((t: TaskWithDate) => ({ console.log('Final tasks to display:', finalTasks.map((t: TaskWithDate) => ({
id: t.id, id: t.id,
headline: t.headline, headline: t.headline,
status: t.status, status: t.status,
dateToFinish: t.dateToFinish, dateToFinish: t.dateToFinish,
date: t.date,
validDate: t.validDate?.toISOString() validDate: t.validDate?.toISOString()
}))); })));
@ -199,24 +168,24 @@ export function Flow() {
const today = new Date(); const today = new Date();
today.setHours(0, 0, 0, 0); today.setHours(0, 0, 0, 0);
const isPastDue = task.validDate < today; const isPastDue = task.validDate < today;
const textColorClass = isPastDue ? 'text-red-600' : 'text-blue-600';
const boldColorClass = isPastDue ? 'text-red-700' : 'text-blue-700';
try { try {
const month = task.validDate.toLocaleString('fr-FR', { month: 'short' }).toUpperCase();
const day = task.validDate.getDate();
return ( return (
<> <>
<span className={`text-xs ${textColorClass} font-medium uppercase`}> <span className={`text-xs font-medium uppercase ${isPastDue ? 'text-red-600' : 'text-blue-600'}`}>
{new Intl.DateTimeFormat('fr-FR', { month: 'short' }).format(task.validDate)} {month}
</span> </span>
<span className={`text-lg ${boldColorClass} font-bold`}> <span className={`text-lg font-bold ${isPastDue ? 'text-red-700' : 'text-blue-700'}`}>
{task.validDate.getDate()} {day}
</span> </span>
</> </>
); );
} catch (error) { } catch (error) {
console.error('Error formatting date:', error); console.error('Error formatting date for task', task.id, error);
return ( return (
<> <>
<span className="text-xs text-gray-600 font-medium">ERR</span> <span className="text-xs text-gray-600 font-medium">ERR</span>