Liga Buttons. Anmeldung, ......

This commit is contained in:
Daniel Nagel 2026-03-02 15:17:50 +00:00
parent df608709a7
commit 3823dac7e3
6 changed files with 135 additions and 30 deletions

View File

@ -1 +1 @@
{"authenticated":true,"discord_id":"277898241750859776","discord_name":"mrteels","db_id":1,"display_name":"Daniel Nagel","discord_avatar_url":"https://cdn.discordapp.com/avatars/277898241750859776/7c3446bb51fafd72b1b4c21124b4994f.png"} {"authenticated":true,"discord_id":"277898241750859776","discord_name":"mrteels","db_id":1,"display_name":"Chaos Regelvergesser","discord_avatar_url":"https://cdn.discordapp.com/avatars/277898241750859776/7c3446bb51fafd72b1b4c21124b4994f.png"}

View File

@ -61,4 +61,70 @@ def get_all_players():
# Die Daten für das Web-GUI in eine lesbare Form umwandeln (Liste von Dictionaries) # Die Daten für das Web-GUI in eine lesbare Form umwandeln (Liste von Dictionaries)
result = [] result = []
return result return result
import sqlite3
from data.setup_database import DB_PATH
def get_gamesystem_data():
connection = sqlite3.connect(DB_PATH)
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
cursor.execute("SELECT * FROM gamesystems")
rows = cursor.fetchall()
connection.close()
# SQLite-Rows in normale Python-Dictionaries um
result = []
for row in rows:
result.append(dict(row))
return result
def get_player_statistics(player_id):
connection = sqlite3.connect(DB_PATH)
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
query = """
SELECT
sys.id AS gamesystem_id,
sys.name AS gamesystem_name,
sys.*,
stat.mmr,
stat.games_in_system,
stat.points
FROM gamesystems sys
LEFT JOIN player_game_statistic stat
ON sys.id = stat.gamesystem_id AND stat.player_id = ?
"""
cursor.execute(query, (player_id,))
rows = cursor.fetchall()
connection.close()
result = []
for row in rows:
result.append(dict(row))
return result
def join_league(player_id, gamesystem_id):
connection = sqlite3.connect(DB_PATH)
cursor = connection.cursor()
# Wir fügen nur die beiden IDs ein, der Rest wird von den DEFAULT-Werten der DB erledigt
query = """
INSERT INTO player_game_statistic (player_id, gamesystem_id)
VALUES (?, ?)
"""
cursor.execute(query, (player_id, gamesystem_id))
connection.commit()
connection.close()

View File

@ -26,6 +26,8 @@ def init_db():
CREATE TABLE IF NOT EXISTS gamesystems ( CREATE TABLE IF NOT EXISTS gamesystems (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL, name TEXT NOT NULL,
picture TEXT,
description TEXT,
min_score INTEGER DEFAULT 0, min_score INTEGER DEFAULT 0,
max_score INTEGER DEFAULT 100 max_score INTEGER DEFAULT 100
) )
@ -102,13 +104,13 @@ def seed_gamesystems():
connection = sqlite3.connect(DB_PATH) connection = sqlite3.connect(DB_PATH)
cursor = connection.cursor() cursor = connection.cursor()
systems = [ systems = [
("Warhammer 40k", 0, 100), ("Warhammer 40k","/gui/pictures/wsdg.png","Die Schlacht um die Galaxie in einer entfernten Zukunft." , 0, 100),
("Age of Sigmar", 0, 50), ("Age of Sigmar","/gui/pictures/wsdg.png","" , 0, 50),
("Spearhead", 0, 50) ("Spearhead","/gui/pictures/wsdg.png","" , 0, 50)
] ]
# executemany ist eine extrem schnelle SQL For-Schleife für Inserts # executemany ist eine extrem schnelle SQL For-Schleife für Inserts
cursor.executemany("INSERT INTO gamesystems (name, min_score, max_score) VALUES (?, ?, ?)", systems) cursor.executemany("INSERT INTO gamesystems (name, picture, description, min_score, max_score) VALUES (?, ?, ?, ?, ?)", systems)
connection.commit() connection.commit()
connection.close() connection.close()

View File

@ -1,4 +1,5 @@
from nicegui import ui, app from nicegui import ui, app
from gui import gui_style
def setup_statistic_routes(): def setup_statistic_routes():
@ -11,9 +12,12 @@ def setup_statistic_routes():
ui.navigate.to('/') ui.navigate.to('/')
return return
ui.dark_mode(True) gui_style.apply_design()
print(systemname)
# 2. Seite aufbauen with ui.header().classes('items-center justify-between bg-zinc-900 p-4 shadow-lg'):
ui.button('Zurück zur Übersicht', on_click=lambda: ui.navigate.to('/')).classes('mt-8 bg-gray-600 text-white')
ui.button("Spiel eintragen", on_click=lambda: ui.navigate.to('/add-match/{systemname}'))
with ui.column().classes('w-full items-center mt-10'): with ui.column().classes('w-full items-center mt-10'):
# Hier nutzen wir die Variable 'systemname', um den Titel anzupassen # Hier nutzen wir die Variable 'systemname', um den Titel anzupassen
ui.label(f'Deine Statistik in {systemname}').classes('text-3xl font-bold text-blue-400') ui.label(f'Deine Statistik in {systemname}').classes('text-3xl font-bold text-blue-400')
@ -25,4 +29,4 @@ def setup_statistic_routes():
ui.label('Winrate: -- %').classes('text-xl mt-4') ui.label('Winrate: -- %').classes('text-xl mt-4')
ui.label('Durchschnittspunkte: --').classes('text-xl') ui.label('Durchschnittspunkte: --').classes('text-xl')
ui.button('Zurück zur Übersicht', on_click=lambda: ui.navigate.to('/')).classes('mt-8 bg-gray-600 text-white')

View File

@ -16,12 +16,12 @@ def setup_routes():
ui.image("gui/pictures/wsdg.png").classes('w-20 h-20 rounded-full') ui.image("gui/pictures/wsdg.png").classes('w-20 h-20 rounded-full')
ui.label('Diceghost Liga').classes('text-2xl font-bold text-white') ui.label('Diceghost Liga').classes('text-2xl font-bold text-white')
# --- RECHTE SEITE --- # --- RECHTE SEITE ---
if app.storage.user.get('authenticated', False): if app.storage.user.get('authenticated', False):
with ui.row().classes('items-center gap-4'): with ui.row().classes('items-center gap-4'):
discord_name = app.storage.user.get('discord_name') discord_name = app.storage.user.get('discord_name')
display_name = app.storage.user.get('display_name') display_name = app.storage.user.get('display_name')
db_id = app.storage.user.get('db_id') player_id = app.storage.user.get('db_id')
# 1. Wir definieren eine kleine Funktion, die zwischen Text und Eingabe hin- und herschaltet # 1. Wir definieren eine kleine Funktion, die zwischen Text und Eingabe hin- und herschaltet
def toggle_edit_mode(): def toggle_edit_mode():
@ -73,22 +73,55 @@ def setup_routes():
ui.button('Login with Discord', on_click=lambda: ui.navigate.to(auth_url)) ui.button('Login with Discord', on_click=lambda: ui.navigate.to(auth_url))
# ---------------------------------- # ----------------------------------
# --- Spielsysteme --- # --- Spielsysteme ---
if app.storage.user.get('authenticated', False): if app.storage.user.get('authenticated', False):
with ui.card().classes("w-full"): with ui.card().classes("w-full"):
ui.label(text="Meine Ligaplätze").classes("font-bold text-white") ui.label(text="Meine Ligaplätze").classes("font-bold text-white text-xl")
with ui.row().classes("w-full h-30 gap-4 items-center"):
#Einfügen: Eine UI Card PRO Spielsystem des Spielers. placements = data_api.get_player_statistics(player_id)
with ui.card().classes("flex-1 h-24 items-center justify-center cursor-pointer hover:bg-zinc-800 transition-colors").on('click', lambda: ui.navigate.to('/statistic/Warhammer 40k')): systems = data_api.get_gamesystem_data()
ui.label(text="Warhammer 40k").classes('text-xl font-bold')
def click_join_league(p_id, sys_id):
data_api.join_league(p_id, sys_id)
ui.navigate.to("/")
with ui.grid(columns=3).classes("w-full gap-4 items-center"):
for place in placements:
sys_card = ui.card().classes("h-60 w-full items-center justify-center transition-colors")
with sys_card:
# Kopfzeile der Karte (Name & Beschreibung)
ui.label(text=place['gamesystem_name']).classes('text-xl font-bold')
if 'description' in place and place['description']:
ui.label(text=place['description']).classes('text-xs text-gray-400')
ui.space()
if place['mmr'] is None:
ui.label(text="Du bist noch nicht in dieser Liga.").classes("text-red-500 font-bold")
# --- HIER IST DER MAGISCHE TRICK ---
# Das 'e' fängt das NiceGUI-Event ab und wirft es weg.
# p=player_id und s=place['gamesystem_id'] frieren die IDs für DIESEN Button bombenfest ein!
ui.button("Liga Beitreten", on_click=lambda e, p=player_id, s=place['gamesystem_id']: click_join_league(p, s))
else:
# Spieler IST in der Liga!
sys_card.classes("cursor-pointer hover:bg-zinc-800")
# Auch hier machen wir es mit dem 'e' absolut sicher:
sys_card.on('click', lambda e, name=place['gamesystem_name']: ui.navigate.to(f'/statistic/{name}'))
# Wir zeigen die Stats.
with ui.row().classes('items-center gap-4'):
ui.label(text=f"MMR: {place['mmr']}")
ui.label(text=f"Spiele: {place['games_in_system']}")
ui.label(text=f"Punkte: {place['points']}")
with ui.card().classes("flex-1 h-24 items-center justify-center cursor-pointer hover:bg-zinc-800 transition-colors").on('click', lambda: ui.navigate.to('/statistic/Age of Sigmar')):
ui.label(text="Age of Sigmar").classes('text-xl font-bold')
with ui.card().classes("flex-1 h-24 items-center justify-center cursor-pointer hover:bg-zinc-800 transition-colors").on('click', lambda: ui.navigate.to('/statistic/Spearhead')):
ui.label(text="Spearhead").classes('text-xl font-bold')

View File

@ -7,16 +7,16 @@ def setup_match_routes():
@ui.page('/add-match/{systemname}') @ui.page('/add-match/{systemname}')
def match_form_page(systemname: str): # <--- WICHTIG: Hier fangen wir das Wort aus der URL auf! def match_form_page(systemname: str): # <--- WICHTIG: Hier fangen wir das Wort aus der URL auf!
gui_style.apply_design() gui_style.apply_design()
# --- SICHERHEITS-CHECK ---
# Prüfen, ob der User wirklich eingeloggt ist.
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
with ui.card().classes('w-full items-center mt-10'): with ui.card().classes('w-full items-center mt-10'):
ui.label('Enter New Match').classes('text-2xl font-bold') ui.label('Neues Spiel für '+ systemname + " eintragen").classes('text-2xl font-bold')
# --- SICHERHEITS-CHECK ---
# Prüfen, ob der User wirklich eingeloggt ist.
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
# --- PLATZHALTER --- # --- PLATZHALTER ---
ui.label('Hier kommt im nächsten Schritt das Eingabe-Formular hin!').classes('text-gray-500 my-4') ui.label('Hier kommt im nächsten Schritt das Eingabe-Formular hin!').classes('text-gray-500 my-4')