working leantime widget 64

This commit is contained in:
Alma 2025-04-12 19:04:34 +02:00
parent e7e387dd56
commit fc49d27b93

View File

@ -6,28 +6,22 @@ import { Button } from "@/components/ui/button";
import { RefreshCw } from "lucide-react"; import { RefreshCw } from "lucide-react";
interface Task { interface Task {
id: string; id: number;
headline: string; headline: string;
projectName: string; description: string;
projectId: number;
status: number;
type: string;
dateToFinish: string;
date: string; date: string;
editFrom: string; dateToFinish: string;
editTo: string; projectId: number;
editor: { projectName: string;
id: string; type: string;
firstname: string; status: number;
lastname: string; editorId: string;
}; editorFirstname: string | null;
authorFirstname?: string; editorLastname: string | null;
authorLastname?: string; authorFirstname: string;
tags?: string; authorLastname: string;
description?: string; milestoneHeadline: string | null;
milestone?: string; tags: string;
details?: string;
milestoneHeadline?: string;
} }
interface ProjectSummary { interface ProjectSummary {
@ -78,15 +72,11 @@ export function Flow() {
}; };
const getDateToSort = (task: Task): number => { const getDateToSort = (task: Task): number => {
// Try different date fields in order of preference // Try to use dateToFinish first, then fall back to date
const dates = [ const dateStr = task.dateToFinish !== '0000-00-00 00:00:00'
task.dateToFinish, ? task.dateToFinish
task.date, : task.date;
task.editTo, return new Date(dateStr).getTime();
task.editFrom
].filter(date => date && date !== '0000-00-00 00:00:00');
return dates.length > 0 ? new Date(dates[0]).getTime() : Number.MAX_SAFE_INTEGER;
}; };
const formatDate = (dateStr: string): string => { const formatDate = (dateStr: string): string => {
@ -123,7 +113,7 @@ export function Flow() {
.filter((task: Task) => .filter((task: Task) =>
task.headline && task.headline &&
typeof task.headline === 'string' && typeof task.headline === 'string' &&
task.editor // Only show tasks with an editor task.status !== 3 // Only show tasks that are not completed (status 3)
) )
.sort((a: Task, b: Task) => getDateToSort(a) - getDateToSort(b)); .sort((a: Task, b: Task) => getDateToSort(a) - getDateToSort(b));
@ -181,9 +171,14 @@ export function Flow() {
Due: {formatDate(task.dateToFinish)} Due: {formatDate(task.dateToFinish)}
</p> </p>
)} )}
{task.editor && ( {task.editorFirstname && task.editorLastname && (
<p className="text-xs text-gray-500 mt-1"> <p className="text-xs text-gray-500 mt-1">
Assigned to: {task.editor.firstname} {task.editor.lastname} Assigned to: {task.editorFirstname} {task.editorLastname}
</p>
)}
{task.projectName && (
<p className="text-xs text-gray-500 mt-1">
Project: {task.projectName}
</p> </p>
)} )}
</div> </div>