From ad2089ec1ffaabf78300ee69361f701a4ca12bd0 Mon Sep 17 00:00:00 2001 From: Daniel Nagel Date: Sun, 8 Mar 2026 16:30:52 +0100 Subject: [PATCH] =?UTF-8?q?Spieler=20k=C3=B6nnen=20jetzt=20selbst=20einget?= =?UTF-8?q?ragene=20Spieler=20selber=20l=C3=B6schen=20solange=20der=20Gegn?= =?UTF-8?q?er=20es=20noch=20nicht=20best=C3=A4tigt=20hat.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/data_api.py | 24 ++++++++++++++++++++++++ gui/main_gui.py | 27 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/data/data_api.py b/data/data_api.py index dd2a4df..101b151 100644 --- a/data/data_api.py +++ b/data/data_api.py @@ -536,3 +536,27 @@ def set_match_counted(match_id): connection.commit() connection.close() + + +def get_submitted_matches(player_id): + """Holt alle offenen Matches, die der Spieler selbst eingetragen hat, aber vom Gegner noch nicht bestätigt wurden.""" + connection = sqlite3.connect(DB_PATH) + connection.row_factory = sqlite3.Row + cursor = connection.cursor() + + # ACHTUNG: Wir joinen hier p2 (player2), weil wir den Namen des Gegners anzeigen wollen! + query = """ + SELECT m.id AS match_id, m.score_player1, m.score_player2, m.played_at, + sys.name AS system_name, + p2.display_name AS p2_name + FROM matches m + JOIN gamesystems sys ON m.gamesystem_id = sys.id + JOIN players p2 ON m.player2_id = p2.id + WHERE m.player1_id = ? AND m.player2_check = 0 + """ + + cursor.execute(query, (player_id,)) + rows = cursor.fetchall() + connection.close() + + return [dict(row) for row in rows] diff --git a/gui/main_gui.py b/gui/main_gui.py index 731118d..202ab8b 100644 --- a/gui/main_gui.py +++ b/gui/main_gui.py @@ -131,6 +131,33 @@ def setup_routes(admin_discord_id): # BESTÄTIGEN und spiel berechnen lassen ui.button("Bestätigen", color="positive", icon="check", on_click=lambda e, m_id=match['match_id']: acccept_match(m_id)) + # --------------------------- + # --- Selbst eingetragene, offene Spiele --- + # --------------------------- + submitted_matches = data_api.get_submitted_matches(player_id) + + if len(submitted_matches) > 0: + # Eine etwas dezentere Karte (grau) + with ui.card().classes('w-full bg-zinc-800 border border-gray-600 mb-6'): + ui.label(f"Warten auf Gegner: Du hast {len(submitted_matches)} offene(s) Spiel(e) eingetragen.").classes('text-xl font-bold text-gray-300 mb-2') + + for match in submitted_matches: + + # Die Lösch-Funktion, die beim Klick ausgeführt wird + def retract_match(m_id): + data_api.delete_match(m_id) + ui.notify("Eingetragenes Spiel zurückgezogen!", color="warning") + ui.navigate.reload() + + # Für jedes Match machen wir eine kleine Reihe + with ui.row().classes('w-full items-center justify-between bg-zinc-900 p-3 rounded shadow-inner'): + + # Info-Text: Auf wen warten wir? + info_text = f"[{match['system_name']}] Warten auf Bestätigung von {match['p2_name']} ({match['score_player1']} : {match['score_player2']})" + ui.label(info_text).classes('text-lg text-gray-400') + + # Der Zurückziehen-Button (wieder mit unserem lambda m_id=... Trick!) + ui.button("Zurückziehen", color="warning", icon="delete", on_click=lambda e, m_id=match['match_id']: retract_match(m_id)) # ---------------------------