chore: Änderungen commited
This commit is contained in:
176
app.py
176
app.py
@@ -2054,6 +2054,182 @@ def get_mindmap_node(node_id):
|
||||
'error': 'Mindmap-Daten konnten nicht geladen werden'
|
||||
}), 500
|
||||
|
||||
# API-Endpunkte für Notizen und Layout-Speicherung
|
||||
|
||||
@app.route('/api/mindmap/node/<int:node_id>/notes', methods=['GET'])
|
||||
@login_required
|
||||
def get_node_notes(node_id):
|
||||
"""Ruft die Notizen für einen Mindmap-Knoten ab"""
|
||||
try:
|
||||
# Prüfen, ob der Knoten existiert
|
||||
node = MindMapNode.query.get_or_404(node_id)
|
||||
|
||||
# Prüfen, ob der Knoten in einer Mindmap des Benutzers ist
|
||||
user_node = UserMindmapNode.query.filter_by(node_id=node_id).join(
|
||||
UserMindmap, UserMindmapNode.user_mindmap_id == UserMindmap.id
|
||||
).filter(UserMindmap.user_id == current_user.id).first()
|
||||
|
||||
if not user_node and not current_user.is_admin:
|
||||
return jsonify({'success': False, 'message': 'Keine Berechtigung'}), 403
|
||||
|
||||
# Prüfen, ob eine Notiz für diesen Knoten existiert
|
||||
note = MindmapNote.query.filter_by(
|
||||
user_id=current_user.id,
|
||||
node_id=node_id
|
||||
).first()
|
||||
|
||||
if note:
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'notes': note.content,
|
||||
'color_code': note.color_code
|
||||
})
|
||||
else:
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'notes': '',
|
||||
'color_code': '#FFF59D' # Standard-Gelb
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
print(f"Fehler in get_node_notes: {str(e)}")
|
||||
return jsonify({'success': False, 'message': str(e)}), 500
|
||||
|
||||
@app.route('/api/mindmap/node/<int:node_id>/notes', methods=['POST'])
|
||||
@login_required
|
||||
def update_node_notes(node_id):
|
||||
"""Aktualisiert die Notizen für einen Mindmap-Knoten"""
|
||||
try:
|
||||
# Prüfen, ob der Knoten existiert
|
||||
node = MindMapNode.query.get_or_404(node_id)
|
||||
|
||||
# Prüfen, ob der Knoten in einer Mindmap des Benutzers ist
|
||||
user_node = UserMindmapNode.query.filter_by(node_id=node_id).join(
|
||||
UserMindmap, UserMindmapNode.user_mindmap_id == UserMindmap.id
|
||||
).filter(UserMindmap.user_id == current_user.id).first()
|
||||
|
||||
if not user_node and not current_user.is_admin:
|
||||
return jsonify({'success': False, 'message': 'Keine Berechtigung'}), 403
|
||||
|
||||
# Daten aus dem Request abrufen
|
||||
data = request.json
|
||||
notes_content = data.get('notes', '')
|
||||
color_code = data.get('color_code', '#FFF59D') # Standard-Gelb
|
||||
|
||||
# Prüfen, ob bereits eine Notiz für diesen Knoten existiert
|
||||
note = MindmapNote.query.filter_by(
|
||||
user_id=current_user.id,
|
||||
node_id=node_id
|
||||
).first()
|
||||
|
||||
if note:
|
||||
# Vorhandene Notiz aktualisieren
|
||||
note.content = notes_content
|
||||
note.color_code = color_code
|
||||
else:
|
||||
# Neue Notiz erstellen - hier brauchen wir die Mindmap-ID
|
||||
mindmap_id = user_node.user_mindmap_id
|
||||
note = MindmapNote(
|
||||
user_id=current_user.id,
|
||||
mindmap_id=mindmap_id,
|
||||
node_id=node_id,
|
||||
content=notes_content,
|
||||
color_code=color_code
|
||||
)
|
||||
db.session.add(note)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'message': 'Notizen erfolgreich gespeichert'
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
print(f"Fehler in update_node_notes: {str(e)}")
|
||||
return jsonify({'success': False, 'message': str(e)}), 500
|
||||
|
||||
@app.route('/api/mindmap/<int:mindmap_id>/layout', methods=['POST'])
|
||||
@login_required
|
||||
def save_mindmap_layout(mindmap_id):
|
||||
"""Speichert das Layout (Positionen der Knoten) einer Mindmap"""
|
||||
try:
|
||||
# Prüfe, ob die Mindmap dem Benutzer gehört
|
||||
mindmap = UserMindmap.query.get_or_404(mindmap_id)
|
||||
if mindmap.user_id != current_user.id and not current_user.is_admin:
|
||||
return jsonify({'success': False, 'message': 'Keine Berechtigung'}), 403
|
||||
|
||||
# Daten aus dem Request abrufen
|
||||
data = request.json
|
||||
nodes_data = data.get('nodes', [])
|
||||
|
||||
# Positionen aller Knoten aktualisieren
|
||||
for node_data in nodes_data:
|
||||
node_id = node_data.get('id')
|
||||
x_pos = node_data.get('x')
|
||||
y_pos = node_data.get('y')
|
||||
|
||||
if node_id and x_pos is not None and y_pos is not None:
|
||||
# UserMindmapNode-Eintrag aktualisieren
|
||||
user_node = UserMindmapNode.query.filter_by(
|
||||
user_mindmap_id=mindmap_id,
|
||||
node_id=node_id
|
||||
).first()
|
||||
|
||||
if user_node:
|
||||
user_node.x_position = x_pos
|
||||
user_node.y_position = y_pos
|
||||
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'message': 'Layout erfolgreich gespeichert'
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
print(f"Fehler in save_mindmap_layout: {str(e)}")
|
||||
return jsonify({'success': False, 'message': str(e)}), 500
|
||||
|
||||
@app.route('/api/public-mindmap', methods=['GET'])
|
||||
def get_public_mindmap():
|
||||
"""Liefert die öffentliche Mindmap für die Knotenübernahme"""
|
||||
try:
|
||||
# Alle öffentlichen Knoten abrufen
|
||||
public_nodes = MindMapNode.query.filter_by(is_public=True).all()
|
||||
|
||||
# Knoten formatieren
|
||||
nodes = []
|
||||
for node in public_nodes:
|
||||
nodes.append({
|
||||
'id': node.id,
|
||||
'name': node.name,
|
||||
'description': node.description or '',
|
||||
'color_code': node.color_code or '#9F7AEA'
|
||||
})
|
||||
|
||||
# Alle Beziehungen zwischen Knoten abrufen
|
||||
edges = []
|
||||
for node in public_nodes:
|
||||
for child in node.children:
|
||||
if child.is_public:
|
||||
edges.append({
|
||||
'source': node.id,
|
||||
'target': child.id
|
||||
})
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'nodes': nodes,
|
||||
'edges': edges
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
print(f"Fehler in get_public_mindmap: {str(e)}")
|
||||
return jsonify({'success': False, 'message': str(e)}), 500
|
||||
|
||||
# Automatische Datenbankinitialisierung - Aktualisiert für Flask 2.2+ Kompatibilität
|
||||
def initialize_app():
|
||||
"""Initialisierung der Anwendung"""
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user