📚 Improved blueprint structures & templates for better organization

This commit is contained in:
2025-06-11 08:53:07 +02:00
parent 23d6a8c6d0
commit 36c2466e53
10 changed files with 181 additions and 6 deletions

View File

@ -182,6 +182,7 @@ def api_get_calendar_events():
# Optional: Filter nach Druckern
printer_id = request.args.get('printer_id')
show_plug_events = request.args.get('show_plug_events', 'false').lower() == 'true'
with get_cached_session() as db_session:
# Jobs im angegebenen Zeitraum abfragen
@ -234,12 +235,89 @@ def api_get_calendar_events():
"description": job.description,
"userName": user_name,
"printerId": job.printer_id,
"printerName": printer_name
"printerName": printer_name,
"eventType": "job"
}
}
events.append(event)
# Steckdosen-Status-Events hinzufügen (falls gewünscht)
if show_plug_events:
from models import PlugStatusLog
# PlugStatusLog-Events im Zeitraum abfragen
plug_query = db_session.query(PlugStatusLog).filter(
PlugStatusLog.timestamp >= start_date,
PlugStatusLog.timestamp <= end_date
)
if printer_id:
plug_query = plug_query.filter(PlugStatusLog.printer_id == printer_id)
plug_logs = plug_query.order_by(PlugStatusLog.timestamp.desc()).all()
# Steckdosen-Events gruppieren (nur Statuswechsel anzeigen)
for i, log in enumerate(plug_logs):
# Prüfen ob es eine Statusänderung ist (nicht einfach ein Status-Check)
if i < len(plug_logs) - 1:
prev_log = plug_logs[i + 1]
if prev_log.status == log.status and prev_log.printer_id == log.printer_id:
continue # Gleicher Status, überspringen
# Drucker-Name für den Event
printer = db_session.query(Printer).filter_by(id=log.printer_id).first()
printer_name = printer.name if printer else f"Drucker {log.printer_id}"
# Event-Farbe basierend auf Status
plug_color = "#FF6B35" # Orange für Steckdosen-Events
if log.status == "on":
plug_color = "#4ECDC4" # Türkis für eingeschaltet
elif log.status == "off":
plug_color = "#FFD23F" # Gelb für ausgeschaltet
elif log.status == "disconnected":
plug_color = "#EE6C4D" # Rot für nicht erreichbar
# Status-Text übersetzen
status_text = {
"on": "Eingeschaltet",
"off": "Ausgeschaltet",
"connected": "Verbunden",
"disconnected": "Offline"
}.get(log.status, log.status)
# Quelle anzeigen
source_text = {
"system": "System",
"manual": "Manuell",
"api": "API",
"scheduler": "Scheduler"
}.get(log.source, log.source)
plug_event = {
"id": f"plug_{log.id}",
"title": f"🔌 {printer_name}: {status_text}",
"start": log.timestamp.isoformat(),
"end": log.timestamp.isoformat(), # Punktereignis
"color": plug_color,
"display": "list-item", # Als kleines Item anzeigen
"extendedProps": {
"eventType": "plug_status",
"status": log.status,
"printerId": log.printer_id,
"printerName": printer_name,
"source": source_text,
"powerConsumption": log.power_consumption,
"voltage": log.voltage,
"current": log.current,
"responseTime": log.response_time_ms,
"notes": log.notes,
"errorMessage": log.error_message
}
}
events.append(plug_event)
logger.info(f"📅 Kalender-Events abgerufen: {len(events)} Einträge für Zeitraum {start_date} bis {end_date}")
return jsonify(events)