fix(tasktree): align active timeline presentation

This commit is contained in:
root
2026-07-21 13:38:09 +02:00
parent 48db528a26
commit 3217b99e50
2 changed files with 54 additions and 15 deletions
+25 -6
View File
@@ -154,7 +154,12 @@ export class TaskTreeStore {
LEFT JOIN tasktree_tasks t ON t.group_id=g.id LEFT JOIN tasktree_tasks t ON t.group_id=g.id
LEFT JOIN tasktree_execution_reports r ON r.task_id=t.id LEFT JOIN tasktree_execution_reports r ON r.task_id=t.id
GROUP BY g.id GROUP BY g.id
ORDER BY g.updated_at DESC, g.name ORDER BY GREATEST(
g.updated_at,
COALESCE(MAX(t.updated_at),g.updated_at),
COALESCE(MAX(r.created_at),g.updated_at),
COALESCE((SELECT MAX(m.created_at) FROM tasktree_milestones m WHERE m.group_id=g.id),g.updated_at)
) DESC, g.name
`); `);
return result.rows.map(overviewRow); return result.rows.map(overviewRow);
} }
@@ -338,11 +343,25 @@ export class TaskTreeStore {
async createReport(input: { taskId: string; title: string; body: string; status?: string }): Promise<ExecutionReport> { async createReport(input: { taskId: string; title: string; body: string; status?: string }): Promise<ExecutionReport> {
await this.ensureSchema(); await this.ensureSchema();
const result = await this.pool.query( const client = await this.pool.connect();
"INSERT INTO tasktree_execution_reports (id,task_id,title,body,status) VALUES ($1,$2,$3,$4,$5) RETURNING *", try {
[`tr_${randomUUID()}`, input.taskId, input.title, input.body, input.status ?? "succeeded"] await client.query("BEGIN");
); const result = await client.query(
return reportRow(result.rows[0]); "INSERT INTO tasktree_execution_reports (id,task_id,title,body,status) VALUES ($1,$2,$3,$4,$5) RETURNING *",
[`tr_${randomUUID()}`, input.taskId, input.title, input.body, input.status ?? "succeeded"]
);
await client.query(
"UPDATE tasktree_groups g SET updated_at=now() FROM tasktree_tasks t WHERE t.id=$1 AND g.id=t.group_id",
[input.taskId]
);
await client.query("COMMIT");
return reportRow(result.rows[0]);
} catch (error) {
await client.query("ROLLBACK").catch(() => {});
throw error;
} finally {
client.release();
}
} }
async listReports(taskId: string): Promise<ExecutionReport[]> { async listReports(taskId: string): Promise<ExecutionReport[]> {
@@ -20,6 +20,7 @@ const collapsedTaskIds = ref(new Set<string>());
const timelineHeaderElement = ref<HTMLElement | null>(null); const timelineHeaderElement = ref<HTMLElement | null>(null);
const taskLabelsElement = ref<HTMLElement | null>(null); const taskLabelsElement = ref<HTMLElement | null>(null);
const timelineBodyElement = ref<HTMLElement | null>(null); const timelineBodyElement = ref<HTMLElement | null>(null);
const timelineScrollbarWidth = ref(0);
const labelChildScrollers = new Map<string, HTMLElement>(); const labelChildScrollers = new Map<string, HTMLElement>();
const timelineChildScrollers = new Map<string, HTMLElement>(); const timelineChildScrollers = new Map<string, HTMLElement>();
const initializedChildGroups = new Set<string>(); const initializedChildGroups = new Set<string>();
@@ -28,6 +29,7 @@ const timelineScaleIndex = ref(1);
const taskColumnWidth = ref(typeof window !== "undefined" ? Math.round(window.innerWidth * (window.innerWidth <= 720 ? 0.55 : 0.21)) : 400); const taskColumnWidth = ref(typeof window !== "undefined" ? Math.round(window.innerWidth * (window.innerWidth <= 720 ? 0.55 : 0.21)) : 400);
const loading = ref(false); const loading = ref(false);
const error = ref<string | null>(null); const error = ref<string | null>(null);
let positionedView = "";
const groupId = computed(() => String(route.params.groupId || "")); const groupId = computed(() => String(route.params.groupId || ""));
const displayTime = displayTimeConfig(); const displayTime = displayTimeConfig();
const displayPartsFormatter = new Intl.DateTimeFormat(displayTime.locale, { const displayPartsFormatter = new Intl.DateTimeFormat(displayTime.locale, {
@@ -113,6 +115,8 @@ async function loadActiveView() {
if (!groupId.value) { if (!groupId.value) {
timeline.value = null; timeline.value = null;
loading.value = false; loading.value = false;
await nextTick();
positionTimelineAtNow("global");
return; return;
} }
const timelineResponse = await tasktreeAPI.timeline(groupId.value); const timelineResponse = await tasktreeAPI.timeline(groupId.value);
@@ -124,6 +128,8 @@ async function loadActiveView() {
timeline.value = timelineResponse.data.data; timeline.value = timelineResponse.data.data;
initializedChildGroups.clear(); initializedChildGroups.clear();
syncSelectedTaskFromRoute(); syncSelectedTaskFromRoute();
await nextTick();
positionTimelineAtNow(groupId.value);
} }
function selectGroup(event: Event) { function selectGroup(event: Event) {
const value = (event.target as HTMLSelectElement).value; const value = (event.target as HTMLSelectElement).value;
@@ -282,13 +288,18 @@ async function changeTimelineScale(direction: -1 | 1) {
function syncTimelineBody() { function syncTimelineBody() {
const body = timelineBodyElement.value; const body = timelineBodyElement.value;
if (!body) return; if (!body) return;
timelineScrollbarWidth.value = Math.max(0, body.offsetWidth - body.clientWidth);
if (timelineHeaderElement.value && timelineHeaderElement.value.scrollLeft !== body.scrollLeft) timelineHeaderElement.value.scrollLeft = body.scrollLeft; if (timelineHeaderElement.value && timelineHeaderElement.value.scrollLeft !== body.scrollLeft) timelineHeaderElement.value.scrollLeft = body.scrollLeft;
if (taskLabelsElement.value && taskLabelsElement.value.scrollTop !== body.scrollTop) taskLabelsElement.value.scrollTop = body.scrollTop; if (taskLabelsElement.value && taskLabelsElement.value.scrollTop !== body.scrollTop) taskLabelsElement.value.scrollTop = body.scrollTop;
} }
function syncTimelineHeader() { function positionTimelineAtNow(view: string) {
const header = timelineHeaderElement.value;
const body = timelineBodyElement.value; const body = timelineBodyElement.value;
if (header && body && body.scrollLeft !== header.scrollLeft) body.scrollLeft = header.scrollLeft; if (!body || positionedView === view) return;
timelineScrollbarWidth.value = Math.max(0, body.offsetWidth - body.clientWidth);
const now = todayOffset.value;
body.scrollLeft = now === null ? 0 : Math.max(0, Math.min(body.scrollWidth - body.clientWidth, body.scrollWidth * now / 100 - body.clientWidth * 0.8));
if (timelineHeaderElement.value) timelineHeaderElement.value.scrollLeft = body.scrollLeft;
positionedView = view;
} }
function syncTaskLabels() { function syncTaskLabels() {
const labels = taskLabelsElement.value; const labels = taskLabelsElement.value;
@@ -321,8 +332,10 @@ function displaySerial(date: Date) { const parts = displayParts(date); return Da
function displayDaySerial(date: Date) { const parts = displayParts(date); return Date.UTC(parts.year, parts.month - 1, parts.day); } function displayDaySerial(date: Date) { const parts = displayParts(date); return Date.UTC(parts.year, parts.month - 1, parts.day); }
function barStyle(item: { startAt: string | null; dueAt: string | null }) { function barStyle(item: { startAt: string | null; dueAt: string | null }) {
const start = displaySerial(new Date(item.startAt || item.dueAt || range.value.start)); const end = displaySerial(new Date(item.dueAt || item.startAt || range.value.start)); const unit = 100 / range.value.dayCount; const start = displaySerial(new Date(item.startAt || item.dueAt || range.value.start)); const end = displaySerial(new Date(item.dueAt || item.startAt || range.value.start)); const unit = 100 / range.value.dayCount;
const left = Math.max(0, (start - displaySerial(range.value.start)) / 86400000) * unit; const width = Math.max(unit * 0.65, ((end - start) / 86400000) * unit); const rangeStart = displaySerial(range.value.start);
return { left: `${left}%`, width: `${Math.min(100 - left, width)}%` }; const left = Math.max(0, (start - rangeStart) / 86400000) * unit;
const rightEdge = Math.min(100, Math.max(left, (end - rangeStart) / 86400000 * unit));
return { right: `${100 - rightEdge}%`, width: `${Math.max(0, rightEdge - left)}%` };
} }
function trackStyle() { function trackStyle() {
return { return {
@@ -393,7 +406,14 @@ function syncSelectedTaskFromRoute() {
<template> <template>
<main class="tasktree-page" data-testid="tasktree-page"> <main class="tasktree-page" data-testid="tasktree-page">
<AsyncBoundary :state="asyncState" title="TaskTree 暂无任务" :message="error || '通过 CLI 创建 taskgroup 和任务后会显示在时间轴中。'" @retry="loadActiveView"> <AsyncBoundary
:state="asyncState"
empty-title="TaskTree 暂无任务"
empty-description="通过 CLI 创建 taskgroup 和任务后会显示在时间轴中"
error-title="TaskTree 加载失败"
:error="error || '请求未完成,请稍后重试。'"
@retry="loadActiveView"
>
<div v-if="isGlobalView || timeline" class="tasktree-view-layout" :class="{ docked: detailMode === 'docked' && selectedTask }"> <div v-if="isGlobalView || timeline" class="tasktree-view-layout" :class="{ docked: detailMode === 'docked' && selectedTask }">
<section class="tasktree-workspace" aria-label="TaskTree 甘特图"> <section class="tasktree-workspace" aria-label="TaskTree 甘特图">
<header class="tasktree-context"> <header class="tasktree-context">
@@ -416,7 +436,7 @@ function syncSelectedTaskFromRoute() {
<button class="icon-button tasktree-refresh" type="button" title="刷新" aria-label="刷新" :disabled="loading" @click="loadActiveView"><RefreshCw :size="15" aria-hidden="true" /></button> <button class="icon-button tasktree-refresh" type="button" title="刷新" aria-label="刷新" :disabled="loading" @click="loadActiveView"><RefreshCw :size="15" aria-hidden="true" /></button>
</div> </div>
</header> </header>
<div class="tasktree-gantt" :class="{ 'global-view': isGlobalView, 'has-today': todayOffset !== null }" :style="{ '--task-column-width': `${taskColumnWidth}px`, '--tick-count': timelineTicks.length, '--tick-width': `${timelineScale.tickWidth}px`, '--timeline-width': `${timelineWidth}px`, '--today-left': `${todayOffset ?? 0}%` }"> <div class="tasktree-gantt" :class="{ 'global-view': isGlobalView, 'has-today': todayOffset !== null }" :style="{ '--task-column-width': `${taskColumnWidth}px`, '--tick-count': timelineTicks.length, '--tick-width': `${timelineScale.tickWidth}px`, '--timeline-width': `${timelineWidth}px`, '--today-left': `${todayOffset ?? 0}%`, '--timeline-scrollbar-width': `${timelineScrollbarWidth}px` }">
<div class="tasktree-corner">{{ isGlobalView ? 'TaskGroup' : '任务' }}</div> <div class="tasktree-corner">{{ isGlobalView ? 'TaskGroup' : '任务' }}</div>
<div <div
class="tasktree-column-resizer" class="tasktree-column-resizer"
@@ -430,7 +450,7 @@ function syncSelectedTaskFromRoute() {
@pointerdown="startTaskColumnResize" @pointerdown="startTaskColumnResize"
@keydown="resizeTaskColumnByKeyboard" @keydown="resizeTaskColumnByKeyboard"
/> />
<div ref="timelineHeaderElement" class="tasktree-timeline-header" @scroll="syncTimelineHeader"> <div ref="timelineHeaderElement" class="tasktree-timeline-header">
<div class="tasktree-days"> <div class="tasktree-days">
<span v-for="tick in timelineTicks" :key="tick.toISOString()" :class="tickClass(tick)">{{ tickLabel(tick) }}</span> <span v-for="tick in timelineTicks" :key="tick.toISOString()" :class="tickClass(tick)">{{ tickLabel(tick) }}</span>
</div> </div>
@@ -605,7 +625,7 @@ function syncSelectedTaskFromRoute() {
.tasktree-column-resizer:focus-visible::after, .tasktree-column-resizer:focus-visible::after,
.tasktree-column-resizer:active::after { background: #2376c9; } .tasktree-column-resizer:active::after { background: #2376c9; }
.tasktree-corner { display: flex; align-items: center; padding: 0 14px; border-right: 1px solid var(--border-color); border-bottom: 1px solid var(--border-color); background: transparent; font-size: 11px; font-weight: 700; } .tasktree-corner { display: flex; align-items: center; padding: 0 14px; border-right: 1px solid var(--border-color); border-bottom: 1px solid var(--border-color); background: transparent; font-size: 11px; font-weight: 700; }
.tasktree-timeline-header { min-width: 0; overflow-x: auto; overflow-y: hidden; border-bottom: 1px solid #dfe5e4; background: #fbfcfc; scrollbar-width: none; overscroll-behavior-inline: contain; } .tasktree-timeline-header { min-width: 0; overflow: hidden; padding-right: var(--timeline-scrollbar-width); border-bottom: 1px solid #dfe5e4; background: #fbfcfc; scrollbar-width: none; }
.tasktree-timeline-header::-webkit-scrollbar { display: none; } .tasktree-timeline-header::-webkit-scrollbar { display: none; }
.tasktree-days { position: relative; width: max(100%, var(--timeline-width)); height: 100%; display: grid; grid-template-columns: repeat(var(--tick-count), minmax(var(--tick-width), 1fr)); } .tasktree-days { position: relative; width: max(100%, var(--timeline-width)); height: 100%; display: grid; grid-template-columns: repeat(var(--tick-count), minmax(var(--tick-width), 1fr)); }
.tasktree-days span { position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; padding: 0 4px; overflow: hidden; border-right: 1px solid #e6ebea; color: #68777a; font-family: var(--console-font-mono); font-size: 10px; white-space: nowrap; } .tasktree-days span { position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; padding: 0 4px; overflow: hidden; border-right: 1px solid #e6ebea; color: #68777a; font-family: var(--console-font-mono); font-size: 10px; white-space: nowrap; }