Add dashboard management delete and edit
This commit is contained in:
Binary file not shown.
@@ -6,6 +6,7 @@ from pathlib import Path
|
|||||||
from tools.load_css import load_css
|
from tools.load_css import load_css
|
||||||
from app_db.app_db import get_list, send_cmd
|
from app_db.app_db import get_list, send_cmd
|
||||||
from ui.selectboxes import get_groups, get_id
|
from ui.selectboxes import get_groups, get_id
|
||||||
|
from tools.numgen import get_num, update_num
|
||||||
import bcrypt
|
import bcrypt
|
||||||
|
|
||||||
|
|
||||||
@@ -41,48 +42,88 @@ def sidebar():
|
|||||||
dashborad()
|
dashborad()
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
# Dialog Dashboard anlegen
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@st.dialog("Dashboard anlegen")
|
@st.dialog("Dashboard anlegen")
|
||||||
def dialog_create_dashboard():
|
def dialog_create_dashboard(dash_id):
|
||||||
txt_username = st.text_input("Benutzername")
|
|
||||||
txt_firstname = st.text_input("Vorname")
|
dash_types = ["page", "url"]
|
||||||
txt_lastname = st.text_input("Nachname")
|
df_groups = get_groups()
|
||||||
txt_email = st.text_input("Email")
|
groups = df_groups["group"].tolist()
|
||||||
txt_pwd = st.text_input("Kennwort", type="password")
|
|
||||||
cmb_role = st.selectbox("Rolle", get_roles(), index=None)
|
txt_dash_id = st.text_input("Dash-Id", value=dash_id, disabled=True)
|
||||||
|
col1, col2 = st.columns([2,1],vertical_alignment="center")
|
||||||
|
with col1:
|
||||||
|
txt_dash_text = st.text_input(label="Dashboard")
|
||||||
|
with col2:
|
||||||
|
is_active = st.checkbox(label="Aktiv", value=1)
|
||||||
|
txt_dash_description = st.text_area(label="Beschreibung")
|
||||||
|
cmb_dash_type = st.selectbox(label="Typ", options=dash_types)
|
||||||
|
txt_page_file = st.text_input(label="Page")
|
||||||
|
cmb_group = st.selectbox(label="Gruppe", options=groups, placeholder="Gruppe auswählen")
|
||||||
|
txt_order_no = st.text_input(label="Order-Nr")
|
||||||
|
|
||||||
if st.button("Save"):
|
if st.button("Save"):
|
||||||
if create_user(
|
|
||||||
username=txt_username,
|
sql = """
|
||||||
firstname=txt_firstname,
|
insert into dashboards (
|
||||||
lastname=txt_lastname,
|
dash_id,
|
||||||
email=txt_email,
|
dash_text,
|
||||||
role_id=get_id(cmb_role),
|
dash_description,
|
||||||
password=txt_pwd
|
group_id,
|
||||||
):
|
page_file,
|
||||||
st.session_state.save_msg = f"✅ Benutzer '{txt_username}' erfolgreich gespeichert"
|
dash_type,
|
||||||
|
active,
|
||||||
|
order_no
|
||||||
|
)
|
||||||
|
values (?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
"""
|
||||||
|
params = (
|
||||||
|
txt_dash_id,
|
||||||
|
txt_dash_text,
|
||||||
|
txt_dash_description,
|
||||||
|
get_id(cmb_group),
|
||||||
|
txt_page_file,
|
||||||
|
cmb_dash_type,
|
||||||
|
is_active,
|
||||||
|
txt_order_no,
|
||||||
|
)
|
||||||
|
|
||||||
|
if send_cmd(sql, params):
|
||||||
|
st.session_state.save_msg = f"✅ Dashboard '{txt_dash_text}' erfolgreich gespeichert"
|
||||||
|
update_num(dash_id,1,"numgen_dashboard")
|
||||||
else:
|
else:
|
||||||
st.session_state.save_msg = "❌ Fehler beim Speichern"
|
st.session_state.save_msg = "❌ Fehler beim Speichern"
|
||||||
st.rerun()
|
st.rerun()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
# Dialog Dashboard löschen
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@st.dialog("Dashboard löschen")
|
@st.dialog("Dashboard löschen")
|
||||||
def dialog_delete_dashboard(id):
|
def dialog_delete_dashboard(dash_id):
|
||||||
if id == None:
|
if dash_id == None:
|
||||||
st.write("kein Benutzer ausgewählt")
|
st.write("kein Dashboard ausgewählt")
|
||||||
else:
|
else:
|
||||||
df = get_list("select username from users where id = ?",(id,))
|
df = get_list("select dash_text from dashboards where dash_id = ?",(dash_id,))
|
||||||
username = df.iloc[0]["username"]
|
dash_text = df.iloc[0]["dash_text"]
|
||||||
st.write(f"Der Benutzer {username} wird gelöscht! Sind Sie sicher?")
|
st.write(f"Das Dashboard {dash_text} wird gelöscht! Sind Sie sicher?")
|
||||||
if st.button("Löschen"):
|
if st.button("Löschen"):
|
||||||
if username != "admin":
|
if send_cmd("delete from dashboards where dash_id = ?",(dash_id,)):
|
||||||
if send_cmd("delete from users where id = ?",(id,)):
|
st.session_state.delete_msg = f"✅ Dashboard '{dash_text}' erfolgreich gelöscht!"
|
||||||
st.session_state.delete_msg = f"✅ Benutzer '{username}' erfolgreich gelöscht!"
|
|
||||||
else:
|
else:
|
||||||
st.session_state.delete_msg = f"❌ Benutzer '{username}' konnte nicht gelöscht werden!"
|
st.session_state.delete_msg = f"❌ Daschboard '{dash_id}' konnte nicht gelöscht werden!"
|
||||||
else:
|
|
||||||
st.session_state.delete_msg = f"❌ Benutzer '{username}' darf nicht gelöscht werden!"
|
|
||||||
st.rerun()
|
st.rerun()
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
# Dialog Dashboard bearbeiten
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@st.dialog("Dashboard bearbeiten")
|
@st.dialog("Dashboard bearbeiten")
|
||||||
def dialog_edit_dashboard(dash_id):
|
def dialog_edit_dashboard(dash_id):
|
||||||
if dash_id == None:
|
if dash_id == None:
|
||||||
@@ -189,7 +230,7 @@ def dashborad():
|
|||||||
|
|
||||||
with col_create_dashboard:
|
with col_create_dashboard:
|
||||||
if st.button(label="Dashboard anlegen", use_container_width=True, icon=":material/add:"):
|
if st.button(label="Dashboard anlegen", use_container_width=True, icon=":material/add:"):
|
||||||
dialog_create_dashboard()
|
dialog_create_dashboard(get_num("numgen_dashboard"))
|
||||||
if "save_msg" in st.session_state:
|
if "save_msg" in st.session_state:
|
||||||
st.toast(st.session_state.save_msg)
|
st.toast(st.session_state.save_msg)
|
||||||
del st.session_state.save_msg
|
del st.session_state.save_msg
|
||||||
|
|||||||
Reference in New Issue
Block a user