chore: Änderungen commited
This commit is contained in:
105
app.py
105
app.py
@@ -2298,6 +2298,111 @@ def get_public_mindmap_nodes():
|
||||
print(f"Fehler in get_public_mindmap_nodes: {str(e)}")
|
||||
return jsonify({'success': False, 'message': str(e)}), 500
|
||||
|
||||
# Suchfunktion für Mindmap-Knoten
|
||||
@app.route('/api/search/mindmap', methods=['GET'])
|
||||
def search_mindmap_nodes():
|
||||
"""
|
||||
Durchsucht Mindmap-Knoten nach einem Suchbegriff.
|
||||
|
||||
Query-Parameter:
|
||||
- q: Suchbegriff
|
||||
- user_only: Wenn "true", werden nur Knoten aus den Mindmaps des Benutzers durchsucht
|
||||
- include_public: Wenn "true", werden auch öffentliche Knoten einbezogen (Standard: true)
|
||||
"""
|
||||
try:
|
||||
# Parameter auslesen
|
||||
query = request.args.get('q', '').strip()
|
||||
user_only = request.args.get('user_only', 'false').lower() == 'true'
|
||||
include_public = request.args.get('include_public', 'true').lower() == 'true'
|
||||
|
||||
if not query:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'message': 'Kein Suchbegriff angegeben',
|
||||
'results': []
|
||||
}), 400
|
||||
|
||||
# Basisfunktion für die Suche
|
||||
results = []
|
||||
|
||||
# Erstelle Such-Pattern (beide Suchbegriffe werden verwendet)
|
||||
search_pattern = f"%{query}%"
|
||||
|
||||
# 1. Knoten aus Benutzer-Mindmaps suchen, falls Benutzer angemeldet ist
|
||||
if current_user.is_authenticated:
|
||||
# Suche in allen Knoten, die in den Mindmaps des Benutzers sind
|
||||
user_nodes_query = db.session.query(
|
||||
MindMapNode, UserMindmapNode
|
||||
).join(
|
||||
UserMindmapNode, UserMindmapNode.node_id == MindMapNode.id
|
||||
).join(
|
||||
UserMindmap, UserMindmapNode.user_mindmap_id == UserMindmap.id
|
||||
).filter(
|
||||
UserMindmap.user_id == current_user.id,
|
||||
db.or_(
|
||||
MindMapNode.name.ilike(search_pattern),
|
||||
MindMapNode.description.ilike(search_pattern)
|
||||
)
|
||||
).all()
|
||||
|
||||
# Formatiere die Ergebnisse
|
||||
for node, user_node in user_nodes_query:
|
||||
# Hole den Mindmap-Namen für diesen Knoten
|
||||
mindmap = UserMindmap.query.get(user_node.user_mindmap_id)
|
||||
|
||||
results.append({
|
||||
'id': node.id,
|
||||
'name': node.name,
|
||||
'description': node.description or '',
|
||||
'color_code': node.color_code or '#9F7AEA',
|
||||
'source': 'user_mindmap',
|
||||
'mindmap_id': user_node.user_mindmap_id,
|
||||
'mindmap_name': mindmap.name if mindmap else 'Unbekannte Mindmap',
|
||||
'position': {
|
||||
'x': user_node.x_position,
|
||||
'y': user_node.y_position
|
||||
}
|
||||
})
|
||||
|
||||
# 2. Öffentliche Knoten suchen, falls gewünscht und nicht nur Benutzer-Mindmaps
|
||||
if include_public and not user_only:
|
||||
public_nodes_query = MindMapNode.query.filter(
|
||||
MindMapNode.is_public == True,
|
||||
db.or_(
|
||||
MindMapNode.name.ilike(search_pattern),
|
||||
MindMapNode.description.ilike(search_pattern)
|
||||
)
|
||||
).all()
|
||||
|
||||
# Prüfen, ob die öffentlichen Knoten bereits in den Ergebnissen sind
|
||||
existing_node_ids = [node['id'] for node in results]
|
||||
|
||||
for node in public_nodes_query:
|
||||
if node.id not in existing_node_ids:
|
||||
results.append({
|
||||
'id': node.id,
|
||||
'name': node.name,
|
||||
'description': node.description or '',
|
||||
'color_code': node.color_code or '#9F7AEA',
|
||||
'source': 'public',
|
||||
'mindmap_id': None,
|
||||
'mindmap_name': 'Öffentliche Mindmap'
|
||||
})
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'message': f'{len(results)} Ergebnisse gefunden',
|
||||
'results': results
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
print(f"Fehler bei der Mindmap-Suche: {str(e)}")
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'message': f'Fehler bei der Suche: {str(e)}',
|
||||
'results': []
|
||||
}), 500
|
||||
|
||||
# Automatische Datenbankinitialisierung - Aktualisiert für Flask 2.2+ Kompatibilität
|
||||
def initialize_app():
|
||||
"""Initialisierung der Anwendung"""
|
||||
|
||||
Reference in New Issue
Block a user