]> git.cworth.org Git - empires-server/commitdiff
/admin: Switch to rendering via a template
authorCarl Worth <cworth@cworth.org>
Sat, 23 May 2020 12:47:36 +0000 (05:47 -0700)
committerCarl Worth <cworth@cworth.org>
Sat, 23 May 2020 12:49:28 +0000 (05:49 -0700)
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
templates/admin.html [new file with mode: 0644]

diff --git a/lmno.js b/lmno.js
index 74687361a59fe485a9c42e44c470aea7510fb190..86306516878b1f68fd6d980ad9ea4e912692d053 100644 (file)
--- 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(`<html><body>Active games: ${active}.<br>
-Idle games: ${idle}</body></html>`);
+  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 (file)
index 0000000..df79394
--- /dev/null
@@ -0,0 +1,37 @@
+{% extends "base.html" %}
+
+{% block page %}
+<h1>
+  LMNO Admin
+</h1>
+
+<h2>
+  Active games
+</h2>
+
+<ul>
+  {% for game in games.active %}
+  <li>
+    {{ game.id }} ({{ game.game.clients.length }}/{{ game.game._players.length }} active)
+    {% for player in game.game._players %}
+      {{ player.name }}
+    {% endfor %}
+  </li>
+  {% endfor %}
+</ul>
+
+<h2>
+  Idle games
+</h2>
+
+<ul>
+  {% for game in games.idle %}
+  <li>
+    {{ game.id }} ({{ game.game._players.length }} active)
+    {% for player in game.game._players %}
+      {{ player.name }}
+    {% endfor %}
+  </li>
+  {% endfor %}
+</ul>
+{% endblock %}