imports angespasst Stylinganpassungen im Adminbereich (Responsive, Farben für die Feiertagsbuttons)
85 lines
3.8 KiB
Python
85 lines
3.8 KiB
Python
from datetime import datetime
|
|
|
|
from nicegui import ui, app
|
|
|
|
from lib.users import *
|
|
from lib.definitions import *
|
|
from lib.web_ui import *
|
|
from calendar import monthrange
|
|
|
|
import hashlib
|
|
import calendar
|
|
import locale
|
|
|
|
@ui.page('/touchscreen')
|
|
def page_touchscreen():
|
|
|
|
if load_adminsettings()["touchscreen"]:
|
|
|
|
def button_click(name):
|
|
#nonlocal buttons
|
|
current_user = user(name)
|
|
current_user.timestamp()
|
|
#if current_user.stamp_status() == status_in:
|
|
# buttons[name].props('color=green')
|
|
# ui.notify(status_in)
|
|
#else:
|
|
# buttons[name].props('color=red')
|
|
# ui.notify(status_out)
|
|
user_buttons.refresh()
|
|
|
|
pageheader("Stempeluhr")
|
|
ui.page_title("Stempeluhr")
|
|
|
|
admin_settings = load_adminsettings()
|
|
userlist = list_users()
|
|
number_of_users = len(userlist)
|
|
buttons = { }
|
|
|
|
@ui.refreshable
|
|
def user_buttons():
|
|
if number_of_users > 5:
|
|
number_of_columns = 5
|
|
else:
|
|
number_of_columns = number_of_users
|
|
|
|
with ui.grid(columns=number_of_columns).classes('w-full center'):
|
|
for name in userlist:
|
|
current_user = user(name)
|
|
current_button = ui.button(on_click=lambda name=name: button_click(name)).classes(f'w-md h-full min-h-[{admin_settings["button_height"]}px]')
|
|
with current_button:
|
|
if admin_settings["photos_on_touchscreen"]:
|
|
try:
|
|
with open(current_user.photofile, 'r') as file:
|
|
pass
|
|
file.close()
|
|
ui.image(current_user.photofile).classes(f'max-h-[{admin_settings["picture_height"]}px]').props('fit=scale-down')
|
|
except:
|
|
pass
|
|
column_classes = "w-full items-center"
|
|
if admin_settings["times_on_touchscreen"] or admin_settings["photos_on_touchscreen"]:
|
|
column_classes += " self-end"
|
|
with ui.column().classes(column_classes):
|
|
if admin_settings["times_on_touchscreen"]:
|
|
todays_timestamps = current_user.get_day_timestamps()
|
|
# Wenn wir Einträge haben
|
|
if len(todays_timestamps) > 0 and admin_settings["times_on_touchscreen"]:
|
|
table_string = ""
|
|
for i in range(0, len(todays_timestamps), 2):
|
|
try:
|
|
table_string += f"{datetime.datetime.fromtimestamp(todays_timestamps[i]).strftime('%H:%M')} - {datetime.datetime.fromtimestamp(todays_timestamps[i+1]).strftime('%H:%M')}"
|
|
except IndexError:
|
|
table_string += f"{datetime.datetime.fromtimestamp(todays_timestamps[i]).strftime('%H:%M')} -"
|
|
if i < len(todays_timestamps) - 2:
|
|
table_string += ", "
|
|
ui.markdown(table_string)
|
|
ui.label(current_user.fullname).classes('text-center')
|
|
if current_user.stamp_status() == status_in:
|
|
current_button.props('color=green')
|
|
else:
|
|
current_button.props('color=red')
|
|
buttons[name] = current_button
|
|
user_buttons()
|
|
|
|
else:
|
|
pageheader("Interface deaktiviert") |