Beginn API
Beginn Übersichtsseite für Benutzer
This commit is contained in:
parent
45a3cbb57c
commit
2b9bad6ad3
17
admin.py
17
admin.py
@ -106,7 +106,6 @@ def page_admin():
|
||||
select_month = ui.select(options=available_months_dict, value=set_month).bind_value_to(month_binder, 'value')
|
||||
select_year = ui.select(options=available_years, value=set_year, on_change=update_months).bind_value_to(year_binder, 'value')
|
||||
|
||||
|
||||
month_header = ui.markdown(f"###Buchungen für **{current_user.fullname}** für **{calendar.month_name[int(select_month.value)]} {select_year.value}**")
|
||||
|
||||
# Tabelle aufbauen
|
||||
@ -180,7 +179,7 @@ Dies kann nicht rückgägig gemacht werden!''')
|
||||
def edit_entry(t_stamp, day):
|
||||
|
||||
with ui.dialog() as edit_dialog, ui.card():
|
||||
ui.markdown("###Eintrag bearbeiten")
|
||||
ui.markdown("**Eintrag bearbeiten**")
|
||||
timestamp = datetime.datetime.fromtimestamp(int(t_stamp))
|
||||
input_time = ui.time().props('format24h now-btn').classes('w-full justify-center')
|
||||
|
||||
@ -338,9 +337,15 @@ Dies kann nicht rückgägig gemacht werden!''')
|
||||
add_dialog.move(calendar_card)
|
||||
|
||||
def add_absence(absence_type, day):
|
||||
with ui.dialog() as dialog, ui.card():
|
||||
ui.markdown(f'Für welchen Zeitraum soll *{absence_entries[absence_type]["name"]}* eingetragen werden?')
|
||||
absence_dates = ui.date().props('range')
|
||||
with ui.dialog() as dialog, ui.card().classes('w-[350px]'):
|
||||
ui.markdown(f'Für welchen Zeitraum soll *{absence_entries[absence_type]["name"]}* eingetragen werden?').classes('w-full')
|
||||
absence_dates = ui.date().props('range today-btn').classes('w-full justify-center')
|
||||
absence_dates._props['locale'] = {'daysShort': ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'],
|
||||
'months': ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
|
||||
'monthsShort': ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez']}
|
||||
absence_dates._props['title'] = absence_entries[absence_type]["name"]
|
||||
absence_dates._props['minimal'] = True
|
||||
|
||||
if day < 10:
|
||||
day = f"0{str(day)}"
|
||||
else:
|
||||
@ -398,7 +403,7 @@ Dies kann nicht rückgägig gemacht werden!''')
|
||||
dialog.close()
|
||||
|
||||
|
||||
with ui.grid(columns=3):
|
||||
with ui.grid(columns=3).classes('w-full justify-center'):
|
||||
ui.button("Speichern", on_click=add_absence_save)
|
||||
ui.space()
|
||||
ui.button("Abbrechen", on_click=dialog.close)
|
||||
|
102
api.py
Normal file
102
api.py
Normal file
@ -0,0 +1,102 @@
|
||||
import sys
|
||||
from logging import exception
|
||||
|
||||
from nicegui import *
|
||||
|
||||
from definitions import *
|
||||
from web_ui import *
|
||||
from users import *
|
||||
from datetime import datetime
|
||||
|
||||
import calendar
|
||||
|
||||
|
||||
# Überblicksseite zum Ausdrucken oder als PDF speichern
|
||||
@ui.page('/api/overview/month/{username}-{year}-{month}')
|
||||
def page(username: str, year: int, month: int):
|
||||
|
||||
#try:
|
||||
current_user = user(username)
|
||||
ui.page_title(f"Bericht für {current_user.fullname} für {calendar.month_name[month]} {year}")
|
||||
ui.label(datetime.now().strftime('%d.%m.%Y')).classes('absolute top-5 right-5')
|
||||
ui.markdown(f'#Bericht für {current_user.fullname} für {calendar.month_name[month]} {year}')
|
||||
|
||||
columns = [
|
||||
{'name': 'date', 'label': 'Datum', 'field': 'date', 'required': True, 'align': 'left'},
|
||||
{'name:': 'bookings', 'label': 'Buchungen', 'field': 'bookings', 'align': 'left'},
|
||||
{'name:': 'is_time', 'label': 'Ist', 'field': 'is_time', 'align': 'left'},
|
||||
{'name:': 'target_time', 'label': 'Soll', 'field': 'target_time', 'align': 'left'},
|
||||
{'name:': 'total', 'label': 'Saldo', 'field': 'total', 'align': 'left'}
|
||||
]
|
||||
|
||||
rows = [ ]
|
||||
|
||||
# Timestamp in ein Array schreiben
|
||||
timestamps = current_user.get_timestamps(year, month)
|
||||
timestamps.sort()
|
||||
|
||||
# Abwesenheitsdaten in ein Dict schreiben
|
||||
user_absent = current_user.get_absence(year, month)
|
||||
|
||||
# Dictionary für sortierte Timestamps
|
||||
timestamps_dict = { }
|
||||
|
||||
# Dictionary mit zunächst leeren Tageinträgen befüllen
|
||||
for day in range(1, monthrange(year, month)[1] + 1):
|
||||
# Jeder Tag bekommt eine leere Liste
|
||||
timestamps_dict[day] = [ ]
|
||||
|
||||
# Timestamps den Monatstagen zuordnen
|
||||
for stamp in timestamps:
|
||||
day_of_month_of_timestamp = datetime.fromtimestamp(int(stamp)).day
|
||||
timestamps_dict[day_of_month_of_timestamp].append(int(stamp))
|
||||
timestamps_dict[day_of_month_of_timestamp].append(int(stamp))
|
||||
|
||||
general_saldo = 0
|
||||
|
||||
# Gehe jeden einzelnen Tag des Dictionaries für die Timestamps durch
|
||||
for day in list(timestamps_dict):
|
||||
booking_text = ""
|
||||
current_day_date = f"{day}.{month}.{year}"
|
||||
|
||||
# Abwesenheitseinträge
|
||||
try:
|
||||
# Abwesenheitszeiten behandeln
|
||||
for i in list(user_absent):
|
||||
if int(i) == day:
|
||||
booking_text += absence_entries[user_absent[i]]["name"] + " "
|
||||
|
||||
# Buchungen behandeln
|
||||
for i in range(len(timestamps_dict[day])):
|
||||
try:
|
||||
temp_pair = [timestamps_dict[day][i], timestamps_dict[day][i + 1]]
|
||||
booking_text = booking_text + str(datetime.fromtimestamp(temp_pair[0]).strftime('%H:%M')) + "-" + str(datetime.fromtimestamp(temp_pair[1]).strftime('%H:%M')) + "\n"
|
||||
|
||||
except:
|
||||
if len(timestamps_dict[day]) % 2 != 0:
|
||||
booking_text += datetime.fromtimestamp(int(timestamps_dict[day][i])).strftime('%H:%M')
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
pass
|
||||
|
||||
rows.append({'date': current_day_date, 'bookings': booking_text, 'is_time': 0, 'target_time': 0, 'total': 0})
|
||||
|
||||
|
||||
|
||||
|
||||
#rows = [
|
||||
# {'date': '1.1.2024', 'bookings': '12345', 'is_time': '12345', 'target_time': '98765', 'total': 123}
|
||||
#]
|
||||
|
||||
overview_table = ui.table(columns=columns, rows=rows).classes('w-120')
|
||||
|
||||
|
||||
overview_table.add_slot('body-cell', r'''
|
||||
<td :props="props" :style="{'white-space':'pre-line'}">{{ props.value }}</td>
|
||||
''')
|
||||
|
||||
#except Exception as e:
|
||||
# print(e)
|
||||
# ui.markdown('#Fehler')
|
||||
# ui.markdown('Benutzer existiert nicht')
|
4
main.py
4
main.py
@ -6,6 +6,8 @@ from login import *
|
||||
from users import *
|
||||
from touchscreen import *
|
||||
from definitions import *
|
||||
from api import *
|
||||
|
||||
import json
|
||||
|
||||
|
||||
@ -19,7 +21,7 @@ def main():
|
||||
port = int(data["port"])
|
||||
secret = data["secret"]
|
||||
|
||||
ui.run(port=port, storage_secret=secret)
|
||||
ui.run(port=port, storage_secret=secret, language='de-DE')
|
||||
|
||||
if __name__ in ("__main__", "__mp_main__"):
|
||||
main()
|
||||
|
15
playgound.py
15
playgound.py
@ -1,5 +1,16 @@
|
||||
from nicegui import ui
|
||||
|
||||
ui.time().props('now-btn format24h')
|
||||
columns=[
|
||||
{'name': 'name', 'label': 'Name', 'field': 'name', 'align': 'left', 'style': 'text-wrap: wrap'},
|
||||
{'name': 'age', 'label': 'Age', 'field': 'age'},
|
||||
]
|
||||
rows=[
|
||||
{'name': 'Alice', 'age': 18},
|
||||
{'name': 'Bob', 'age': 21},
|
||||
{'name': 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam nec purus nec nunc ultricies'},
|
||||
]
|
||||
|
||||
ui.run(port=9000)
|
||||
ui.table(columns=columns, rows=rows).classes('w-80')
|
||||
|
||||
|
||||
ui.run(language="de-DE", port=9000)
|
Loading…
x
Reference in New Issue
Block a user