Tier 3: timers CRUD + time tracking with topbar timer

This commit is contained in:
2026-02-28 05:03:16 +00:00
parent 7b259b9597
commit a1d24354a0
5 changed files with 813 additions and 1 deletions

View File

@@ -16,6 +16,15 @@ router = APIRouter(prefix="/tasks", tags=["tasks"])
templates = Jinja2Templates(directory="templates")
async def get_running_task_id(db: AsyncSession) -> Optional[str]:
"""Get the task_id of the currently running timer, if any."""
result = await db.execute(text(
"SELECT task_id FROM time_entries WHERE end_at IS NULL AND is_deleted = false LIMIT 1"
))
row = result.first()
return str(row.task_id) if row else None
@router.get("/")
async def list_tasks(
request: Request,
@@ -83,6 +92,8 @@ async def list_tasks(
))
context_types = [dict(r._mapping) for r in result]
running_task_id = await get_running_task_id(db)
return templates.TemplateResponse("tasks.html", {
"request": request, "sidebar": sidebar, "items": items,
"domains": domains, "projects": projects, "context_types": context_types,
@@ -92,6 +103,7 @@ async def list_tasks(
"current_priority": priority or "",
"current_context": context or "",
"current_sort": sort,
"running_task_id": running_task_id,
"page_title": "All Tasks", "active_nav": "tasks",
})
@@ -207,10 +219,13 @@ async def task_detail(task_id: str, request: Request, db: AsyncSession = Depends
"""), {"tid": task_id})
subtasks = [dict(r._mapping) for r in result]
running_task_id = await get_running_task_id(db)
return templates.TemplateResponse("task_detail.html", {
"request": request, "sidebar": sidebar, "item": item,
"domain": domain, "project": project, "parent": parent,
"subtasks": subtasks,
"running_task_id": running_task_id,
"page_title": item["title"], "active_nav": "tasks",
})