data_api mit admin Panel anpassen.

This commit is contained in:
Daniel Nagel 2026-05-05 13:31:03 +00:00
parent 93fea0aecd
commit 8ed28160c2
6 changed files with 26 additions and 20 deletions

View File

@ -7,8 +7,8 @@ Das Projekt ermöglicht es einfach zu dokumentieren WANN, WER im Einsatz (oder
Das Projekt kann auf jedem Linux Server per Systemd oder ähnlichem gehostet werden. Standard Einstellung ist Port 9000. Das Projekt kann auf jedem Linux Server per Systemd oder ähnlichem gehostet werden. Standard Einstellung ist Port 9000.
##### Hardware: ##### Hardware:
* 2 Kerne
Linux Container mit 4GB RAM. * Linux Container mit 4GB RAM.
Deployment: Deployment:

View File

@ -10,7 +10,6 @@ def add_data_to_einsaetze(name, location, date, time, etype, device):
data = (name, location, date, time, etype, device) data = (name, location, date, time, etype, device)
cursor.execute(sql_query, data) cursor.execute(sql_query, data)
print("DB geschrieben")
connection.commit() connection.commit()
connection.close() connection.close()
@ -39,7 +38,9 @@ def get_entrys():
''') ''')
data = cursor.fetchall() data = cursor.fetchall()
connection.close() connection.close()
return [dict(row) for row in data] d = [dict(row) for row in data]
print (d)
return d
# ATS Träger aus DB Löschen ODER einfügen.abs # ATS Träger aus DB Löschen ODER einfügen.abs
@ -61,3 +62,8 @@ def get_ats_with_id():
def delete_entry(entry_id): def delete_entry(entry_id):
connection = sqlite3.connect(DB_NAME)
cursor = connection.cursor()
cursor.execute("DELETE FROM entrys WHERE id = ?", (entry_id,))
connection.commit()

View File

@ -6,7 +6,9 @@ def initialize_db():
connection = sqlite3.connect(DB_NAME) connection = sqlite3.connect(DB_NAME)
cursor = connection.cursor() cursor = connection.cursor()
# --- Tabelle 1: Die Liste für dein Dropdown --- cursor.execute("PRAGMA foreign_keys = ON")
# --- Tabelle 1: BA Träger ---
cursor.execute(''' cursor.execute('''
CREATE TABLE IF NOT EXISTS ba_wearer ( CREATE TABLE IF NOT EXISTS ba_wearer (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
@ -15,7 +17,16 @@ def initialize_db():
) )
''') ''')
# --- Tabelle 2: Das Logbuch (jetzt mit Ort) --- # --- Tabelle 2: BA Geräte (muss VOR entrys erstellt werden!) ---
cursor.execute('''
CREATE TABLE IF NOT EXISTS ba_devices (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE,
code TEXT UNIQUE
)
''')
# --- Tabelle 3: Das Logbuch ---
cursor.execute(''' cursor.execute('''
CREATE TABLE IF NOT EXISTS entrys ( CREATE TABLE IF NOT EXISTS entrys (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
@ -24,21 +35,13 @@ def initialize_db():
date TEXT, date TEXT,
time INTEGER, time INTEGER,
etype TEXT, etype TEXT,
device TEXT, device_id INTEGER,
wearer_id INTEGER,
FOREIGN KEY (wearer_id) REFERENCES ba_wearer(id) ON DELETE SET NULL, FOREIGN KEY (wearer_id) REFERENCES ba_wearer(id) ON DELETE SET NULL,
FOREIGN KEY (device_id) REFERENCES ba_devices(id) ON DELETE SET NULL FOREIGN KEY (device_id) REFERENCES ba_devices(id) ON DELETE SET NULL
) )
''') ''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS ba_devices (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE,
code TEXT UNIQUE
)
''')
# Optional: Ein paar Test-ats anlegen, falls die Tabelle leer ist # Optional: Ein paar Test-ats anlegen, falls die Tabelle leer ist
cursor.execute("SELECT count(*) FROM ats") cursor.execute("SELECT count(*) FROM ats")
if cursor.fetchone()[0] == 0: if cursor.fetchone()[0] == 0:

View File

@ -26,9 +26,7 @@ def setup_route():
rows = data_api.get_entrys() rows = data_api.get_entrys()
def delete_entry(entry_id: int): def delete_entry(entry_id: int):
"""Hier deinen SQL DELETE Aufruf einfügen."""
data_api.delete_entry(entry_id) data_api.delete_entry(entry_id)
print(f"Lösche Eintrag mit ID: {entry_id}")
table.update() table.update()
table = ui.table(columns=columns, rows= rows, row_key='id').classes('w-full') table = ui.table(columns=columns, rows= rows, row_key='id').classes('w-full')

View File

@ -64,12 +64,12 @@ def setup_route():
time = input_time.value time = input_time.value
etype = input_type.value etype = input_type.value
device = input_device.value device = input_device.value
# Hinweis: database Aufruf ist hier korrekt, sofern importiert # Hinweis: database Aufruf ist hier korrekt, sofern importiert
data_api.add_data_to_einsaetze(name, location, date, time, etype, device) data_api.add_data_to_einsaetze(name, location, date, time, etype, device)
einsaetze_table.rows = data_api.get_entrys() einsaetze_table.rows = data_api.get_entrys()
einsaetze_table.update() einsaetze_table.update()
ui.notify("Eintrag in Datenbank erstellt.") ui.notify("Eintrag in Datenbank erstellt.")
ClearForm()
@ -96,7 +96,6 @@ def setup_route():
{'name': 'etype', 'label': 'Art', 'field': 'etype', "sortable": True}, {'name': 'etype', 'label': 'Art', 'field': 'etype', "sortable": True},
{'name': 'device', 'label': 'Gerät', 'field': 'device', "sortable": True}, {'name': 'device', 'label': 'Gerät', 'field': 'device', "sortable": True},
] ]
# Die Tabelle selbst bekommt auch h-full, damit sie die Karte ausfüllt
einsaetze_table = ui.table( einsaetze_table = ui.table(
columns = collums, columns = collums,
rows = data_api.get_entrys(), rows = data_api.get_entrys(),