display waiting person counter

This commit is contained in:
miklo 2025-11-24 00:18:51 +01:00
parent bf0b323e69
commit 701c638140
2 changed files with 12 additions and 6 deletions

10
app.py
View File

@ -55,11 +55,11 @@ def index():
@app.route("/current")
def current_api():
db = get_db()
cur = db.execute(
"SELECT number FROM items WHERE status='called' ORDER BY id"
).fetchall()
nums = [r["number"] for r in cur]
return jsonify(current=nums)
cur_called = db.execute("SELECT number FROM items WHERE status='called' ORDER BY id").fetchall()
nums = [r["number"] for r in cur_called]
cur_wait = db.execute("SELECT COUNT(*) AS cnt FROM items WHERE status='waiting'").fetchone()
waiting_count = cur_wait["cnt"] if cur_wait else 0
return jsonify(current=nums, waiting=waiting_count)
# Admin UI: start/reset system by providing count of tickets (1..N)

View File

@ -30,14 +30,20 @@
el.textContent = n;
cont.appendChild(el);
});
document.getElementById('waiting-count').textContent = (j.waiting != null) ? j.waiting : '0';
}catch(e){}
}
setInterval(fetchCurrent, 2000);
setInterval(fetchCurrent, 5000);
window.addEventListener('load', fetchCurrent);
</script>
</head>
<body>
<h1>Zapraszamy do stanowiska osoby z numerem:</h1>
<div id="nums">-</div>
<div id="waiting" style="margin-top:18px;color:#333">
<h3>Liczba osób oczekujących: <span id="waiting-count">0</span></h3>
</div>
</body>
</html>