Compare commits
9 Commits
37d1daa052
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07854cc0ad | ||
|
|
3725e7fe5d | ||
|
|
3f3ec5097d | ||
|
|
13385db5ef | ||
|
|
c711a75eed | ||
|
|
00692e1641 | ||
|
|
4207fe29d6 | ||
|
|
52010b0730 | ||
|
|
9c5ed967ec |
@@ -1,7 +1,8 @@
|
|||||||
[client]
|
[client]
|
||||||
showSidebarNavigation = false
|
showSidebarNavigation = false
|
||||||
toolbarMode = "minimal"
|
# toolbarMode = "minimal"
|
||||||
# toolbarMode = "auto"
|
# toolbarMode = "auto"
|
||||||
|
toolbarMode = "viewer"
|
||||||
|
|
||||||
[theme]
|
[theme]
|
||||||
# primaryColor = "blue"
|
# primaryColor = "blue"
|
||||||
|
|||||||
Binary file not shown.
@@ -163,7 +163,7 @@ def load_credentials_from_db() -> dict:
|
|||||||
|
|
||||||
with closing(get_conn()) as conn:
|
with closing(get_conn()) as conn:
|
||||||
rows = conn.execute(
|
rows = conn.execute(
|
||||||
"SELECT username, email, password_hash FROM users"
|
"SELECT username, email, password_hash FROM users where active = 1"
|
||||||
).fetchall()
|
).fetchall()
|
||||||
|
|
||||||
for username, email, pw_hash in rows:
|
for username, email, pw_hash in rows:
|
||||||
|
|||||||
318
app/pages/dashboards.py
Normal file
318
app/pages/dashboards.py
Normal file
@@ -0,0 +1,318 @@
|
|||||||
|
import streamlit as st
|
||||||
|
from auth_runtime import require_login
|
||||||
|
from pathlib import Path
|
||||||
|
from tools.load_css import load_css
|
||||||
|
from app_db.app_db import get_list, send_cmd
|
||||||
|
from ui.selectboxes import get_groups, get_id
|
||||||
|
from tools.numgen import get_num, update_num
|
||||||
|
|
||||||
|
|
||||||
|
DASH_NAME = Path(__file__).stem # Hier muss die dash_id aus der DB stehen -> wird gegen die session_state geprüft (User-Berechtigung)
|
||||||
|
DASH_PATH = Path(__file__).resolve().parent
|
||||||
|
|
||||||
|
|
||||||
|
load_css()
|
||||||
|
|
||||||
|
st.set_page_config(page_title="Co-App Benutzer", page_icon=":material/person:", layout="wide", initial_sidebar_state="collapsed")
|
||||||
|
|
||||||
|
authenticator = require_login()
|
||||||
|
st.session_state["authenticator"] = authenticator
|
||||||
|
|
||||||
|
def get_dashboards_from_pages():
|
||||||
|
dashboards = sorted(
|
||||||
|
d.stem
|
||||||
|
for d in DASH_PATH.glob("*.py")
|
||||||
|
if d.name != "__init__.py"
|
||||||
|
)
|
||||||
|
#dash_list = [""] + dashboards
|
||||||
|
return dashboards
|
||||||
|
|
||||||
|
def sidebar():
|
||||||
|
|
||||||
|
fullname = st.session_state.get("fullname")
|
||||||
|
role_text = st.session_state.get("role_text")
|
||||||
|
|
||||||
|
with st.sidebar:
|
||||||
|
|
||||||
|
st.logo("app/images/GMN_Logo_neu_rgb.png", size="small")
|
||||||
|
st.markdown(f"**{fullname}** ({role_text})")
|
||||||
|
|
||||||
|
col1, col2 = st.columns([2,2])
|
||||||
|
with col1:
|
||||||
|
authenticator.logout("Logout")
|
||||||
|
with col2:
|
||||||
|
if st.button("Home", use_container_width=True, icon=":material/home:"):
|
||||||
|
st.switch_page("pages/home.py")
|
||||||
|
|
||||||
|
dashborad()
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
# Dialog Dashboard anlegen
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@st.dialog("Dashboard anlegen")
|
||||||
|
def dialog_create_dashboard(dash_id):
|
||||||
|
|
||||||
|
dash_types = ["page", "url"]
|
||||||
|
df_groups = get_groups()
|
||||||
|
groups = df_groups["group"].tolist()
|
||||||
|
|
||||||
|
dash_list = get_dashboards_from_pages()
|
||||||
|
dash_default_index = dash_list.index("default")
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
if cmb_dash_type == "url":
|
||||||
|
txt_page_file = st.text_input(label="URL", placeholder="URL, z.B. https://www.gmn.de")
|
||||||
|
else:
|
||||||
|
txt_page_file = st.selectbox(label="Dashboard", options=dash_list, index=dash_default_index)
|
||||||
|
|
||||||
|
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"):
|
||||||
|
|
||||||
|
sql = """
|
||||||
|
insert into dashboards (
|
||||||
|
dash_id,
|
||||||
|
dash_text,
|
||||||
|
dash_description,
|
||||||
|
group_id,
|
||||||
|
page_file,
|
||||||
|
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:
|
||||||
|
st.session_state.save_msg = "❌ Fehler beim Speichern"
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
# Dialog Dashboard löschen
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@st.dialog("Dashboard löschen")
|
||||||
|
def dialog_delete_dashboard(dash_id):
|
||||||
|
if dash_id == None:
|
||||||
|
st.write("kein Dashboard ausgewählt")
|
||||||
|
else:
|
||||||
|
df = get_list("select dash_text from dashboards where dash_id = ?",(dash_id,))
|
||||||
|
dash_text = df.iloc[0]["dash_text"]
|
||||||
|
st.write(f"Das Dashboard {dash_text} wird gelöscht! Sind Sie sicher?")
|
||||||
|
if st.button("Löschen"):
|
||||||
|
if send_cmd("delete from dashboards where dash_id = ?",(dash_id,)):
|
||||||
|
st.session_state.delete_msg = f"✅ Dashboard '{dash_text}' erfolgreich gelöscht!"
|
||||||
|
else:
|
||||||
|
st.session_state.delete_msg = f"❌ Daschboard '{dash_id}' konnte nicht gelöscht werden!"
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
# Dialog Dashboard bearbeiten
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@st.dialog("Dashboard bearbeiten")
|
||||||
|
def dialog_edit_dashboard(dash_id):
|
||||||
|
if dash_id == None:
|
||||||
|
st.write("kein Dashboard ausgewählt")
|
||||||
|
else:
|
||||||
|
sql = """
|
||||||
|
select
|
||||||
|
d.dash_id,
|
||||||
|
d.dash_text,
|
||||||
|
d.dash_description,
|
||||||
|
d.group_id || ' | ' || g.group_text as "group",
|
||||||
|
d.page_file,
|
||||||
|
d.dash_type,
|
||||||
|
d.active,
|
||||||
|
d.order_no
|
||||||
|
from
|
||||||
|
dashboards d
|
||||||
|
left join groups g
|
||||||
|
on d.group_id = g.group_id
|
||||||
|
where
|
||||||
|
d.dash_id = ?
|
||||||
|
"""
|
||||||
|
df = get_list(sql,(dash_id,))
|
||||||
|
|
||||||
|
# Index für Gruppe aus DB für selectbox ermitteln
|
||||||
|
df_groups = get_groups()
|
||||||
|
groups = df_groups["group"].tolist()
|
||||||
|
group = df.iloc[0]["group"]
|
||||||
|
try:
|
||||||
|
idx = groups.index(group)
|
||||||
|
except:
|
||||||
|
idx = None
|
||||||
|
|
||||||
|
# Index für Dash-Typ aus DB für selectbox ermitteln
|
||||||
|
dash_types = ["page", "url"]
|
||||||
|
dash_type_index = dash_types.index(df.iloc[0]["dash_type"])
|
||||||
|
|
||||||
|
dash_list = get_dashboards_from_pages()
|
||||||
|
dash_default_index = dash_list.index(df.iloc[0]["page_file"]) if df.iloc[0]["page_file"] in dash_list else dash_list.index("default")
|
||||||
|
|
||||||
|
|
||||||
|
col1, col2 = st.columns([2,1],vertical_alignment="center")
|
||||||
|
with col1:
|
||||||
|
txt_dash_text = st.text_input(label="Dashboard", value=df.iloc[0]["dash_text"])
|
||||||
|
with col2:
|
||||||
|
is_active = st.checkbox(label="Aktiv", value=df.iloc[0]["active"])
|
||||||
|
txt_dash_description = st.text_area(label="Beschreibung", value=df.iloc[0]["dash_description"])
|
||||||
|
cmb_dash_type = st.selectbox(label="Typ", options=dash_types, index=dash_type_index)
|
||||||
|
if cmb_dash_type == "url":
|
||||||
|
if df.iloc[0]["dash_type"] == "page":
|
||||||
|
txt_page_file = st.text_input(label="URL", value="", placeholder="URL, z.B. https://www.gmn.de")
|
||||||
|
else:
|
||||||
|
txt_page_file = st.text_input(label="URL", value=df.iloc[0]["page_file"])
|
||||||
|
dash_default_index = dash_list.index("default")
|
||||||
|
else:
|
||||||
|
txt_page_file = st.selectbox(label="Dashboard", options=dash_list, index=dash_default_index)
|
||||||
|
|
||||||
|
cmb_group = st.selectbox(label="Gruppe", options=groups, placeholder="Gruppe auswählen", index=idx)
|
||||||
|
txt_order_no = st.text_input(label="Order-Nr",value=df.iloc[0]["order_no"])
|
||||||
|
|
||||||
|
if st.button("Save"):
|
||||||
|
|
||||||
|
sql = """
|
||||||
|
update dashboards set
|
||||||
|
dash_text = ?,
|
||||||
|
dash_description = ?,
|
||||||
|
group_id = ?,
|
||||||
|
page_file = ?,
|
||||||
|
dash_type = ?,
|
||||||
|
active = ?,
|
||||||
|
order_no = ?
|
||||||
|
where dash_id = ?
|
||||||
|
"""
|
||||||
|
params = (txt_dash_text, txt_dash_description, get_id(cmb_group), txt_page_file, cmb_dash_type, is_active, txt_order_no, dash_id)
|
||||||
|
|
||||||
|
if send_cmd(sql, params):
|
||||||
|
st.session_state.save_msg = f"✅ Dashboard '{txt_dash_text}' erfolgreich geändert"
|
||||||
|
else:
|
||||||
|
st.session_state.save_msg = "❌ Fehler beim Speichern"
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def dashborad():
|
||||||
|
|
||||||
|
if "selected_dash_id" not in st.session_state:
|
||||||
|
st.session_state.selected_dash_id = None
|
||||||
|
|
||||||
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
# Dashboard-Verwaltung
|
||||||
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
df = get_list("""
|
||||||
|
select
|
||||||
|
d.dash_id,
|
||||||
|
d.dash_text,
|
||||||
|
d.dash_description,
|
||||||
|
d.group_id || ' | ' || g.group_text as "group",
|
||||||
|
d.page_file,
|
||||||
|
d.dash_type,
|
||||||
|
d.active,
|
||||||
|
d.order_no
|
||||||
|
from
|
||||||
|
dashboards d
|
||||||
|
left join groups g
|
||||||
|
on d.group_id = g.group_id
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
col_find_dashboard, col_create_dashboard, col_edit_dashboard, col_delete_dashboard = st.columns([3,2,2,2], vertical_alignment="bottom")
|
||||||
|
|
||||||
|
with col_find_dashboard:
|
||||||
|
txt_search = st.text_input(label="Suche", label_visibility="hidden", placeholder="Dashboard, Beschreibung ...", icon=":material/search:")
|
||||||
|
|
||||||
|
with col_create_dashboard:
|
||||||
|
if st.button(label="Dashboard anlegen", use_container_width=True, icon=":material/add:"):
|
||||||
|
dialog_create_dashboard(get_num("numgen_dashboard"))
|
||||||
|
if "save_msg" in st.session_state:
|
||||||
|
st.toast(st.session_state.save_msg)
|
||||||
|
del st.session_state.save_msg
|
||||||
|
|
||||||
|
with col_edit_dashboard:
|
||||||
|
if st.button(label="Dashboard bearbeiten", use_container_width=True, icon=":material/edit:"):
|
||||||
|
if not st.session_state.selected_dash_id is None:
|
||||||
|
dialog_edit_dashboard(st.session_state.selected_dash_id)
|
||||||
|
else:
|
||||||
|
st.toast("❌ Bitte erst eine Zeile auswählen")
|
||||||
|
if "save_msg" in st.session_state:
|
||||||
|
st.toast(st.session_state.save_msg)
|
||||||
|
del st.session_state.save_msg
|
||||||
|
|
||||||
|
with col_delete_dashboard:
|
||||||
|
if st.button(label="Dashboard löschen", use_container_width=True, icon=":material/delete:"):
|
||||||
|
if not st.session_state.selected_dash_id is None:
|
||||||
|
dialog_delete_dashboard(st.session_state.selected_dash_id)
|
||||||
|
else:
|
||||||
|
st.toast("❌ Bitte erst eine Zeile auswählen")
|
||||||
|
if "delete_msg" in st.session_state:
|
||||||
|
st.toast(st.session_state.delete_msg)
|
||||||
|
del st.session_state.delete_msg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if txt_search.strip():
|
||||||
|
txt_search_norm = txt_search.strip().lower()
|
||||||
|
mask = (
|
||||||
|
df["dash_text"].fillna("").str.lower().str.contains(txt_search_norm)
|
||||||
|
| df["dash_description"].fillna("").str.lower().str.contains(txt_search_norm)
|
||||||
|
| df["group"].fillna("").str.lower().str.contains(txt_search_norm)
|
||||||
|
)
|
||||||
|
df_view = df.loc[mask].copy()
|
||||||
|
else:
|
||||||
|
df_view = df.copy()
|
||||||
|
|
||||||
|
event = st.dataframe(df_view,key="dash_data", on_select="rerun", selection_mode="single-row")
|
||||||
|
rows = event.selection.rows
|
||||||
|
if rows:
|
||||||
|
row_idx = rows[0]
|
||||||
|
st.session_state.selected_dash_id = int(df_view.iloc[row_idx]["dash_id"])
|
||||||
|
else:
|
||||||
|
st.session_state.selected_dash_id = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sidebar()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
3
app/pages/default.py
Normal file
3
app/pages/default.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import streamlit as st
|
||||||
|
|
||||||
|
st.header("Baustelle!")
|
||||||
@@ -4,7 +4,7 @@ from auth_runtime import require_login
|
|||||||
from pathlib import Path
|
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 tools.numgen import get_num
|
from tools.numgen import get_num, update_num
|
||||||
|
|
||||||
|
|
||||||
DASH_NAME = Path(__file__).stem
|
DASH_NAME = Path(__file__).stem
|
||||||
@@ -36,87 +36,173 @@ def sidebar():
|
|||||||
groups()
|
groups()
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
# Dialog Gruppe anlegen
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@st.dialog("Gruppe anlegen")
|
||||||
|
def dialog_create_group(group_id):
|
||||||
|
txt_group_id = st.text_input("GrpId", value=group_id, disabled=True)
|
||||||
|
txt_group_text = st.text_input("Gruppenbezeichnung")
|
||||||
|
txt_description = st.text_area("Beschreibung")
|
||||||
|
txt_order_no = st.text_input("Reihenfolge")
|
||||||
|
if st.button("Save"):
|
||||||
|
if send_cmd(f"insert into groups (group_id, group_text, group_description, order_no) " \
|
||||||
|
"values (?, ?, ?, ?)",(txt_group_id, txt_group_text, txt_description, txt_order_no)):
|
||||||
|
st.session_state.save_msg = f"✅ Gruppe '{txt_group_text}' erfolgreich gespeichert"
|
||||||
|
update_num(group_id,1,"numgen_group")
|
||||||
|
else:
|
||||||
|
st.session_state.save_msg = "❌ Fehler beim Speichern"
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
# Dialog Gruppe bearbeiten
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@st.dialog("Gruppe bearbeiten")
|
||||||
|
def dialog_edit_group(group_id):
|
||||||
|
if group_id == None:
|
||||||
|
st.write("keine Gruppe ausgewählt")
|
||||||
|
else:
|
||||||
|
sql = """
|
||||||
|
select
|
||||||
|
group_id,
|
||||||
|
group_text,
|
||||||
|
group_description,
|
||||||
|
active,
|
||||||
|
order_no
|
||||||
|
from
|
||||||
|
groups
|
||||||
|
where
|
||||||
|
group_id = ?
|
||||||
|
order by
|
||||||
|
order_no
|
||||||
|
"""
|
||||||
|
df = get_list(sql,(group_id,))
|
||||||
|
|
||||||
|
|
||||||
|
col1, col2 = st.columns([2,1],vertical_alignment="center")
|
||||||
|
with col1:
|
||||||
|
txt_group_text = st.text_input(label="Gruppenbezeichnung", value=df.iloc[0]["group_text"])
|
||||||
|
with col2:
|
||||||
|
is_active = st.checkbox(label="Aktiv", value=df.iloc[0]["active"])
|
||||||
|
txt_group_description = st.text_area(label="Beschreibung", value=df.iloc[0]["group_description"])
|
||||||
|
txt_oder_no = st.text_input(label="Reihenfolge", value=df.iloc[0]["order_no"])
|
||||||
|
|
||||||
|
if st.button("Save"):
|
||||||
|
sql = """
|
||||||
|
update groups set
|
||||||
|
group_text = ?,
|
||||||
|
active = ?,
|
||||||
|
group_description = ?,
|
||||||
|
order_no = ?
|
||||||
|
where group_id = ?
|
||||||
|
"""
|
||||||
|
params = (txt_group_text, is_active, txt_group_description, txt_oder_no, group_id)
|
||||||
|
|
||||||
|
if send_cmd(sql, params):
|
||||||
|
st.session_state.save_msg = f"✅ Gruppe '{txt_group_text}' erfolgreich geändert"
|
||||||
|
else:
|
||||||
|
st.session_state.save_msg = "❌ Fehler beim Speichern"
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
# Dialog Gruppe löschen
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@st.dialog("Gruppe löschen")
|
||||||
|
def dialog_delete_group(group_id):
|
||||||
|
if id == None:
|
||||||
|
st.write("keine Gruppe ausgewählt")
|
||||||
|
else:
|
||||||
|
df = get_list("select group_text from groups where group_id = ?",(group_id,))
|
||||||
|
group_text = df.iloc[0]["group_text"]
|
||||||
|
st.write(f"Die Gruppe {group_text} wird gelöscht! Sind Sie sicher?")
|
||||||
|
if st.button("Löschen"):
|
||||||
|
if send_cmd("delete from groups where group_id = ?",(group_id,)):
|
||||||
|
st.session_state.delete_msg = f"✅ Gruppe '{group_text}' erfolgreich gelöscht!"
|
||||||
|
else:
|
||||||
|
st.session_state.delete_msg = f"❌ Gruppe '{group_text}' konnte nicht gelöscht werden!"
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
|
||||||
def groups():
|
def groups():
|
||||||
|
|
||||||
if "selected_user_id" not in st.session_state:
|
if "selected_group_id" not in st.session_state:
|
||||||
st.session_state.selected_user_id = None
|
st.session_state.selected_group_id = None
|
||||||
if st.button(label="test"):
|
|
||||||
st.info(get_num("numgen_group", step=10))
|
|
||||||
#--------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------
|
||||||
# Rollenverwaltung
|
# Gruppenverwaltung
|
||||||
#--------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
df = get_list("""
|
||||||
# df = get_list("""
|
select
|
||||||
# select
|
group_id,
|
||||||
# u.id,
|
group_text,
|
||||||
# u.username,
|
group_description,
|
||||||
# u.firstname,
|
active,
|
||||||
# u.lastname,
|
order_no
|
||||||
# u.role_id || ' | ' || r.role_text as role,
|
from
|
||||||
# u.new_pwd,
|
groups
|
||||||
# u.active
|
order by
|
||||||
# from
|
order_no
|
||||||
# users u
|
""")
|
||||||
# left join roles r
|
|
||||||
# on u.role_id = r.role_id
|
|
||||||
# """)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# col_find_role, col_create_role, col_modify_role, col_delete_role = st.columns([3,2,2,2], vertical_alignment="bottom")
|
col_find_group, col_create_group, col_edit_group, col_delete_group = st.columns([3,2,2,2], vertical_alignment="bottom")
|
||||||
|
|
||||||
# with col_find_role:
|
with col_find_group:
|
||||||
# txt_search = st.text_input(label="Suche", label_visibility="hidden", placeholder="Benutzer, Vorname, ...", icon=":material/search:")
|
txt_search = st.text_input(label="Suche", label_visibility="hidden", placeholder="Gruppe", icon=":material/search:")
|
||||||
|
|
||||||
# with col_create_user:
|
with col_create_group:
|
||||||
# if st.button(label="Benutzer anlegen", use_container_width=True, icon=":material/person_add:"):
|
if st.button(label="Gruppe anlegen", use_container_width=True, icon=":material/add:"):
|
||||||
# dialog_create_user()
|
dialog_create_group(get_num("numgen_group"))
|
||||||
# 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
|
||||||
|
|
||||||
# with col_modify_user:
|
with col_edit_group:
|
||||||
# if st.button(label="Benutzer bearbeiten", use_container_width=True, icon=":material/person:"):
|
if st.button(label="Gruppe bearbeiten", use_container_width=True, icon=":material/edit:"):
|
||||||
# if not st.session_state.selected_user_id is None:
|
if not st.session_state.selected_group_id is None:
|
||||||
# dialog_modify_user(st.session_state.selected_user_id)
|
dialog_edit_group(st.session_state.selected_group_id)
|
||||||
# else:
|
else:
|
||||||
# st.toast("❌ Bitte erst eine Zeile auswählen")
|
st.toast("❌ Bitte erst eine Zeile auswählen")
|
||||||
# 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
|
||||||
|
|
||||||
# with col_delete_user:
|
with col_delete_group:
|
||||||
# if st.button(label="Benutzer löschen", use_container_width=True, icon=":material/person_remove:"):
|
if st.button(label="Gruppe löschen", use_container_width=True, icon=":material/delete:"):
|
||||||
# if not st.session_state.selected_user_id is None:
|
if not st.session_state.selected_group_id is None:
|
||||||
# dialog_delete_user(st.session_state.selected_user_id)
|
dialog_delete_group(st.session_state.selected_group_id)
|
||||||
# else:
|
else:
|
||||||
# st.toast("❌ Bitte erst eine Zeile auswählen")
|
st.toast("❌ Bitte erst eine Zeile auswählen")
|
||||||
# if "delete_msg" in st.session_state:
|
if "delete_msg" in st.session_state:
|
||||||
# st.toast(st.session_state.delete_msg)
|
st.toast(st.session_state.delete_msg)
|
||||||
# del st.session_state.delete_msg
|
del st.session_state.delete_msg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# if txt_search.strip():
|
if txt_search.strip():
|
||||||
# txt_search_norm = txt_search.strip().lower()
|
txt_search_norm = txt_search.strip().lower()
|
||||||
# mask = (
|
mask = (
|
||||||
# df["username"].fillna("").str.lower().str.contains(txt_search_norm)
|
df["group_text"].fillna("").str.lower().str.contains(txt_search_norm)
|
||||||
# | df["firstname"].fillna("").str.lower().str.contains(txt_search_norm)
|
)
|
||||||
# | df["lastname"].fillna("").str.lower().str.contains(txt_search_norm)
|
df_view = df.loc[mask].copy()
|
||||||
# )
|
else:
|
||||||
# df_view = df.loc[mask].copy()
|
df_view = df.copy()
|
||||||
# else:
|
|
||||||
# df_view = df.copy()
|
|
||||||
|
|
||||||
# event = st.dataframe(df_view,key="data", on_select="rerun", selection_mode="single-row")
|
event = st.dataframe(df_view, key="group_data", on_select="rerun", selection_mode="single-row", height="auto")
|
||||||
# rows = event.selection.rows
|
rows = event.selection.rows
|
||||||
# if rows:
|
if rows:
|
||||||
# row_idx = rows[0]
|
row_idx = rows[0]
|
||||||
# st.session_state.selected_user_id = int(df_view.iloc[row_idx]["id"])
|
st.session_state.selected_group_id = int(df_view.iloc[row_idx]["group_id"])
|
||||||
# else:
|
else:
|
||||||
# st.session_state.selected_user_id = None
|
st.session_state.selected_group_id = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,213 @@
|
|||||||
|
import streamlit as st
|
||||||
|
from auth_runtime import require_login
|
||||||
|
# from ui.sidebar import build_sidebar
|
||||||
|
from pathlib import Path
|
||||||
|
from tools.load_css import load_css
|
||||||
|
from app_db.app_db import get_list, send_cmd
|
||||||
|
from tools.numgen import get_num, update_num
|
||||||
|
|
||||||
|
|
||||||
|
DASH_NAME = Path(__file__).stem
|
||||||
|
|
||||||
|
load_css()
|
||||||
|
|
||||||
|
st.set_page_config(page_title="Co-App Benutzer", page_icon=":material/person:", layout="wide", initial_sidebar_state="collapsed")
|
||||||
|
|
||||||
|
authenticator = require_login()
|
||||||
|
st.session_state["authenticator"] = authenticator
|
||||||
|
|
||||||
|
def sidebar():
|
||||||
|
|
||||||
|
fullname = st.session_state.get("fullname")
|
||||||
|
role_text = st.session_state.get("role_text")
|
||||||
|
|
||||||
|
with st.sidebar:
|
||||||
|
|
||||||
|
st.logo("app/images/GMN_Logo_neu_rgb.png", size="small")
|
||||||
|
st.markdown(f"**{fullname}** ({role_text})")
|
||||||
|
|
||||||
|
col1, col2 = st.columns([2,2])
|
||||||
|
with col1:
|
||||||
|
authenticator.logout("Logout")
|
||||||
|
with col2:
|
||||||
|
if st.button("Home", use_container_width=True, icon=":material/home:"):
|
||||||
|
st.switch_page("pages/home.py")
|
||||||
|
|
||||||
|
roles()
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
# Dialog Rollen anlegen
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@st.dialog("Rolle anlegen")
|
||||||
|
def dialog_create_role(role_id):
|
||||||
|
txt_role_id = st.text_input("RoleId", value=role_id, disabled=True)
|
||||||
|
txt_role_text = st.text_input("Gruppenbezeichnung")
|
||||||
|
txt_description = st.text_area("Beschreibung")
|
||||||
|
txt_order_no = st.text_input("Reihenfolge")
|
||||||
|
if st.button("Save"):
|
||||||
|
if send_cmd(f"insert into roles (role_id, role_text, role_description, order_no) " \
|
||||||
|
"values (?, ?, ?, ?)",(txt_role_id, txt_role_text, txt_description, txt_order_no)):
|
||||||
|
st.session_state.save_msg = f"✅ Rolle '{txt_role_text}' erfolgreich gespeichert"
|
||||||
|
update_num(role_id,1,"numgen_role")
|
||||||
|
else:
|
||||||
|
st.session_state.save_msg = "❌ Fehler beim Speichern"
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
# Dialog Rollen bearbeiten
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@st.dialog("Rolle bearbeiten")
|
||||||
|
def dialog_edit_role(role_id):
|
||||||
|
if role_id == None:
|
||||||
|
st.write("keine Rolle ausgewählt")
|
||||||
|
else:
|
||||||
|
sql = """
|
||||||
|
select
|
||||||
|
role_id,
|
||||||
|
role_text,
|
||||||
|
role_description,
|
||||||
|
active,
|
||||||
|
order_no
|
||||||
|
from
|
||||||
|
roles
|
||||||
|
where
|
||||||
|
role_id = ?
|
||||||
|
order by
|
||||||
|
order_no
|
||||||
|
"""
|
||||||
|
df = get_list(sql,(role_id,))
|
||||||
|
|
||||||
|
|
||||||
|
col1, col2 = st.columns([2,1],vertical_alignment="center")
|
||||||
|
with col1:
|
||||||
|
txt_role_text = st.text_input(label="Rollenbezeichnung", value=df.iloc[0]["role_text"])
|
||||||
|
with col2:
|
||||||
|
is_active = st.checkbox(label="Aktiv", value=df.iloc[0]["active"])
|
||||||
|
txt_role_description = st.text_area(label="Beschreibung", value=df.iloc[0]["role_description"])
|
||||||
|
txt_oder_no = st.text_input(label="Reihenfolge", value=df.iloc[0]["order_no"])
|
||||||
|
|
||||||
|
if st.button("Save"):
|
||||||
|
sql = """
|
||||||
|
update roles set
|
||||||
|
role_text = ?,
|
||||||
|
active = ?,
|
||||||
|
role_description = ?,
|
||||||
|
order_no = ?
|
||||||
|
where role_id = ?
|
||||||
|
"""
|
||||||
|
params = (txt_role_text, is_active, txt_role_description, txt_oder_no, role_id)
|
||||||
|
|
||||||
|
if send_cmd(sql, params):
|
||||||
|
st.session_state.save_msg = f"✅ Rolle '{txt_role_text}' erfolgreich geändert"
|
||||||
|
else:
|
||||||
|
st.session_state.save_msg = "❌ Fehler beim Speichern"
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
# Dialog Rollen löschen
|
||||||
|
#-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@st.dialog("Rolle löschen")
|
||||||
|
def dialog_delete_role(role_id):
|
||||||
|
if role_id == None:
|
||||||
|
st.write("keine Rolle ausgewählt")
|
||||||
|
else:
|
||||||
|
df = get_list("select role_text from roles where role_id = ?",(role_id,))
|
||||||
|
role_text = df.iloc[0]["role_text"]
|
||||||
|
if role_text != "admin":
|
||||||
|
st.write(f"Die Rolle {role_text} wird gelöscht! Sind Sie sicher?")
|
||||||
|
if st.button("Löschen"):
|
||||||
|
if send_cmd("delete from roles where role_id = ?",(role_id,)):
|
||||||
|
st.session_state.delete_msg = f"✅ Rolle '{role_text}' erfolgreich gelöscht!"
|
||||||
|
else:
|
||||||
|
st.session_state.delete_msg = f"❌ Rolle '{role_text}' konnte nicht gelöscht werden!"
|
||||||
|
else:
|
||||||
|
st.session_state.delete_msg = f"❌ Rolle '{role_text}' darf nicht gelöscht werden!"
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
|
||||||
|
def roles():
|
||||||
|
|
||||||
|
if "selected_role_id" not in st.session_state:
|
||||||
|
st.session_state.selected_role_id = None
|
||||||
|
|
||||||
|
|
||||||
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
# Rollenverwaltung
|
||||||
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
df = get_list("""
|
||||||
|
select
|
||||||
|
role_id,
|
||||||
|
role_text,
|
||||||
|
role_description,
|
||||||
|
active,
|
||||||
|
order_no
|
||||||
|
from
|
||||||
|
roles
|
||||||
|
order by
|
||||||
|
order_no
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
col_find_role, col_create_role, col_edit_role, col_delete_role = st.columns([3,2,2,2], vertical_alignment="bottom")
|
||||||
|
|
||||||
|
with col_find_role:
|
||||||
|
txt_search = st.text_input(label="Suche", label_visibility="hidden", placeholder="Rolle", icon=":material/search:")
|
||||||
|
|
||||||
|
with col_create_role:
|
||||||
|
if st.button(label="Rolle anlegen", use_container_width=True, icon=":material/add:"):
|
||||||
|
dialog_create_role(get_num("numgen_role"))
|
||||||
|
if "save_msg" in st.session_state:
|
||||||
|
st.toast(st.session_state.save_msg,)
|
||||||
|
del st.session_state.save_msg
|
||||||
|
|
||||||
|
with col_edit_role:
|
||||||
|
if st.button(label="Rolle bearbeiten", use_container_width=True, icon=":material/edit:"):
|
||||||
|
if not st.session_state.selected_role_id is None:
|
||||||
|
dialog_edit_role(st.session_state.selected_role_id)
|
||||||
|
else:
|
||||||
|
st.toast("❌ Bitte erst eine Zeile auswählen")
|
||||||
|
if "save_msg" in st.session_state:
|
||||||
|
st.toast(st.session_state.save_msg)
|
||||||
|
del st.session_state.save_msg
|
||||||
|
|
||||||
|
with col_delete_role:
|
||||||
|
if st.button(label="Rolle löschen", use_container_width=True, icon=":material/delete:"):
|
||||||
|
if not st.session_state.selected_role_id is None:
|
||||||
|
dialog_delete_role(st.session_state.selected_role_id)
|
||||||
|
else:
|
||||||
|
st.toast("❌ Bitte erst eine Zeile auswählen")
|
||||||
|
if "delete_msg" in st.session_state:
|
||||||
|
st.toast(st.session_state.delete_msg)
|
||||||
|
del st.session_state.delete_msg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if txt_search.strip():
|
||||||
|
txt_search_norm = txt_search.strip().lower()
|
||||||
|
mask = (
|
||||||
|
df["role_text"].fillna("").str.lower().str.contains(txt_search_norm)
|
||||||
|
)
|
||||||
|
df_view = df.loc[mask].copy()
|
||||||
|
else:
|
||||||
|
df_view = df.copy()
|
||||||
|
|
||||||
|
event = st.dataframe(df_view, key="role_data", on_select="rerun", selection_mode="single-row", height="auto")
|
||||||
|
rows = event.selection.rows
|
||||||
|
if rows:
|
||||||
|
row_idx = rows[0]
|
||||||
|
st.session_state.selected_role_id = int(df_view.iloc[row_idx]["role_id"])
|
||||||
|
else:
|
||||||
|
st.session_state.selected_role_id = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sidebar()
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ def dialog_delete_user(id):
|
|||||||
|
|
||||||
|
|
||||||
@st.dialog("Benutzer bearbeiten")
|
@st.dialog("Benutzer bearbeiten")
|
||||||
def dialog_modify_user(id):
|
def dialog_edit_user(id):
|
||||||
if id == None:
|
if id == None:
|
||||||
st.write("kein Benutzer ausgewählt")
|
st.write("kein Benutzer ausgewählt")
|
||||||
else:
|
else:
|
||||||
@@ -120,8 +120,11 @@ def dialog_modify_user(id):
|
|||||||
idx = roles.index(role)
|
idx = roles.index(role)
|
||||||
except:
|
except:
|
||||||
idx = None
|
idx = None
|
||||||
|
col1, col2 = st.columns([2,1],vertical_alignment="center")
|
||||||
|
with col1:
|
||||||
txt_username = st.text_input(label="Benutzername", value=df.iloc[0]["user"])
|
txt_username = st.text_input(label="Benutzername", value=df.iloc[0]["user"])
|
||||||
|
with col2:
|
||||||
|
is_active = st.checkbox(label="Aktiv", value=df.iloc[0]["active"])
|
||||||
txt_firstname = st.text_input(label="Vorname", value=df.iloc[0]["firstname"])
|
txt_firstname = st.text_input(label="Vorname", value=df.iloc[0]["firstname"])
|
||||||
txt_lastname = st.text_input(label="Nachname", value=df.iloc[0]["lastname"])
|
txt_lastname = st.text_input(label="Nachname", value=df.iloc[0]["lastname"])
|
||||||
txt_email = st.text_input(label="Email", value=df.iloc[0]["email"])
|
txt_email = st.text_input(label="Email", value=df.iloc[0]["email"])
|
||||||
@@ -137,6 +140,7 @@ def dialog_modify_user(id):
|
|||||||
sql = """
|
sql = """
|
||||||
update users set
|
update users set
|
||||||
username = ?,
|
username = ?,
|
||||||
|
active = ?,
|
||||||
firstname = ?,
|
firstname = ?,
|
||||||
lastname = ?,
|
lastname = ?,
|
||||||
email = ?,
|
email = ?,
|
||||||
@@ -145,12 +149,13 @@ def dialog_modify_user(id):
|
|||||||
role_id = ?
|
role_id = ?
|
||||||
where id = ?
|
where id = ?
|
||||||
"""
|
"""
|
||||||
params = (txt_username, txt_firstname, txt_lastname, txt_email, pw_hash, new_pwd, get_id(cmb_role), id)
|
params = (txt_username, is_active, txt_firstname, txt_lastname, txt_email, pw_hash, new_pwd, get_id(cmb_role), id)
|
||||||
# send_cmd(sql,(txt_username, txt_firstname, txt_lastname, txt_email, pw_hash, new_pwd, get_id(cmb_role), id))
|
# send_cmd(sql,(txt_username, txt_firstname, txt_lastname, txt_email, pw_hash, new_pwd, get_id(cmb_role), id))
|
||||||
else:
|
else:
|
||||||
sql = """
|
sql = """
|
||||||
update users set
|
update users set
|
||||||
username = ?,
|
username = ?,
|
||||||
|
active = ?,
|
||||||
firstname = ?,
|
firstname = ?,
|
||||||
lastname = ?,
|
lastname = ?,
|
||||||
email = ?,
|
email = ?,
|
||||||
@@ -158,7 +163,7 @@ def dialog_modify_user(id):
|
|||||||
role_id = ?
|
role_id = ?
|
||||||
where id = ?
|
where id = ?
|
||||||
"""
|
"""
|
||||||
params = (txt_username, txt_firstname, txt_lastname, txt_email, new_pwd, get_id(cmb_role), id)
|
params = (txt_username, is_active, txt_firstname, txt_lastname, txt_email, new_pwd, get_id(cmb_role), id)
|
||||||
# send_cmd(sql,(txt_username, txt_firstname, txt_lastname, txt_email, new_pwd, get_id(cmb_role), id))
|
# send_cmd(sql,(txt_username, txt_firstname, txt_lastname, txt_email, new_pwd, get_id(cmb_role), id))
|
||||||
print (params)
|
print (params)
|
||||||
if send_cmd(sql, params):
|
if send_cmd(sql, params):
|
||||||
@@ -201,7 +206,7 @@ def user():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
col_find_user, col_create_user, col_modify_user, col_delete_user = st.columns([3,2,2,2], vertical_alignment="bottom")
|
col_find_user, col_create_user, col_edit_user, col_delete_user = st.columns([3,2,2,2], vertical_alignment="bottom")
|
||||||
|
|
||||||
with col_find_user:
|
with col_find_user:
|
||||||
txt_search = st.text_input(label="Suche", label_visibility="hidden", placeholder="Benutzer, Vorname, ...", icon=":material/search:")
|
txt_search = st.text_input(label="Suche", label_visibility="hidden", placeholder="Benutzer, Vorname, ...", icon=":material/search:")
|
||||||
@@ -213,10 +218,10 @@ def user():
|
|||||||
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
|
||||||
|
|
||||||
with col_modify_user:
|
with col_edit_user:
|
||||||
if st.button(label="Benutzer bearbeiten", use_container_width=True, icon=":material/person:"):
|
if st.button(label="Benutzer bearbeiten", use_container_width=True, icon=":material/person_edit:"):
|
||||||
if not st.session_state.selected_user_id is None:
|
if not st.session_state.selected_user_id is None:
|
||||||
dialog_modify_user(st.session_state.selected_user_id)
|
dialog_edit_user(st.session_state.selected_user_id)
|
||||||
else:
|
else:
|
||||||
st.toast("❌ Bitte erst eine Zeile auswählen")
|
st.toast("❌ Bitte erst eine Zeile auswählen")
|
||||||
if "save_msg" in st.session_state:
|
if "save_msg" in st.session_state:
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ import os
|
|||||||
APP_ENV = os.environ.get("APP_ENV", "dev")
|
APP_ENV = os.environ.get("APP_ENV", "dev")
|
||||||
logger = setup_logging(APP_ENV)
|
logger = setup_logging(APP_ENV)
|
||||||
|
|
||||||
def get_num(numgen, step=10):
|
def get_num(numgen):
|
||||||
num = get_value(f"select param_value from param where parameter = '{numgen}'")
|
num = get_value(f"select param_value from param where parameter = '{numgen}'")
|
||||||
print(int(num) + step)
|
#print(int(num) + step)
|
||||||
update_num(num, 10, numgen)
|
# update_num(num, step, numgen)
|
||||||
return num
|
return num
|
||||||
|
|
||||||
def update_num(num, step, numgen):
|
def update_num(num, step, numgen):
|
||||||
|
print(num,step,numgen)
|
||||||
try:
|
try:
|
||||||
send_cmd(f"update param set param_value = {int(num) + step} where parameter = '{numgen}'")
|
send_cmd(f"update param set param_value = {int(num) + step} where parameter = '{numgen}'")
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -12,6 +12,19 @@ def get_roles():
|
|||||||
|
|
||||||
return df
|
return df
|
||||||
|
|
||||||
|
def get_groups():
|
||||||
|
|
||||||
|
sql = """
|
||||||
|
select
|
||||||
|
group_id || ' | ' || group_text as "group"
|
||||||
|
from
|
||||||
|
groups
|
||||||
|
"""
|
||||||
|
df = get_list(sql)
|
||||||
|
|
||||||
|
return df
|
||||||
|
|
||||||
|
|
||||||
def get_id(id_text: str):
|
def get_id(id_text: str):
|
||||||
id = int(id_text.split("|")[0])
|
id = int(id_text.split("|")[0])
|
||||||
if not id:
|
if not id:
|
||||||
|
|||||||
Reference in New Issue
Block a user