first feasability of event management feature
This commit is contained in:
@@ -2,9 +2,13 @@
|
||||
import requests
|
||||
import json
|
||||
from flask import session
|
||||
from dash import Input, Output, State, callback, ctx, dash
|
||||
from dash import Input, Output, State, callback, ctx, dash, no_update
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
# --- Modalbox öffnen: jetzt auch auf Kalenderklick reagieren ---
|
||||
|
||||
sys.path.append('/workspace')
|
||||
|
||||
print("appointments_callbacks.py geladen")
|
||||
@@ -69,19 +73,86 @@ def load_events(view_dates):
|
||||
|
||||
|
||||
@callback(
|
||||
Output("appointment-modal", "opened"),
|
||||
[
|
||||
Output("appointment-modal", "opened"),
|
||||
Output("start-date-input", "value", allow_duplicate=True),
|
||||
Output("time-start", "value", allow_duplicate=True),
|
||||
Output("time-end", "value", allow_duplicate=True),
|
||||
],
|
||||
[
|
||||
Input("calendar", "lastDateClick"),
|
||||
Input("calendar", "lastSelect"),
|
||||
Input("open-appointment-modal-btn", "n_clicks"),
|
||||
Input("close-appointment-modal-btn", "n_clicks")
|
||||
Input("close-appointment-modal-btn", "n_clicks"),
|
||||
],
|
||||
State("appointment-modal", "opened"),
|
||||
prevent_initial_call=True
|
||||
)
|
||||
def toggle_appointment_modal(open_click, close_click, is_open):
|
||||
from dash import ctx
|
||||
def open_modal(date_click, select, open_click, close_click, is_open):
|
||||
trigger = ctx.triggered_id
|
||||
|
||||
# Bereichsauswahl (lastSelect)
|
||||
if trigger == "calendar" and select:
|
||||
try:
|
||||
start_dt = datetime.fromisoformat(select["start"])
|
||||
end_dt = datetime.fromisoformat(select["end"])
|
||||
|
||||
return (
|
||||
True,
|
||||
start_dt.date().isoformat(),
|
||||
start_dt.strftime("%H:%M"),
|
||||
end_dt.strftime("%H:%M"),
|
||||
)
|
||||
except Exception as e:
|
||||
print("Fehler beim Parsen von select:", e)
|
||||
return no_update, no_update, no_update, no_update
|
||||
|
||||
# Einzelklick (lastDateClick)
|
||||
if trigger == "calendar" and date_click:
|
||||
try:
|
||||
dt = datetime.fromisoformat(date_click)
|
||||
# Versuche, die Slotlänge aus dem Kalender zu übernehmen (optional)
|
||||
# Hier als Beispiel 30 Minuten aufaddieren, falls keine Endzeit vorhanden
|
||||
end_dt = dt + timedelta(minutes=30)
|
||||
return (
|
||||
True,
|
||||
dt.date().isoformat(),
|
||||
dt.strftime("%H:%M"),
|
||||
end_dt.strftime("%H:%M"),
|
||||
)
|
||||
except Exception as e:
|
||||
print("Fehler beim Parsen von date_click:", e)
|
||||
return no_update, no_update, no_update, no_update
|
||||
|
||||
# Modal öffnen per Button
|
||||
if trigger == "open-appointment-modal-btn" and open_click:
|
||||
return True
|
||||
now = datetime.now()
|
||||
end_dt = now + timedelta(minutes=30)
|
||||
return True, now.date().isoformat(), now.strftime("%H:%M"), end_dt.strftime("%H:%M")
|
||||
|
||||
# Modal schließen
|
||||
if trigger == "close-appointment-modal-btn" and close_click:
|
||||
return False
|
||||
return is_open
|
||||
return False, no_update, no_update, no_update
|
||||
|
||||
return is_open, no_update, no_update, no_update
|
||||
|
||||
|
||||
# @callback(
|
||||
# Output("time-end", "value", allow_duplicate=True),
|
||||
# Input("time-start", "value"),
|
||||
# prevent_initial_call=True
|
||||
# )
|
||||
# def handle_end_time(start_time, duration="00:30"):
|
||||
# trigger = ctx.triggered_id
|
||||
# if trigger == "time-start" and start_time and duration:
|
||||
# try:
|
||||
# # Beispiel für start_time: "09:00"
|
||||
# start_dt = datetime.strptime(start_time, "%H:%M")
|
||||
# # Dauer in Stunden und Minuten, z.B. "01:30"
|
||||
# hours, minutes = map(int, duration.split(":"))
|
||||
# # Endzeit berechnen: Dauer addieren!
|
||||
# end_dt = start_dt + timedelta(hours=hours, minutes=minutes)
|
||||
# return end_dt.strftime("%H:%M")
|
||||
# except Exception as e:
|
||||
# print("Fehler bei der Berechnung der Endzeit:", e)
|
||||
# return no_update
|
||||
|
||||
Reference in New Issue
Block a user