Upgrade unified reports centre to v2

This commit is contained in:
A R R R Associates
2026-07-06 12:15:32 +05:30
parent 2689cb28a6
commit 47f5080d43
10 changed files with 250 additions and 100 deletions
+26 -5
View File
@@ -11,15 +11,18 @@ from app.core.templating import templates
from app.modules.core.rbac.deps import get_user_permissions, get_user_roles
from app.modules.unified_reports.service import (
can_access_reports,
cards_by_area,
cards_by_group,
get_report_summary,
get_report_tabs,
get_visible_report_cards,
recommended_cards,
)
router = APIRouter(prefix="/reports", tags=["unified-reports-ui"])
_ALLOWED_TABS = {
"overview": "overview",
"my-reports": "my",
"work": "work",
"client": "client",
@@ -27,6 +30,20 @@ _ALLOWED_TABS = {
"hr": "hr",
"system": "system",
"audit": "audit",
# Backward-compatible aliases from V1 direct links.
"my_reports": "my",
}
_PARTIALS = {
"overview": "modules/unified_reports/templates/unified_reports/partials/overview.html",
"my-reports": "modules/unified_reports/templates/unified_reports/partials/my_reports.html",
"my_reports": "modules/unified_reports/templates/unified_reports/partials/my_reports.html",
"work": "modules/unified_reports/templates/unified_reports/partials/work.html",
"client": "modules/unified_reports/templates/unified_reports/partials/client.html",
"billing": "modules/unified_reports/templates/unified_reports/partials/billing.html",
"hr": "modules/unified_reports/templates/unified_reports/partials/hr.html",
"system": "modules/unified_reports/templates/unified_reports/partials/system.html",
"audit": "modules/unified_reports/templates/unified_reports/partials/audit.html",
}
@@ -55,6 +72,8 @@ def _payload(db, current_user):
"current_user_permissions": permissions,
"report_cards": cards,
"report_groups": groups,
"report_area_groups": cards_by_area(cards),
"recommended_cards": recommended_cards(cards),
"report_tabs": get_report_tabs(cards),
"report_summary": get_report_summary(cards),
}
@@ -72,13 +91,13 @@ def _base_context(request: Request, db, current_user, **extra):
@router.get("")
def reports_home(request: Request, tab: str = "my-reports"):
def reports_home(request: Request, tab: str = "overview"):
db = CommonSessionLocal()
try:
current_user, response = _current_user_or_response(request, db)
if response:
return response
active_tab = tab if tab in _ALLOWED_TABS else "my-reports"
active_tab = tab if tab in _ALLOWED_TABS else "overview"
return templates.TemplateResponse(
"modules/unified_reports/templates/unified_reports/dashboard.html",
_base_context(request, db, current_user, title="Reports Centre", active_tab=active_tab),
@@ -94,10 +113,12 @@ def reports_tab(request: Request, tab_name: str):
current_user, response = _current_user_or_response(request, db)
if response:
return response
active_tab = tab_name if tab_name in _ALLOWED_TABS else "my-reports"
active_tab = tab_name if tab_name in _ALLOWED_TABS else "overview"
group_key = _ALLOWED_TABS[active_tab]
cards = get_visible_report_cards(get_user_roles(db, current_user.id), get_user_permissions(db, current_user.id))
group_cards = cards_by_group(cards)
return templates.TemplateResponse(
f"modules/unified_reports/templates/unified_reports/partials/{active_tab.replace('-', '_')}.html",
_PARTIALS[active_tab],
_base_context(
request,
db,
@@ -105,7 +126,7 @@ def reports_tab(request: Request, tab_name: str):
title="Reports Centre",
active_tab=active_tab,
active_group=group_key,
active_cards=cards_by_group(get_visible_report_cards(get_user_roles(db, current_user.id), get_user_permissions(db, current_user.id))).get(group_key, []),
active_cards=cards if group_key == "overview" else group_cards.get(group_key, []),
),
)
finally: