admin Seite. data_api enthält jetzt alle db get, delete und inputs.
This commit is contained in:
parent
20123348a7
commit
905490ecd0
|
|
@ -1,2 +1,55 @@
|
|||
import sqlite3
|
||||
from data.database import DB_NAME
|
||||
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]
|
||||
|
|
@ -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]
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Binary file not shown.
14
gui/admin_gui.py
Normal file
14
gui/admin_gui.py
Normal file
|
|
@ -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")
|
||||
|
|
@ -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")
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user