diff --git a/admin.py b/admin.py index bf48431..afb8c8c 100644 --- a/admin.py +++ b/admin.py @@ -38,7 +38,7 @@ def page_admin(): settings = ui.tab('Einstellungen') users = ui.tab('Benutzer') - 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") @@ -291,7 +291,8 @@ Dies kann nicht rückgägig gemacht werden!''') day_type.content = "**Kein Arbeitstag**" day_type.set_visibility(True) - + if day_in_list.strftime("%Y-%m-%d") in data["holidays"]: + day_type.content = f'**{data["holidays"][day_in_list.strftime("%Y-%m-%d")]}**' # Saldo für den Tag berechnen @@ -461,10 +462,11 @@ Dies kann nicht rückgägig gemacht werden!''') output_dict["admin_password"] = data["admin_password"] output_dict["port"] = port.value output_dict["secret"] = secret + output_dict["holidays"] = data["holidays"] json_dict = json.dumps(output_dict, indent=4) with open(f"{scriptpath}/{usersettingsfilename}", "w") as outputfile: outputfile.write(json_dict) - if old_port != int(port.value): + if int(old_port) != int(port.value): with ui.dialog() as dialog, ui.card(): ui.markdown("Damit die Porteinstellungen wirksam werden, muss der Server neu gestartet werden.") ui.button("OK", on_click=lambda: dialog.close()) @@ -488,42 +490,79 @@ Dies kann nicht rückgägig gemacht werden!''') old_port = data["port"] port.value = old_port - @ui.refreshable def holiday_section(): with ui.card(): ui.markdown('**Feiertage:**') - holidays = data["holidays"] - holidays.sort() - year_list = [ ] + def new_holiday_entry(): + def add_holiday_to_dict(): + year_from_picker = int(datepicker.value.split("-")[0]) + month_from_picker = int(datepicker.value.split("-")[1]) + day_from_picker = int(datepicker.value.split("-")[2]) + for i in range(0, int(repetition.value)): + repetition_date_dt = datetime.datetime(year_from_picker + i, month_from_picker, day_from_picker) + date_entry = repetition_date_dt.strftime('%Y-%m-%d') + data["holidays"][date_entry] = description.value + print(data['holidays']) + holiday_buttons_grid.refresh() + dialog.close() - # Jahresliste erzeugen - for i in holidays: - i_split = i.split("-") - year = int(i_split[0]) - year_list.append(year) + with ui.dialog() as dialog, ui.card(): + with ui.grid(columns='auto auto'): + ui.markdown('Geben Sie den neuen Feiertag ein:').classes('col-span-2') + datepicker = ui.date(value=datetime.datetime.now().strftime('%Y-%m-%d')).classes('col-span-2') + description = ui.input('Beschreibung').classes('col-span-2') + repetition = ui.number('Für Jahre wiederholen', value=1, min=1, precision=0).classes('col-span-2') + ui.button("OK", on_click=add_holiday_to_dict) + ui.button('Abbrechen', on_click=dialog.close) + dialog.open() - year_list = list(set(year_list)) - year_dict = { } + @ui.refreshable + def holiday_buttons_grid(): - # Jahresdictionary konstruieren - for i in year_list: - year_dict[i] = [ ] + holidays = list(data["holidays"]) + holidays.sort() - for i in holidays: - i_split = i.split("-") - year = int(i_split[0]) - month = int(i_split[1]) - day = int(i_split[2]) - date_dt = datetime.datetime(year, month, day) - year_dict[year].append(date_dt) + year_list = [] + + # Jahresliste erzeugen + for i in holidays: + i_split = i.split("-") + year = int(i_split[0]) + year_list.append(year) + + year_list = list(set(year_list)) + year_dict = {} + + # Jahresdictionary konstruieren + for i in year_list: + year_dict[i] = [] + + for i in holidays: + i_split = i.split("-") + year = int(i_split[0]) + month = int(i_split[1]) + day = int(i_split[2]) + date_dt = datetime.datetime(year, month, day) + year_dict[year].append(date_dt) + + def del_holiday_entry(entry): + del(data['holidays'][entry.strftime('%Y-%m-%d')]) + holiday_buttons_grid.refresh() + + with ui.grid(columns='auto auto'): + ui.space() + with ui.row(): + ui.button("Neuer Eintrag", on_click=new_holiday_entry) + + for year_entry in year_list: + ui.markdown(f"{str(year_entry)}:") + with ui.row(): + for entry in year_dict[year_entry]: + date_label = entry.strftime("%d.%m.%Y") + ui.button(f"{data['holidays'][entry.strftime('%Y-%m-%d')]} ({date_label})", on_click=lambda entry=entry: del_holiday_entry(entry)).classes('bg-blue') + holiday_buttons_grid() - for year_entry in year_list: - with ui.row(): - ui.markdown(f"{str(year_entry)}:") - for entry in year_dict[year_entry]: - date_label = entry.strftime("%d.%m.%Y") - ui.button(date_label) holiday_section() ui.button("Speichern", on_click=save_admin_settings) diff --git a/settings.json b/settings.json index 1097177..c6d1e98 100644 --- a/settings.json +++ b/settings.json @@ -3,5 +3,10 @@ "admin_password": "8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92", "port": "8090", "secret": "ftgzuhjikg,mt5jn46uzer8sfi9okrmtzjhndfierko5zltjhdgise", - "holidays": [ "2024-01-01", "2024-12-25", "2025-01-01", "2025-05-01"] + "holidays": { + "2024-01-01": "Tag der Arbeit", + "2024-12-25": "1. Weihnachtsfeiertag", + "2025-01-01": "Neujahr", + "2025-05-01": "Tag der Arbeit" + } } \ No newline at end of file diff --git a/users.py b/users.py index 5f9c953..eca1707 100644 --- a/users.py +++ b/users.py @@ -297,7 +297,7 @@ class user: # Fertage prüfen settings = load_adminsettings() - holidays = settings["holidays"] + holidays = list(settings["holidays"]) today_dt = datetime.datetime(int(year), int(month), int(day)) check_date_list = [ ] diff --git a/users/testuser1/2025-5.txt b/users/testuser1/2025-5.txt index 36ee3bc..e69de29 100644 --- a/users/testuser1/2025-5.txt +++ b/users/testuser1/2025-5.txt @@ -1,2 +0,0 @@ -1746090493 -1746090500