From ca610d4381622efac2545531d51b073d02591cad Mon Sep 17 00:00:00 2001 From: Alexander Malzkuhn Date: Tue, 22 Apr 2025 17:43:46 +0200 Subject: [PATCH] =?UTF-8?q?Admin=C3=BCbersicht=20Timestamps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lesefunktion für Timestamps und Erzeugung von Buttons in der Übersicht --- users.py | 6 ++++ web_ui.py | 85 +++++++++++++++++++++++++++++++++---------------------- 2 files changed, 57 insertions(+), 34 deletions(-) diff --git a/users.py b/users.py index d88c020..0e37db3 100644 --- a/users.py +++ b/users.py @@ -132,6 +132,12 @@ class user: available_months.append(entry[5:-4]) return available_months + def get_timestamps(self, year, month): + with open(f"{self.userfolder}/{year}-{month}.txt", "r") as file: + timestamps = file.readlines() + timestamps.sort() + return timestamps + # Benutzer auflisten def list_users(): users = [d for d in os.listdir(userfolder) if os.path.isdir(os.path.join(userfolder, d))] diff --git a/web_ui.py b/web_ui.py index 91aeca2..85b021a 100644 --- a/web_ui.py +++ b/web_ui.py @@ -89,7 +89,7 @@ def page_admin(): users = ui.tab('Benutzer') settings = ui.tab('Einstellungen') - with ui.tab_panels(tabs, value=time_overview): + with (ui.tab_panels(tabs, value=time_overview)): with ui.tab_panel(time_overview): ui.markdown("##Übersichten") @@ -109,30 +109,7 @@ def page_admin(): # Tabelle konstruieren with ui.card(): - with ui.row(): - def update_month_and_year(): - try: - calendar_card.clear() - except: - pass - with ui.card() as calendar_card: - with ui.grid(columns=6): - ui.markdown("Datum") - ui.markdown("Buchungen") - ui.markdown("Soll") - ui.markdown("Ist") - ui.markdown("+/-") - ui.space() - for day in range(1, monthrange(int(select_year.value), int(select_month.value))[1] + 1): - ui.markdown(f"{day}. {calendar.month_name[int(select_month.value)]}") - - # ---> Hier die Schleife für die Buchungen - ui.markdown('BUCHUNGEN') - ui.markdown("Soll") - ui.markdown("Ist") - ui.markdown("+/-") - ui.button("Bearbeiten") - + with ui.row() as timetable_header: def update_months(): current_user = user(time_user.value) @@ -158,25 +135,65 @@ def page_admin(): select_month = ui.select(options=available_months_dict) - try: - select_month.value = str(current_month) - except: - pass - select_year = ui.select(options=available_years, on_change=update_months) try: select_year.value = str(current_year) except: pass + try: + select_month.value = str(current_month) + except: + select_month.value = str(available_months[0]) - ui.button("Aktualisieren", on_click=update_month_and_year) - - ui.markdown(f"###Buchungen für {calendar.month_name[current_month]} {current_year}") + month_header = ui.markdown(f"###Buchungen für {calendar.month_name[int(select_month.value)]} {select_year.value}") # Tabelle aufbauen - update_month_and_year() + with ui.card() as calendar_card: + def update_month_and_year(): + with ui.grid(columns=6) as table_grid: + ui.markdown("Datum") + ui.markdown("Buchungen") + ui.markdown("Soll") + ui.markdown("Ist") + ui.markdown("Saldo") + ui.space() + current_user = user(time_user.value) + timestamps = current_user.get_timestamps(year=select_year.value, month=select_month.value) + + for day in range(1, monthrange(int(select_year.value), int(select_month.value))[1] + 1): + ui.markdown(f"{day}. {calendar.month_name[int(select_month.value)]}") + + # ---> Hier die Schleife für die Buchungen + #ui.markdown('BUCHUNGEN') + with ui.row(): + counter = 0 + for i in timestamps: + actual_timestamp = datetime.datetime.fromtimestamp(int(i)) + timestamp_day = actual_timestamp.strftime('%-d') + + if int(timestamp_day) == int(day): + counter += 1 + current_button = ui.button(actual_timestamp.strftime('%H:%m')) + if counter % 2 == 0: + current_button.props('color=red') + else: + current_button.props('color=green') + ui.markdown("Soll") + ui.markdown("Ist") + ui.markdown("+/-") + ui.button("Eintrag hinzufügen") + table_grid.move(calendar_card) + update_month_and_year() + + def clear_card(): + calendar_card.clear() + update_month_and_year() + month_header.set_content(f"###Buchungen für {calendar.month_name[int(select_month.value)]} {select_year.value}") + + button_update = ui.button("Aktualisieren", on_click=clear_card) + button_update.move(timetable_header) with ui.tab_panel(admin_user):