diff --git a/src/app.py b/src/app.py index 75d8453..30a60b8 100644 --- a/src/app.py +++ b/src/app.py @@ -64,7 +64,7 @@ def infokiosk(): return render_template("infokiosk.html", current=current) -# API endpoint used by clients to poll current number (JSON) +# API endpoint used by clients to poll current number(s) (JSON) @app.route("/current") def current_api(): db = get_db() @@ -76,7 +76,11 @@ def current_api(): "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) + cur_first = db.execute( + "SELECT number AS first FROM items WHERE status='waiting' ORDER BY id LIMIT 1" + ).fetchone() + first = cur_first["first"] if cur_first else 0 + return jsonify(current=nums, waiting=waiting_count, first=first) # Admin UI: start/reset system by providing count of tickets (1..N) diff --git a/src/templates/index.html b/src/templates/index.html index 8f33a9d..3c8645e 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -17,20 +17,22 @@ try{ const r = await fetch('/current'); const j = await r.json(); + const cont = document.getElementById('nums'); cont.innerHTML = ''; const list = j.current || []; - if(list.length === 0){ + if(list.length == 0){ cont.textContent = '-'; - return; - } - list.forEach(n => { - const el = document.createElement('div'); - el.className = 'num'; - el.textContent = n; - cont.appendChild(el); - }); - document.getElementById('waiting-count').textContent = (j.waiting != null) ? j.waiting : '0'; + } else { + list.forEach(n => { + const el = document.createElement('div'); + el.className = 'num'; + el.textContent = n; + cont.appendChild(el); + }); + }; + document.getElementById('waiting-count').textContent = (j.waiting != null) ? j.waiting : '0'; + document.getElementById('first-waiting').textContent = (j.first != 0 ) ? j.first : '-'; }catch(e){} } setInterval(fetchCurrent, 5000); @@ -43,6 +45,7 @@