2026-02-25 15:26:24 +01:00
|
|
|
from nicegui import ui, app
|
2026-03-01 20:34:42 +01:00
|
|
|
from gui import gui_style
|
2026-03-03 15:49:40 +01:00
|
|
|
from data import data_api
|
2026-03-06 12:01:58 +01:00
|
|
|
from match_calculations import calc_match
|
2026-02-25 15:26:24 +01:00
|
|
|
|
2026-03-03 15:49:40 +01:00
|
|
|
def setup_routes():
|
2026-02-25 15:26:24 +01:00
|
|
|
|
2026-03-02 10:16:30 +01:00
|
|
|
# 1. Die {}-Klammern definieren eine dynamische Variable in der URL
|
2026-03-08 16:23:39 +01:00
|
|
|
@ui.page('/add-match/{systemname}', dark=True)
|
2026-03-02 10:16:30 +01:00
|
|
|
def match_form_page(systemname: str): # <--- WICHTIG: Hier fangen wir das Wort aus der URL auf!
|
2026-03-01 20:34:42 +01:00
|
|
|
gui_style.apply_design()
|
2026-03-02 16:17:50 +01:00
|
|
|
|
|
|
|
|
# --- SICHERHEITS-CHECK ---
|
|
|
|
|
if not app.storage.user.get('authenticated', False):
|
|
|
|
|
ui.label('Access Denied. Please log in first.').classes('text-red-500')
|
|
|
|
|
ui.button('Back to Home', on_click=lambda: ui.navigate.to('/'))
|
|
|
|
|
return
|
2026-02-25 15:26:24 +01:00
|
|
|
|
2026-03-06 12:01:58 +01:00
|
|
|
# ÄNDERUNG: w-full (für Handy) + max-w-md (für PC) + mx-auto (Zentrieren) + p-6 (Innenabstand)
|
|
|
|
|
with ui.card().classes('w-full max-w-md mx-auto items-center mt-10 p-6 shadow-xl'):
|
2026-02-25 15:26:24 +01:00
|
|
|
|
2026-03-06 12:01:58 +01:00
|
|
|
# Text-Center hinzugefügt, falls der Systemname sehr lang ist und auf dem Handy umbricht
|
|
|
|
|
ui.label(f'Neues Spiel für {systemname} eintragen').classes('text-2xl font-bold text-center mb-6')
|
2026-03-03 15:49:40 +01:00
|
|
|
|
2026-03-06 12:01:58 +01:00
|
|
|
ui.label("Meine Punkte:").classes('text-xl font-bold w-full text-left')
|
|
|
|
|
|
|
|
|
|
# ÄNDERUNG: h-60 entfernt, stattdessen gap-6 (Abstand zwischen den Elementen)
|
|
|
|
|
with ui.column().classes("w-full items-center gap-6"):
|
2026-03-03 15:49:40 +01:00
|
|
|
|
|
|
|
|
# 1. Daten aus der DB holen
|
|
|
|
|
raw_players = data_api.get_all_players_from_system(systemname)
|
|
|
|
|
my_id = app.storage.user.get('db_id')
|
|
|
|
|
|
2026-03-06 12:01:58 +01:00
|
|
|
# 3. Eine saubere Optionen-Liste für NiceGUI bauen
|
2026-03-03 15:49:40 +01:00
|
|
|
dropdown_options = {}
|
|
|
|
|
|
|
|
|
|
for p in raw_players:
|
|
|
|
|
if p['player_id'] == my_id:
|
2026-03-06 12:01:58 +01:00
|
|
|
continue
|
2026-03-03 15:49:40 +01:00
|
|
|
dropdown_options[p['player_id']] = f"{p['display_name']} aka {p['discord_name']}"
|
|
|
|
|
|
2026-03-06 12:01:58 +01:00
|
|
|
# ÄNDERUNG: .classes('w-full') hinzugefügt, damit der Slider sich anpasst
|
|
|
|
|
p1_points = ui.slider(min=0, max=100, value=10).props("label-always").classes('w-full')
|
|
|
|
|
|
|
|
|
|
ui.separator().classes('w-full mt-4') # Ein schöner Trennstrich für die Optik
|
|
|
|
|
|
|
|
|
|
# 5. Dropdown und Gegner Punkte
|
|
|
|
|
ui.label("Gegner:").classes('text-xl font-bold w-full text-left')
|
2026-03-03 15:49:40 +01:00
|
|
|
|
2026-03-06 12:01:58 +01:00
|
|
|
# ÄNDERUNG: w-64 durch w-full ersetzt
|
|
|
|
|
opponent_select = ui.select(options=dropdown_options, label='Gegner auswählen').classes('w-full')
|
2026-03-03 15:49:40 +01:00
|
|
|
|
2026-03-06 12:01:58 +01:00
|
|
|
# ÄNDERUNG: .classes('w-full') hinzugefügt
|
|
|
|
|
p2_points = ui.slider(min=0, max=100, value=10).props("label-always").classes('w-full')
|
2026-03-03 15:49:40 +01:00
|
|
|
|
|
|
|
|
ui.space()
|
|
|
|
|
|
2026-03-05 16:19:40 +01:00
|
|
|
# Das Match in die Datenbank eintragen lassen und die MMR Berechnung triggern.
|
2026-03-03 15:49:40 +01:00
|
|
|
def input_match_to_database():
|
|
|
|
|
p2_id = opponent_select.value
|
|
|
|
|
if p2_id is None:
|
|
|
|
|
ui.notify("Bitte wähle zuerst einen Gegner aus!", color="red", position="top")
|
2026-03-06 12:01:58 +01:00
|
|
|
return
|
2026-03-03 15:49:40 +01:00
|
|
|
|
|
|
|
|
score_p1 = p1_points.value
|
|
|
|
|
score_p2 = p2_points.value
|
|
|
|
|
|
2026-03-05 16:19:40 +01:00
|
|
|
match_id = data_api.add_new_match(systemname, my_id, p2_id, score_p1, score_p2)
|
2026-03-03 15:49:40 +01:00
|
|
|
|
2026-03-06 12:01:58 +01:00
|
|
|
# 4. Erfolgsmeldung und Berechnung
|
2026-03-03 15:49:40 +01:00
|
|
|
ui.notify("Match erfolgreich eingetragen!", color="green")
|
2026-03-06 21:20:48 +01:00
|
|
|
ui.navigate.to(f'/statistic/{systemname}')
|
2026-03-03 15:49:40 +01:00
|
|
|
|
2026-03-06 12:01:58 +01:00
|
|
|
# Buttons ganz unten in einer Reihe
|
|
|
|
|
with ui.row().classes("w-full items-center justify-between mt-8"):
|
2026-03-06 12:09:25 +01:00
|
|
|
ui.button('Cancel', on_click=lambda: ui.navigate.to(f'/statistic/{systemname}')).classes('bg-gray-500 text-white')
|
2026-03-06 12:01:58 +01:00
|
|
|
ui.button(text="Absenden", color="positive", on_click=lambda: input_match_to_database())
|