bmc_hub/app/dashboard/backend/views.py

30 lines
962 B
Python
Raw Normal View History

from fastapi import APIRouter, Request
from fastapi.templating import Jinja2Templates
from fastapi.responses import HTMLResponse
from app.core.database import execute_query_single
router = APIRouter()
templates = Jinja2Templates(directory="app")
@router.get("/", response_class=HTMLResponse)
async def dashboard(request: Request):
"""
Render the dashboard page
"""
# Fetch count of unknown billing worklogs
unknown_query = """
SELECT COUNT(*) as count
FROM tticket_worklog
WHERE billing_method = 'unknown'
AND status NOT IN ('billed', 'rejected')
"""
start_date = "2024-01-01" # Filter ancient history if needed, but for now take all
result = execute_query_single(unknown_query)
unknown_count = result['count'] if result else 0
return templates.TemplateResponse("dashboard/frontend/index.html", {
"request": request,
"unknown_worklog_count": unknown_count
})