diff --git a/app.py b/app.py index 86df8d1..b6f261a 100644 --- a/app.py +++ b/app.py @@ -192,6 +192,27 @@ def index(): ORDER BY name """).fetchall() + + # NEW: users currently clocked in + clocked_in_users = conn.execute(""" + SELECT u.id, u.name + FROM users u + JOIN ( + SELECT e.user_id, e.entrytype, e.ts + FROM entries e + INNER JOIN ( + SELECT user_id, MAX(ts) AS max_ts + FROM entries + GROUP BY user_id + ) latest + ON e.user_id = latest.user_id + AND e.ts = latest.max_ts + ) last_entry + ON u.id = last_entry.user_id + WHERE last_entry.entrytype = 'in' + ORDER BY u.name + """).fetchall() + conn.close() report_hours = None @@ -221,7 +242,8 @@ def index(): return render_template( "index.html", users=users, - report_hours=report_hours + report_hours=report_hours, + clocked_in_users=clocked_in_users ) # ----------------------------------------------------------------------------- diff --git a/templates/index.html b/templates/index.html index d0f74a4..643ae21 100644 --- a/templates/index.html +++ b/templates/index.html @@ -8,6 +8,22 @@

Simple Time Clock

+

Currently Clocked In

+ +{% if clocked_in_users %} + +{% else %} +

No users are currently clocked in.

+{% endif %} + +
+
+
+
@@ -19,7 +35,7 @@ {% for user in users %} {% endfor %}