wir haben unterkategorien
This commit is contained in:
61
app.py
61
app.py
@@ -2134,14 +2134,14 @@ def get_root_mindmap_data():
|
||||
|
||||
print(f"Gefundene Hauptkategorien: {[cat.name for cat in categories]}")
|
||||
|
||||
# Basis-Knoten erstellen
|
||||
# Basis-Knoten erstellen (ohne has_children gesetzt, da Wissen selbst keine Unterkategorien haben soll)
|
||||
nodes = [{
|
||||
'id': 'root',
|
||||
'name': 'Wissen',
|
||||
'description': 'Zentrale Wissensbasis',
|
||||
'color_code': '#4299E1',
|
||||
'is_center': True,
|
||||
'has_children': bool(categories),
|
||||
'has_children': False, # Geändert, damit "Wissen" selbst keine Unterkategorien hat
|
||||
'icon': 'fa-solid fa-circle'
|
||||
}]
|
||||
|
||||
@@ -2153,7 +2153,7 @@ def get_root_mindmap_data():
|
||||
'description': category.description or '',
|
||||
'color_code': category.color_code or '#9F7AEA',
|
||||
'category': category.name,
|
||||
'has_children': bool(len(category.children) > 0),
|
||||
'has_children': bool(len(category.children) > 0), # Diese Kategorien haben Unterkategorien
|
||||
'icon': category.icon or 'fa-solid fa-circle'
|
||||
})
|
||||
|
||||
@@ -2207,7 +2207,62 @@ def get_mindmap_data(node_id):
|
||||
'error': 'Ungültige Knoten-ID',
|
||||
'details': 'Diese ID ist für spezielle Routen reserviert'
|
||||
}), 400
|
||||
|
||||
# Prüfen, ob es sich um eine Kategorie-ID handelt (Format: cat_X)
|
||||
if node_id.startswith('cat_'):
|
||||
category_id = None
|
||||
try:
|
||||
category_id = int(node_id.split('_')[1])
|
||||
except (IndexError, ValueError) as e:
|
||||
print(f"Fehler beim Parsen der Kategorie-ID '{node_id}': {str(e)}")
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': 'Ungültige Kategorie-ID',
|
||||
'details': f"Die ID '{node_id}' konnte nicht als Kategorie identifiziert werden"
|
||||
}), 400
|
||||
|
||||
# Kategorie mit Unterkategorien laden
|
||||
category = Category.query.options(
|
||||
joinedload(Category.children)
|
||||
).get_or_404(category_id)
|
||||
|
||||
# Basis-Knoten erstellen
|
||||
nodes = [{
|
||||
'id': f'cat_{category.id}',
|
||||
'name': category.name,
|
||||
'description': category.description or '',
|
||||
'color_code': category.color_code or '#9F7AEA',
|
||||
'is_center': True,
|
||||
'has_children': bool(category.children),
|
||||
'icon': category.icon or 'fa-solid fa-circle'
|
||||
}]
|
||||
|
||||
# Unterkategorien hinzufügen
|
||||
for subcat in category.children:
|
||||
nodes.append({
|
||||
'id': f'cat_{subcat.id}',
|
||||
'name': subcat.name,
|
||||
'description': subcat.description or '',
|
||||
'color_code': subcat.color_code or '#9F7AEA',
|
||||
'category': category.name,
|
||||
'has_children': bool(subcat.children),
|
||||
'icon': subcat.icon or 'fa-solid fa-circle'
|
||||
})
|
||||
|
||||
# Kanten erstellen (vereinheitlichte Schlüssel)
|
||||
edges = [{
|
||||
'source': f'cat_{category.id}',
|
||||
'target': f'cat_{subcat.id}',
|
||||
'strength': 0.8
|
||||
} for subcat in category.children]
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'nodes': nodes,
|
||||
'edges': edges
|
||||
})
|
||||
|
||||
# Sonst: Normale Knoten-ID
|
||||
# Knoten mit Unterknoten in einer Abfrage laden
|
||||
node = MindMapNode.query.options(
|
||||
joinedload(MindMapNode.children)
|
||||
|
||||
Reference in New Issue
Block a user