From 905490ecd06ed891938afc45eccd0714253dc57b Mon Sep 17 00:00:00 2001 From: Daniel Nagel Date: Thu, 2 Apr 2026 13:39:46 +0000 Subject: [PATCH] =?UTF-8?q?admin=20Seite.=20data=5Fapi=20enth=C3=A4lt=20je?= =?UTF-8?q?tzt=20alle=20db=20get,=20delete=20und=20inputs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/data_api.py | 55 ++++++++++++++++++++++- data/database.py | 54 +--------------------- gui/__pycache__/main_gui.cpython-312.pyc | Bin 8543 -> 8664 bytes gui/admin_gui.py | 14 ++++++ gui/gui_admin.py | 9 ---- gui/gui_style.py | 1 - gui/main_gui.py | 28 +++++++----- main.py | 3 +- 8 files changed, 88 insertions(+), 76 deletions(-) create mode 100644 gui/admin_gui.py delete mode 100644 gui/gui_admin.py diff --git a/data/data_api.py b/data/data_api.py index 0b54a3f..02db574 100644 --- a/data/data_api.py +++ b/data/data_api.py @@ -1,2 +1,55 @@ import sqlite3 -from data.database import DB_NAME \ No newline at end of file +from data.database import DB_NAME + + +def add_data_to_einsaetze(name, location, date, time, etype, device): + connection = sqlite3.connect(DB_NAME) + cursor = connection.cursor() + + sql_query = "INSERT INTO einsaetze (name, location, date, time, etype, device) VALUES (?, ?, ?, ?, ?, ?)" + data = (name, location, date, time, etype, device) + + cursor.execute(sql_query, data) + print("DB geschrieben") + + connection.commit() + connection.close() + +def get_ats_names(): + connection = sqlite3.connect(DB_NAME) + cursor = connection.cursor() + + # nur die Spalte 'name' aus der Tabelle 'ats' + cursor.execute("SELECT name FROM ats ORDER BY name ASC") + names = cursor.fetchall() + connection.close() + return [row[0] for row in names] + +def get_einsaetze(): + connection = sqlite3.connect(DB_NAME) + + #Get Data an Row Names + connection.row_factory = sqlite3.Row + cursor = connection.cursor() + cursor.execute("SELECT * FROM einsaetze ORDER BY id DESC") + data = cursor.fetchall() + connection.close() + return [dict(row) for row in data] + + +# ATS Träger aus DB Löschen ODER einfügen.abs +def delete_ats_traeger(id): + connection = sqlite3.connect(DB_NAME) + + cursor = connection.cursor() + +def get_ats_with_id(): + #Verbindung Aufbauen + connection = sqlite3.connect(DB_NAME) + connection.row_factory = sqlite3.Row + + cursor = connection.cursor() + cursor.execute("SELECT id, name FROM ats ORDER BY name ASC") + + data = cursor.fetchall() + return [dict(row) for row in data] \ No newline at end of file diff --git a/data/database.py b/data/database.py index 86a5183..e99c561 100644 --- a/data/database.py +++ b/data/database.py @@ -38,59 +38,7 @@ def initialize_db(): connection.close() -def add_data_to_einsaetze(name, location, date, time, etype, device): - connection = sqlite3.connect(DB_NAME) - cursor = connection.cursor() - - sql_query = "INSERT INTO einsaetze (name, location, date, time, etype, device) VALUES (?, ?, ?, ?, ?, ?)" - data = (name, location, date, time, etype, device) - - cursor.execute(sql_query, data) - print("DB geschrieben") - - connection.commit() - connection.close() - -def get_ats_names(): - connection = sqlite3.connect(DB_NAME) - cursor = connection.cursor() - - # nur die Spalte 'name' aus der Tabelle 'ats' - cursor.execute("SELECT name FROM ats ORDER BY name ASC") - names = cursor.fetchall() - connection.close() - return [row[0] for row in names] - -def get_einsaetze(): - connection = sqlite3.connect(DB_NAME) - - #Get Data an Row Names - connection.row_factory = sqlite3.Row - cursor = connection.cursor() - cursor.execute("SELECT * FROM einsaetze ORDER BY id DESC") - data = cursor.fetchall() - connection.close() - return [dict(row) for row in data] - - -# ATS Träger aus DB Löschen ODER einfügen.abs -def delete_ats_traeger(id): - connection = sqlite3.connect(DB_NAME) - - cursor = connection.cursor() - -def get_ats_with_id(): - #Verbindung Aufbauen - connection = sqlite3.connect(DB_NAME) - connection.row_factory = sqlite3.Row - - #Cursor in die DB Schicken und Daten holen. - cursor = connection.cursor() - cursor.execute("SELECT id, name FROM ats ORDER BY name ASC") - - # - data = cursor.fetchall() - return [dict(row) for row in data] + diff --git a/gui/__pycache__/main_gui.cpython-312.pyc b/gui/__pycache__/main_gui.cpython-312.pyc index 516c19b347c7c4352a6e385eb4b5af224d9a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6PCJ#h;r@j6D;uWcY+0 zjZMV#jHE>qvC+xdbIF9>LNYyu-g8yA{ohLJPO`8KL)?NP-wR%3b@x=eAw~W7KQB=C zIm&E#X=G*Ohfk*!Z%XlQ`UY<)$9Jfc=y~^;WjI52Ir+26h^e?v?G`%a9 zj{uf-9i`E@r)uEyVAF59-s*aL_Ji5Y_My#FiQB5JdU zLgJI0;PT@H(wN-ll|-=AN#4fD*0-r6A>yaIz*zOvU5X@*y!KT^V94fMfq zllZ6RUMbAUABAi~UCN)O&`_27G3~+f$Cdt}M)evkVELNVjMrQX1+l~RnqD<*mv8Lr z4dB^d%6plxSH4*(;K|LpAP&6vskPS};l<4=SGZf=3<+3HQ3AH4gdk3zYU}kyeEh8v z0Z(pu2(R0GcVs`@0s@w|Y;edUZaEFP3JwMATYkb}s}T-$*tc2@xeJCF>sF6|S#5JL zY*DvmLSWkt!xf9_c9}8p!f=DSU2DiqFx;tZ?;|X>yJ3V?w+|9tX&y$bO4>y9=@J;J zl+!LkEA4}kpq#EV4qNyDZ9F^~_FQx#76AHL%7ZTe zdAz)O8ODqpk0p}lM)kR5BBsxvR-ap8PXQRZ2Pw|B!=6IJzOJenyiz|vz)gTS=7h)b W?MzO`dh}<}+rBFCI{<_X^Zx+cBay!V diff --git a/gui/admin_gui.py b/gui/admin_gui.py new file mode 100644 index 0000000..03d887c --- /dev/null +++ b/gui/admin_gui.py @@ -0,0 +1,14 @@ +from nicegui import ui +from data import database +from gui import gui_style + +def setup_route(): + @ui.page("/admin") + def admin_page(): + gui_style.apply_design() + + with ui.row().classes("w-full flex-1 p-4 gap-4 no-wrap overflow-hidden"): + with ui.card().classes("flex-1"): + ui.label(text="ATS Träger anpassen.") + with ui.card().classes("flex-1"): + ui.label(text="Einträge Löschen") \ No newline at end of file diff --git a/gui/gui_admin.py b/gui/gui_admin.py deleted file mode 100644 index 2b69e0b..0000000 --- a/gui/gui_admin.py +++ /dev/null @@ -1,9 +0,0 @@ -from nicegui import ui -from data import database -from gui import gui_style - -def setup_route(): - @ui.page("/") - - def admin_page(): - ui.label("kasdlkfs") \ No newline at end of file diff --git a/gui/gui_style.py b/gui/gui_style.py index a6399fa..aecd145 100644 --- a/gui/gui_style.py +++ b/gui/gui_style.py @@ -4,7 +4,6 @@ from nicegui import ui # muss man es nur hier ändern! def apply_design(): - ui.add_css('body { background-color: #171721; }') # 1. Dark Mode aktivieren ui.dark_mode(True) ui.colors( diff --git a/gui/main_gui.py b/gui/main_gui.py index ec4af70..b604835 100644 --- a/gui/main_gui.py +++ b/gui/main_gui.py @@ -1,14 +1,14 @@ from nicegui import ui from datetime import datetime -from data import database -from gui import gui_style, gui_admin +from data import data_api +from gui import gui_style, admin_gui def setup_route(): @ui.page("/") - def main_page(): + gui_style.apply_design() with ui.column().classes('w-full h-screen no-wrap gap-0 items-stretch'): # --------------------------------------------------------- # Header @@ -24,7 +24,7 @@ def setup_route(): with ui.column(): # --- Linke Karte: Eingabemaske --- with ui.card().classes('overflow-y-auto'): - traeger = database.get_ats_names() + traeger = data_api.get_ats_names() input_name = ui.select(label="ATS Träger Name", options=traeger, with_input=True).classes('w-full') input_location = ui.input(label='Einsatzort', placeholder='Adresse, oder Beschreibung').classes("w-full") with ui.row().classes('gap-10'): @@ -39,14 +39,21 @@ def setup_route(): input_time = ui.number(label="Dauer (Min)", value=0).classes('flex-1') with ui.row().classes("gap-10 w-full items-center"): input_type = ui.toggle(["Einsatz", "Übung"]).classes('flex-1 center') - input_device = ui.select(["ATS Gerät 1", "ATS Gerät 2"], label="ATS Gerät auswählen").classes('flex-1') + + devices = [] + for x in range(1, 10): + devices.append(f"ATS Gerät {x}") + + + + input_device = ui.select(devices, label="ATS Gerät auswählen").classes('flex-1') def ClearForm(): input_name.value = "" input_location.value = "" input_date.value = today input_time.value = 0 - input_type.value = "Einsatz" # Achtung: Value sollte zum Toggle passen (String, nicht 0) + input_type.value = "" # Achtung: Value sollte zum Toggle passen (String, nicht 0) input_device.value = None # Select resetten ui.notify("Gelöscht.") @@ -58,8 +65,8 @@ def setup_route(): etype = input_type.value device = input_device.value # Hinweis: database Aufruf ist hier korrekt, sofern importiert - database.add_data_to_einsaetze(name, location, date, time, etype, device) - einsaetze_table.rows = database.get_einsaetze() + data_api.add_data_to_einsaetze(name, location, date, time, etype, device) + einsaetze_table.rows = data_api.get_einsaetze() einsaetze_table.update() ui.notify("Eintrag in Datenbank erstellt.") ClearForm() @@ -74,9 +81,8 @@ def setup_route(): ui.button(text="Eintragen", on_click=InputDataToTable) with ui.card().classes("w-full"): - # 1. Das Passwort-Feld + # Passwort-Feld pw_input = ui.input("Passwort", password=True) - with ui.card().bind_visibility_from(pw_input, 'value', backward=lambda v: v == '1234').classes("w-full"): ui.button(text="Admin Seite", on_click=lambda:ui.navigate.to("/admin")) @@ -93,7 +99,7 @@ def setup_route(): # Die Tabelle selbst bekommt auch h-full, damit sie die Karte ausfüllt einsaetze_table = ui.table( columns = collums, - rows = database.get_einsaetze(), + rows = data_api.get_einsaetze(), row_key = "id" ).classes("w-full h-full") diff --git a/main.py b/main.py index 702190a..93e08e8 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,11 @@ -from gui import main_gui +from gui import main_gui, admin_gui from nicegui import ui from data import database database.initialize_db() main_gui.setup_route() +admin_gui.setup_route() main_gui.ui.run( title="ATS Träger Dokumentation",