working leantime widget 18

This commit is contained in:
Alma 2025-04-12 13:33:12 +02:00
parent 742f436ff8
commit bdca2c6252

View File

@ -135,29 +135,36 @@ export async function GET() {
projectsData.result.map((project: any) => [project.id, project.name])
);
// Define status code mapping
const statusMapping: Record<string, string> = {
'-1': 'archived',
'0': 'new',
'1': 'in progress',
'2': 'waiting',
'3': 'in review',
'4': 'done'
};
// Transform the nested structure into a flat array of tasks
const tasks: Task[] = [];
Object.entries(data.result).forEach(([projectId, statusGroups]) => {
const projectName = projectsMap.get(Number(projectId)) || `Project ${projectId}`;
console.log(`Processing project ${projectId} (${projectName}):`, JSON.stringify(statusGroups, null, 2));
if (typeof statusGroups === 'object' && statusGroups !== null) {
// Iterate through each status group
Object.entries(statusGroups).forEach(([statusType, statusLabels]) => {
console.log(` Status type ${statusType}:`, JSON.stringify(statusLabels, null, 2));
if (typeof statusLabels === 'object' && statusLabels !== null) {
// Each status label in the group
Object.values(statusLabels).forEach((label: any) => {
console.log(` Processing label:`, JSON.stringify(label, null, 2));
const statusName = statusMapping[statusType] || `status-${statusType}`;
const headline = String(label.title || label.name || statusName);
const headline = String(label.name || label.title || 'Untitled');
tasks.push({
id: label.id?.toString() || `${projectId}-${statusType}`,
headline,
projectName,
status: label.type || statusType,
dueDate: null, // Status labels don't have due dates
status: statusName,
dueDate: null,
details: label.description || null,
milestone: label.milestone || null
});
@ -167,15 +174,14 @@ export async function GET() {
}
});
console.log('Transformed tasks:', JSON.stringify(tasks, null, 2));
// Sort tasks by status type
const statusOrder: Record<string, number> = {
'new': 1,
'in progress': 2,
'waiting': 3,
'done': 4,
'archived': 5
'in review': 4,
'done': 5,
'archived': 6
};
tasks.sort((a, b) => {
@ -184,7 +190,21 @@ export async function GET() {
return statusA - statusB;
});
return NextResponse.json({ tasks });
// Deduplicate tasks based on project and status
const uniqueTasks = tasks.reduce((acc: Task[], task) => {
const existingTask = acc.find(t =>
t.projectName === task.projectName &&
t.status === task.status
);
if (!existingTask) {
acc.push(task);
}
return acc;
}, []);
return NextResponse.json({ tasks: uniqueTasks });
} catch (error) {
console.error('Error fetching tasks:', error);
return NextResponse.json(