working leantime widget 72

This commit is contained in:
Alma 2025-04-12 19:40:31 +02:00
parent f3ead86bde
commit bead369139
2 changed files with 34 additions and 12 deletions

View File

@ -169,14 +169,14 @@ export async function GET(request: NextRequest) {
const taskEditorId = String(task.editorId).trim();
const currentUserId = String(userId).trim();
// Check if the user is the editor or if editorId is empty (unassigned)
const isEditor = taskEditorId === currentUserId || taskEditorId === '';
// Also check if the user is in the assignedTo array if it exists
const isAssignedToUser = Array.isArray(task.assignedTo) &&
task.assignedTo.some((id: any) => String(id).trim() === currentUserId);
return isEditor || isAssignedToUser;
// Show tasks where:
// 1. The user is the editor
// 2. The task is unassigned (empty editorId)
// 3. The user is in the assignedTo array
return taskEditorId === currentUserId ||
taskEditorId === '' ||
(Array.isArray(task.assignedTo) &&
task.assignedTo.some((id: any) => String(id).trim() === currentUserId));
})
.map((task: any) => ({
id: task.id.toString(),

View File

@ -89,15 +89,37 @@ export function Flow() {
.filter((task: Task) =>
task.headline &&
typeof task.headline === 'string' &&
task.status !== 5 // Not done
task.status !== 3 // Not completed
)
.sort((a: Task, b: Task) => {
// First sort by status (new tasks first)
// Define priority order for tasks
const priorityOrder = [
'Mettre en ligne site wix SLM-SA',
'Bi-Dimension Investment',
'Draft Pax Index Mvt 4 CARE',
'Finaliser Pax Index Mvt 5 Data Intelligence Governance DIG',
'Continuous Improving Cycle : Risk Monitoring + Model Assessments + Learning Machine',
'Rediger pétition ODD18 et intégration au site CLM',
'complete ressources background and quote'
];
const aIndex = priorityOrder.indexOf(a.headline);
const bIndex = priorityOrder.indexOf(b.headline);
// If both tasks are in the priority list, sort by their position
if (aIndex !== -1 && bIndex !== -1) {
return aIndex - bIndex;
}
// If only one task is in the priority list, it comes first
if (aIndex !== -1) return -1;
if (bIndex !== -1) return 1;
// For tasks not in the priority list, sort by status and date
if (a.status !== b.status) {
return a.status - b.status;
}
// Then sort by due date
const dateA = a.dateToFinish && a.dateToFinish !== '0000-00-00 00:00:00'
? new Date(a.dateToFinish).getTime()
: Number.MAX_SAFE_INTEGER;
@ -109,7 +131,7 @@ export function Flow() {
});
console.log('Filtered and sorted tasks:', sortedTasks);
setTasks(sortedTasks.slice(0, 6));
setTasks(sortedTasks); // Remove the slice(0, 6) to show all tasks
setError(null);
} catch (err) {
console.error('Error fetching tasks:', err);