working leantime widget 65

This commit is contained in:
Alma 2025-04-12 19:08:36 +02:00
parent fc49d27b93
commit b30e2a95dd

View File

@ -15,6 +15,7 @@ interface Task {
projectName: string; projectName: string;
type: string; type: string;
status: number; status: number;
assignedTo: number[];
editorId: string; editorId: string;
editorFirstname: string | null; editorFirstname: string | null;
editorLastname: string | null; editorLastname: string | null;
@ -40,34 +41,23 @@ export function Flow() {
const getStatusLabel = (status: number): string => { const getStatusLabel = (status: number): string => {
switch (status) { switch (status) {
case 0: case 1: return 'New';
return 'NEW'; case 2: return 'Ready';
case 1: case 3: return 'In Progress';
return 'INPROGRESS'; case 4: return 'Review';
case 2: case 5: return 'Done';
return 'DONE'; default: return 'Unknown';
case 3:
return 'NEW';
case 4:
return 'INPROGRESS';
case 5:
return 'DONE';
default:
return 'UNKNOWN';
} }
}; };
const getStatusColor = (status: number): string => { const getStatusColor = (status: number): string => {
const statusLabel = getStatusLabel(status); switch (status) {
switch (statusLabel) { case 1: return 'bg-blue-500';
case 'DONE': case 2: return 'bg-green-500';
return 'bg-green-100 text-green-800'; case 3: return 'bg-yellow-500';
case 'INPROGRESS': case 4: return 'bg-purple-500';
return 'bg-yellow-100 text-yellow-800'; case 5: return 'bg-gray-500';
case 'NEW': default: return 'bg-gray-300';
return 'bg-gray-100 text-gray-800';
default:
return 'bg-gray-100 text-gray-800';
} }
}; };
@ -113,9 +103,17 @@ export function Flow() {
.filter((task: Task) => .filter((task: Task) =>
task.headline && task.headline &&
typeof task.headline === 'string' && typeof task.headline === 'string' &&
task.status !== 3 // Only show tasks that are not completed (status 3) task.status !== 5 && // Not done
Array.isArray(task.assignedTo) && task.assignedTo.length > 0 // Has assignments
) )
.sort((a: Task, b: Task) => getDateToSort(a) - getDateToSort(b)); .sort((a: Task, b: Task) => {
// First sort by status (new tasks first)
if (a.status !== b.status) {
return a.status - b.status;
}
// Then sort by due date
return getDateToSort(a) - getDateToSort(b);
});
// Limit to 6 tasks // Limit to 6 tasks
setTasks(sortedTasks.slice(0, 6)); setTasks(sortedTasks.slice(0, 6));
@ -136,7 +134,7 @@ export function Flow() {
return ( return (
<Card className="transition-transform duration-500 ease-in-out transform hover:scale-105"> <Card className="transition-transform duration-500 ease-in-out transform hover:scale-105">
<CardHeader className="flex flex-row items-center justify-between pb-2"> <CardHeader className="flex flex-row items-center justify-between pb-2">
<CardTitle className="text-lg font-medium">Tasks</CardTitle> <CardTitle className="text-lg font-medium">My ToDos</CardTitle>
<Button <Button
variant="ghost" variant="ghost"
size="icon" size="icon"
@ -155,32 +153,38 @@ export function Flow() {
) : error ? ( ) : error ? (
<div className="text-center text-sm text-red-500">{error}</div> <div className="text-center text-sm text-red-500">{error}</div>
) : tasks.length === 0 ? ( ) : tasks.length === 0 ? (
<div className="text-center text-sm text-gray-500">No tasks found</div> <div className="text-center text-sm text-gray-500">No tasks assigned to you</div>
) : ( ) : (
<div className="space-y-2"> <div className="space-y-2">
{tasks.map((task) => ( {tasks.map((task) => (
<div <div
key={task.id} key={task.id}
className="p-2 rounded-lg bg-white/50 backdrop-blur-sm hover:bg-white/60 transition-colors" className="p-3 rounded-lg bg-white/50 backdrop-blur-sm hover:bg-white/60 transition-colors border border-gray-200"
> >
<h3 className="text-sm font-medium truncate" title={task.headline}> <div className="flex items-start gap-3">
<div className="flex-1">
<div className="flex items-center gap-2">
<h3 className="text-sm font-medium text-blue-600 hover:text-blue-800 truncate" title={task.headline}>
{task.headline} {task.headline}
</h3> </h3>
{task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00' && ( <span className={`px-2 py-0.5 text-xs rounded-full ${getStatusColor(task.status)} text-white`}>
<p className="text-xs text-gray-500 mt-1"> {getStatusLabel(task.status)}
Due: {formatDate(task.dateToFinish)} </span>
</p> </div>
)} <div className="mt-1 flex items-center gap-2 text-xs text-gray-500">
{task.editorFirstname && task.editorLastname && (
<p className="text-xs text-gray-500 mt-1">
Assigned to: {task.editorFirstname} {task.editorLastname}
</p>
)}
{task.projectName && ( {task.projectName && (
<p className="text-xs text-gray-500 mt-1"> <span className="inline-flex items-center">
Project: {task.projectName} <span className="mr-1">📁</span> {task.projectName}
</p> </span>
)} )}
{task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00' && (
<span className="inline-flex items-center">
<span className="mr-1">📅</span> {formatDate(task.dateToFinish)}
</span>
)}
</div>
</div>
</div>
</div> </div>
))} ))}
</div> </div>