diff --git a/models.py b/models.py index 968af23..ed1a524 100644 --- a/models.py +++ b/models.py @@ -1647,6 +1647,42 @@ def purge_app_log(older_than_days: int = 30): conn.close() +# ─── Today's Check Notes ────────────────────────────────────────────────────── + +def get_todays_check_notes() -> list: + """Return all shift_checks from today that have a non-empty user_note.""" + conn = None + try: + conn = get_connection() + cur = conn.cursor(dictionary=True) + cur.execute( + """ + SELECT + sc.id AS check_id, + sc.checked_at, + sc.user_note, + w.id AS website_id, + w.name AS website_name, + w.url AS website_url, + COALESCE(u.full_name, u.username) AS full_name, + u.username + FROM shift_checks sc + JOIN websites w ON w.id = sc.website_id + JOIN users u ON u.id = sc.user_id + WHERE DATE(sc.checked_at) = CURDATE() + AND sc.user_note IS NOT NULL + AND TRIM(sc.user_note) <> '' + ORDER BY sc.checked_at DESC + """ + ) + rows = cur.fetchall() + cur.close() + return rows + finally: + if conn: + conn.close() + + # ─── Missed Shifts ──────────────────────────────────────────────────────────── def get_missed_shifts_today() -> list: diff --git a/routes/admin_dashboard.py b/routes/admin_dashboard.py index 8351b09..f2f4893 100644 --- a/routes/admin_dashboard.py +++ b/routes/admin_dashboard.py @@ -4,7 +4,7 @@ routes/admin_dashboard.py — Admin dashboard: today's completion stats. import logging from flask import Blueprint, render_template -from models import get_admin_dashboard_stats, get_missed_shifts_today +from models import get_admin_dashboard_stats, get_missed_shifts_today, get_todays_check_notes from utils.decorators import admin_required logger = logging.getLogger("routes.admin_dashboard") @@ -25,4 +25,10 @@ def dashboard(): except Exception as e: logger.error(f"Missed shifts error: {e}") missed = [] - return render_template("admin/dashboard.html", stats=stats, missed=missed) + try: + check_notes = get_todays_check_notes() + except Exception as e: + logger.error(f"Check notes error: {e}") + check_notes = [] + return render_template("admin/dashboard.html", stats=stats, missed=missed, + check_notes=check_notes) diff --git a/templates/admin/dashboard.html b/templates/admin/dashboard.html index 7f410b3..c32861d 100644 --- a/templates/admin/dashboard.html +++ b/templates/admin/dashboard.html @@ -63,7 +63,7 @@
+ onsubmit="return confirm('Send reminder emails to all staff with incomplete checks in shifts ending within 45 minutes?')">
@@ -99,6 +99,40 @@ + +{% if check_notes %} +
+
+

Today's Check Notes

+ {{ check_notes|length }} note{{ 's' if check_notes|length != 1 }} +
+ + + + + + + + + + + {% for n in check_notes %} + + + + + + + {% endfor %} + +
TimeUserWebsiteNote
+ {{ n.checked_at.strftime('%H:%M') if n.checked_at else '' }} + {{ n.full_name }} + {{ n.website_name }} + {{ n.user_note }}
+
+{% endif %} +