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
|
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()
|
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!
|
# muss man es nur hier ändern!
|
||||||
|
|
||||||
def apply_design():
|
def apply_design():
|
||||||
ui.add_css('body { background-color: #171721; }')
|
|
||||||
# 1. Dark Mode aktivieren
|
# 1. Dark Mode aktivieren
|
||||||
ui.dark_mode(True)
|
ui.dark_mode(True)
|
||||||
ui.colors(
|
ui.colors(
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
from nicegui import ui
|
from nicegui import ui
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from data import database
|
from data import data_api
|
||||||
from gui import gui_style, gui_admin
|
from gui import gui_style, admin_gui
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def setup_route():
|
def setup_route():
|
||||||
@ui.page("/")
|
@ui.page("/")
|
||||||
|
|
||||||
def main_page():
|
def main_page():
|
||||||
|
gui_style.apply_design()
|
||||||
with ui.column().classes('w-full h-screen no-wrap gap-0 items-stretch'):
|
with ui.column().classes('w-full h-screen no-wrap gap-0 items-stretch'):
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
# Header
|
# Header
|
||||||
|
|
@ -24,7 +24,7 @@ def setup_route():
|
||||||
with ui.column():
|
with ui.column():
|
||||||
# --- Linke Karte: Eingabemaske ---
|
# --- Linke Karte: Eingabemaske ---
|
||||||
with ui.card().classes('overflow-y-auto'):
|
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_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")
|
input_location = ui.input(label='Einsatzort', placeholder='Adresse, oder Beschreibung').classes("w-full")
|
||||||
with ui.row().classes('gap-10'):
|
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')
|
input_time = ui.number(label="Dauer (Min)", value=0).classes('flex-1')
|
||||||
with ui.row().classes("gap-10 w-full items-center"):
|
with ui.row().classes("gap-10 w-full items-center"):
|
||||||
input_type = ui.toggle(["Einsatz", "Übung"]).classes('flex-1 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():
|
def ClearForm():
|
||||||
input_name.value = ""
|
input_name.value = ""
|
||||||
input_location.value = ""
|
input_location.value = ""
|
||||||
input_date.value = today
|
input_date.value = today
|
||||||
input_time.value = 0
|
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
|
input_device.value = None # Select resetten
|
||||||
ui.notify("Gelöscht.")
|
ui.notify("Gelöscht.")
|
||||||
|
|
||||||
|
|
@ -58,8 +65,8 @@ def setup_route():
|
||||||
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
|
||||||
database.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 = database.get_einsaetze()
|
einsaetze_table.rows = data_api.get_einsaetze()
|
||||||
einsaetze_table.update()
|
einsaetze_table.update()
|
||||||
ui.notify("Eintrag in Datenbank erstellt.")
|
ui.notify("Eintrag in Datenbank erstellt.")
|
||||||
ClearForm()
|
ClearForm()
|
||||||
|
|
@ -74,9 +81,8 @@ def setup_route():
|
||||||
ui.button(text="Eintragen", on_click=InputDataToTable)
|
ui.button(text="Eintragen", on_click=InputDataToTable)
|
||||||
|
|
||||||
with ui.card().classes("w-full"):
|
with ui.card().classes("w-full"):
|
||||||
# 1. Das Passwort-Feld
|
# Passwort-Feld
|
||||||
pw_input = ui.input("Passwort", password=True)
|
pw_input = ui.input("Passwort", password=True)
|
||||||
|
|
||||||
with ui.card().bind_visibility_from(pw_input, 'value', backward=lambda v: v == '1234').classes("w-full"):
|
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"))
|
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
|
# 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 = database.get_einsaetze(),
|
rows = data_api.get_einsaetze(),
|
||||||
row_key = "id"
|
row_key = "id"
|
||||||
).classes("w-full h-full")
|
).classes("w-full h-full")
|
||||||
|
|
||||||
|
|
|
||||||
3
main.py
3
main.py
|
|
@ -1,10 +1,11 @@
|
||||||
from gui import main_gui
|
from gui import main_gui, admin_gui
|
||||||
from nicegui import ui
|
from nicegui import ui
|
||||||
from data import database
|
from data import database
|
||||||
|
|
||||||
|
|
||||||
database.initialize_db()
|
database.initialize_db()
|
||||||
main_gui.setup_route()
|
main_gui.setup_route()
|
||||||
|
admin_gui.setup_route()
|
||||||
|
|
||||||
main_gui.ui.run(
|
main_gui.ui.run(
|
||||||
title="ATS Träger Dokumentation",
|
title="ATS Träger Dokumentation",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user