feat: implement dashboard widgets functionality

Backend:
- Add dashboard API router with widget endpoints
- Create dashboard schemas for widget data
- Add dashboard tests

Frontend:
- Enhance Dashboard page with widget components
- Add dashboard service for API calls
- Create reusable dashboard components

OpenSpec:
- Archive add-dashboard-widgets change
- Add dashboard capability specs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
beabigegg
2026-01-08 22:52:28 +08:00
parent 3d678ba5b0
commit 4860704543
17 changed files with 2152 additions and 28 deletions

View File

@@ -0,0 +1,72 @@
"""Dashboard API schemas.
Defines response models for the dashboard endpoint that aggregates
task statistics, workload, and project health summaries.
"""
from pydantic import BaseModel
from decimal import Decimal
from typing import Optional
from app.schemas.workload import LoadLevel
class TaskStatistics(BaseModel):
"""User's task statistics for dashboard display.
Attributes:
assigned_count: Total tasks assigned to user (not completed)
due_this_week: Tasks with due_date in current week
overdue_count: Tasks past due_date, not completed
completion_rate: Percentage of completed tasks (0-100)
"""
assigned_count: int
due_this_week: int
overdue_count: int
completion_rate: float
class WorkloadSummary(BaseModel):
"""User's workload summary for dashboard display.
Attributes:
allocated_hours: Total estimated hours from tasks due this week
capacity_hours: User's weekly capacity
load_percentage: Percentage of capacity used
load_level: normal (<80%), warning (80-99%), overloaded (>=100%)
"""
allocated_hours: Decimal
capacity_hours: Decimal
load_percentage: Optional[Decimal] = None
load_level: LoadLevel
class HealthSummary(BaseModel):
"""Aggregated project health summary for dashboard display.
Attributes:
total_projects: Total number of active projects
healthy_count: Projects with health_score >= 80
at_risk_count: Projects with health_score 50-79
critical_count: Projects with health_score < 50
average_health_score: Average health score across all projects
"""
total_projects: int
healthy_count: int
at_risk_count: int
critical_count: int
average_health_score: float
class DashboardResponse(BaseModel):
"""Complete dashboard response aggregating all widgets.
Single endpoint response that combines:
- Task statistics for the current user
- Current week workload summary
- Project health summary
This minimizes frontend API calls and ensures data consistency.
"""
task_stats: TaskStatistics
workload: WorkloadSummary
health_summary: HealthSummary