From 808f638d7b86b8befcd9a5d3cd75b7e620d98206 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sat, 23 May 2020 05:47:36 -0700 Subject: [PATCH] /admin: Switch to rendering via a template Thanks to the common code of base.html, this looks lovely and styled (compared to the previous text/plain output) while not even being that much code. We also now display the IDs of all games as well as the names of each player. --- lmno.js | 13 ++++++------- templates/admin.html | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 templates/admin.html diff --git a/lmno.js b/lmno.js index 7468736..8630651 100644 --- a/lmno.js +++ b/lmno.js @@ -213,17 +213,16 @@ app.post('/login', async (request, response) => { /* An admin page (only available to admin users, of course) */ app.get('/admin/', auth_admin, (request, response) => { - let active = 0; - let idle = 0; + let active = []; + let idle = []; for (let id in lmno.ids) { if (lmno.ids[id].game.clients.length) - active++; - else - idle++; + active.push(lmno.ids[id]); + else + idle.push(lmno.ids[id]); } - response.send(`Active games: ${active}.
-Idle games: ${idle}`); + response.render('admin.html', { test: "foobar", games: { active: active, idle: idle}}); }); diff --git a/templates/admin.html b/templates/admin.html new file mode 100644 index 0000000..df79394 --- /dev/null +++ b/templates/admin.html @@ -0,0 +1,37 @@ +{% extends "base.html" %} + +{% block page %} +

+ LMNO Admin +

+ +

+ Active games +

+ + + +

+ Idle games +

+ + +{% endblock %} -- 2.43.0