2026-02-25 15:26:24 +01:00
|
|
|
from nicegui import ui, app
|
2026-03-01 20:34:42 +01:00
|
|
|
import database
|
|
|
|
|
from gui import discord_login, gui_style
|
2026-02-25 15:26:24 +01:00
|
|
|
|
|
|
|
|
def setup_routes():
|
|
|
|
|
@ui.page('/')
|
|
|
|
|
def home_page():
|
2026-03-01 20:34:42 +01:00
|
|
|
gui_style.apply_design()
|
2026-02-25 15:26:24 +01:00
|
|
|
|
2026-02-27 12:01:02 +01:00
|
|
|
# --- NAVIGATIONSLEISTE (HEADER) ---
|
|
|
|
|
with ui.header().classes('items-center justify-between bg-zinc-900 p-4 shadow-lg'):
|
2026-02-25 15:26:24 +01:00
|
|
|
|
2026-03-01 20:34:42 +01:00
|
|
|
# --- LINKE SEITE ---
|
|
|
|
|
# Vereinslogo und den Titel in einer eigenen Reihe (Reihe 1)
|
|
|
|
|
with ui.row().classes('items-center gap-4'):
|
|
|
|
|
ui.image("gui/pictures/wsdg.png").classes('w-20 h-20 rounded-full')
|
|
|
|
|
ui.label('Diceghost Liga').classes('text-2xl font-bold text-white')
|
|
|
|
|
|
|
|
|
|
# --- RECHTE SEITE ---
|
2026-02-27 12:01:02 +01:00
|
|
|
if app.storage.user.get('authenticated', False):
|
|
|
|
|
with ui.row().classes('items-center gap-4'):
|
2026-03-01 20:34:42 +01:00
|
|
|
discord_name = app.storage.user.get('discord_name')
|
|
|
|
|
display_name = app.storage.user.get('display_name')
|
|
|
|
|
db_id = app.storage.user.get('db_id')
|
|
|
|
|
|
|
|
|
|
# 1. Wir definieren eine kleine Funktion, die zwischen Text und Eingabe hin- und herschaltet
|
|
|
|
|
def toggle_edit_mode():
|
|
|
|
|
display_row.visible = not display_row.visible
|
|
|
|
|
edit_row.visible = not edit_row.visible
|
|
|
|
|
|
|
|
|
|
# --- ANSICHT 1: Der normale Text mit Edit-Button ---
|
|
|
|
|
with ui.row().classes('items-center gap-2') as display_row:
|
|
|
|
|
ui.label(display_name).classes('text-xl font-bold text-white')
|
|
|
|
|
ui.label('aka').classes('text-sm text-gray-500')
|
|
|
|
|
ui.label(discord_name).classes('text-lg text-gray-400')
|
|
|
|
|
|
|
|
|
|
# Ein runder Button (.props('round')), der exakt wie ein FAB aussieht!
|
|
|
|
|
ui.button(icon='edit', color='primary', on_click=toggle_edit_mode).props('round dense')
|
|
|
|
|
|
|
|
|
|
# --- ANSICHT 2: Das Eingabefeld (startet unsichtbar!) ---
|
|
|
|
|
with ui.row().classes('items-center gap-2') as edit_row:
|
|
|
|
|
edit_row.visible = False # Am Anfang verstecken
|
|
|
|
|
|
|
|
|
|
def save_new_name():
|
|
|
|
|
new_name = name_input.value
|
|
|
|
|
# Nur speichern, wenn ein Name drinsteht und er anders ist als vorher
|
|
|
|
|
if new_name and new_name != display_name:
|
|
|
|
|
import database
|
|
|
|
|
database.change_display_name(db_id, new_name) # Deine DB Funktion
|
|
|
|
|
app.storage.user['display_name'] = new_name
|
|
|
|
|
ui.notify('Name gespeichert!', color='positive')
|
|
|
|
|
ui.navigate.reload()
|
|
|
|
|
else:
|
|
|
|
|
# Wenn nichts geändert wurde, einfach wieder einklappen
|
|
|
|
|
toggle_edit_mode()
|
|
|
|
|
|
|
|
|
|
name_input = ui.input('Neuer Name', value=display_name).on('keydown.enter', save_new_name)
|
|
|
|
|
ui.button(icon='save', color='positive', on_click=save_new_name).props('round dense')
|
|
|
|
|
ui.button(icon='close', color='negative', on_click=toggle_edit_mode).props('round dense')
|
|
|
|
|
# ---------------------------------------------
|
|
|
|
|
|
2026-02-27 12:01:02 +01:00
|
|
|
avatar = app.storage.user.get('avatar_url')
|
|
|
|
|
if avatar:
|
2026-03-01 20:34:42 +01:00
|
|
|
ui.image(avatar).classes('w-12 h-12 rounded-full border-2 border-red-500')
|
|
|
|
|
|
|
|
|
|
def logout():
|
|
|
|
|
app.storage.user.clear()
|
|
|
|
|
ui.navigate.to('/')
|
2026-02-25 15:26:24 +01:00
|
|
|
|
2026-03-01 20:34:42 +01:00
|
|
|
ui.button('Logout', on_click=logout).classes('bg-red-500 text-white')
|
2026-02-25 15:26:24 +01:00
|
|
|
|
|
|
|
|
else:
|
2026-02-27 12:01:02 +01:00
|
|
|
auth_url = discord_login.get_auth_url()
|
|
|
|
|
ui.button('Login with Discord', on_click=lambda: ui.navigate.to(auth_url))
|
2026-03-01 20:34:42 +01:00
|
|
|
# ----------------------------------
|
|
|
|
|
|
2026-02-27 12:01:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# --- Spielsysteme ---
|
2026-02-26 16:20:05 +01:00
|
|
|
if app.storage.user.get('authenticated', False):
|
|
|
|
|
with ui.card().classes("w-full"):
|
2026-02-27 12:01:02 +01:00
|
|
|
ui.label(text="Meine Ligaplätze").classes("font-bold text-white")
|
2026-02-26 16:20:05 +01:00
|
|
|
with ui.row().classes("w-full h-30 gap-4 items-center"):
|
2026-02-27 12:01:02 +01:00
|
|
|
#Einfügen: Eine UI Card PRO Spielsystem des Spielers.
|
|
|
|
|
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')):
|
|
|
|
|
ui.label(text="Warhammer 40k").classes('text-xl font-bold')
|
2026-02-26 16:20:05 +01:00
|
|
|
|
2026-02-27 12:01:02 +01:00
|
|
|
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')
|
2026-02-26 16:20:05 +01:00
|
|
|
|
2026-02-27 12:01:02 +01:00
|
|
|
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')
|
2026-03-01 20:34:42 +01:00
|
|
|
|
2026-02-26 16:20:05 +01:00
|
|
|
|
2026-02-27 12:01:02 +01:00
|
|
|
|