From f4ab617c59637b97858dcae1e1cd6f531ea08b56 Mon Sep 17 00:00:00 2001 From: Till Tomczak Date: Sat, 10 May 2025 22:52:11 +0200 Subject: [PATCH] =?UTF-8?q?chore:=20=C3=84nderungen=20commited?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 176 +++++++++++++++++++++++++++++++++++++++++++ database/systades.db | Bin 131072 -> 131072 bytes 2 files changed, 176 insertions(+) diff --git a/app.py b/app.py index b715181..9118097 100644 --- a/app.py +++ b/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//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//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//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""" diff --git a/database/systades.db b/database/systades.db index 0250a760bfbfa885443d1180cb430b3e108f90ea..efc21de3fa4f1c7f62c3555185847cebe965e48d 100644 GIT binary patch delta 73 zcmZo@;Am*zm>|t4Gf~EwQD$SpGJdw347@k_R&N#*ILpi5=+DTBuQADk?hp Xi|kyUlGNf77;c^@w|$}