diff --git a/app.py b/app.py index a49a73a..52ffffb 100644 --- a/app.py +++ b/app.py @@ -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) diff --git a/templates/index.html b/templates/index.html index 437e0a0..510054a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -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);