feat: Hierarchical Admin UI - Tree View for Catalogs
Backend: - New endpoint: GET /api/admin/hierarchy - Returns hierarchical structure: Focus Areas with nested Style Directions + Training Types - Style Directions include target_groups assignments (M:N) - JSON aggregation for efficient data loading Frontend: - New page: AdminHierarchyPage.jsx with Tree + Detail Panel layout - Tree View: Expandable/collapsible nodes (Focus Areas → Stilrichtungen/Trainingstypen) - Detail Panel: Shows selected item details, inline editing - Visual hierarchy: Icons, indentation, color coding - Responsive layout: Fixed 400px tree, fluid detail panel Routes: - /admin now redirects to /admin/hierarchy (new default) - /admin/hierarchy: Tree-based catalog management - /admin/catalogs: Legacy flat UI (still available) UX Improvements: - Visual hierarchy instead of flat tabs - M:N relationships visible (target groups per style) - Better navigation: Click to select, expand/collapse sections - Cleaner layout: Two-column design Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0be9fd840c
commit
7314ae1436
4 files changed
+497
-1
No files matched your search
@@ -1298,3 +1298,110 @@ def delete_trainer_context(context_id: int, session=Depends(require_auth)):
|
||||
conn.commit()
|
||||
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
# ════════════════════════════════════════════════════════════════════════
|
||||
# HIERARCHICAL CATALOG VIEW (Admin UI Tree)
|
||||
# ════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@router.get("/admin/hierarchy")
|
||||
def get_admin_hierarchy(session=Depends(require_auth)):
|
||||
"""
|
||||
Get complete hierarchical catalog structure for admin tree view.
|
||||
|
||||
Returns:
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Karate",
|
||||
"icon": "🥋",
|
||||
"description": "...",
|
||||
"style_directions": [
|
||||
{
|
||||
"id": 10,
|
||||
"name": "Shotokan",
|
||||
"abbreviation": "SKA",
|
||||
"description": "...",
|
||||
"target_groups": [
|
||||
{"id": 100, "name": "Kinder", "is_primary": true}
|
||||
]
|
||||
}
|
||||
],
|
||||
"training_types": [
|
||||
{
|
||||
"id": 20,
|
||||
"name": "Breitensport",
|
||||
"abbreviation": "BS",
|
||||
"description": "..."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
"""
|
||||
role = session.get('role')
|
||||
if role not in ['admin', 'superadmin']:
|
||||
raise HTTPException(403, "Nur Admins dürfen die Hierarchie abrufen")
|
||||
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
|
||||
# 1. Get all focus areas
|
||||
cur.execute("""
|
||||
SELECT id, name, icon, description, sort_order, status
|
||||
FROM focus_areas
|
||||
WHERE status = 'active'
|
||||
ORDER BY sort_order, name
|
||||
""")
|
||||
focus_areas = [r2d(r) for r in cur.fetchall()]
|
||||
|
||||
# 2. Get all style directions with their target group assignments
|
||||
cur.execute("""
|
||||
SELECT
|
||||
sd.id,
|
||||
sd.name,
|
||||
sd.abbreviation,
|
||||
sd.description,
|
||||
sd.focus_area_id,
|
||||
sd.sort_order,
|
||||
json_agg(
|
||||
json_build_object(
|
||||
'id', tg.id,
|
||||
'name', tg.name,
|
||||
'is_primary', sdtg.is_primary
|
||||
) ORDER BY tg.name
|
||||
) FILTER (WHERE tg.id IS NOT NULL) as target_groups
|
||||
FROM style_directions sd
|
||||
LEFT JOIN style_direction_target_groups sdtg ON sd.id = sdtg.style_direction_id
|
||||
LEFT JOIN target_groups tg ON sdtg.target_group_id = tg.id
|
||||
WHERE sd.status = 'active'
|
||||
GROUP BY sd.id, sd.name, sd.abbreviation, sd.description, sd.focus_area_id, sd.sort_order
|
||||
ORDER BY sd.sort_order, sd.name
|
||||
""")
|
||||
style_directions = [r2d(r) for r in cur.fetchall()]
|
||||
|
||||
# 3. Get all training types
|
||||
cur.execute("""
|
||||
SELECT id, name, abbreviation, description, focus_area_id, sort_order
|
||||
FROM training_types
|
||||
WHERE status = 'active'
|
||||
ORDER BY sort_order, name
|
||||
""")
|
||||
training_types = [r2d(r) for r in cur.fetchall()]
|
||||
|
||||
# 4. Build hierarchy
|
||||
for fa in focus_areas:
|
||||
fa_id = fa['id']
|
||||
|
||||
# Attach style directions
|
||||
fa['style_directions'] = [
|
||||
sd for sd in style_directions
|
||||
if sd['focus_area_id'] == fa_id
|
||||
]
|
||||
|
||||
# Attach training types
|
||||
fa['training_types'] = [
|
||||
tt for tt in training_types
|
||||
if tt['focus_area_id'] == fa_id
|
||||
]
|
||||
|
||||
return focus_areas
|
||||
Reference in new issue
Block a user