63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
"""Dashboard route."""
|
|
from fastapi import APIRouter, Request
|
|
from fastapi.responses import HTMLResponse
|
|
from fastapi.templating import Jinja2Templates
|
|
from pathlib import Path
|
|
from datetime import datetime
|
|
from src.scheduler.briefings import (
|
|
get_todays_events,
|
|
get_priority_tasks,
|
|
get_tasks_due_soon,
|
|
get_waiting_items,
|
|
)
|
|
from src.parsers.project_parser import ProjectParser
|
|
from src.tools.file_ops import read_file
|
|
|
|
router = APIRouter()
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
|
templates = Jinja2Templates(directory=str(BASE_DIR / "web" / "templates"))
|
|
|
|
|
|
@router.get("/dashboard", response_class=HTMLResponse)
|
|
async def dashboard(request: Request):
|
|
"""Dashboard page."""
|
|
# Get today's data
|
|
today = datetime.now().strftime("%A, %B %d, %Y")
|
|
events = get_todays_events()
|
|
priority_tasks = get_priority_tasks(["A", "B"])
|
|
due_soon = get_tasks_due_soon(3)
|
|
waiting = get_waiting_items()
|
|
|
|
# Get active projects
|
|
try:
|
|
content = read_file("projects.txt")
|
|
all_projects = ProjectParser.parse_file(content)
|
|
active_projects = [p for p in all_projects if p.status == "active"]
|
|
except:
|
|
active_projects = []
|
|
|
|
# Stats
|
|
stats = {
|
|
"events_today": len(events),
|
|
"priority_tasks": len(priority_tasks),
|
|
"due_soon": len(due_soon),
|
|
"active_projects": len(active_projects),
|
|
"waiting_items": len(waiting),
|
|
}
|
|
|
|
return templates.TemplateResponse(
|
|
"dashboard.html",
|
|
{
|
|
"request": request,
|
|
"page": "dashboard",
|
|
"today": today,
|
|
"events": events,
|
|
"priority_tasks": priority_tasks[:5], # Top 5
|
|
"due_soon": due_soon[:3], # Top 3
|
|
"active_projects": active_projects[:5], # Top 5
|
|
"waiting": waiting[:3], # Top 3
|
|
"stats": stats,
|
|
}
|
|
)
|