From: Carl Worth Date: Thu, 25 Jun 2020 03:19:18 +0000 (-0700) Subject: Refactor admin page a bit X-Git-Url: https://git.cworth.org/git?p=lmno-server;a=commitdiff_plain;h=f0f8fab1203b64af04c7c41c6a4a5d7a3cfe88c6 Refactor admin page a bit Using a new filter to map an array to a new array of just a single property value from each object of the original array. This lets us avoid using the "for" directive in the template, as well as use the "join" filter to get commas between each item in the list, (which is hard to do with the "for" directive in the template). --- diff --git a/lmno.js b/lmno.js index 0db6789..569d33d 100644 --- a/lmno.js +++ b/lmno.js @@ -59,14 +59,21 @@ njx.addFilter('active', function(list) { if (list) return list.filter(e => e.active === true); else - return null; + return []; }); njx.addFilter('idle', function(list) { if (list) return list.filter(e => e.active === false); else - return null; + return []; +}); + +njx.addFilter('map_prop', function(list, prop) { + if (list) + return list.map(e => e[prop]); + else + return []; }); /* Load each of our game mini-apps. diff --git a/templates/admin.html b/templates/admin.html index 3a25e60..e2ed1b7 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -12,21 +12,13 @@ @@ -38,14 +30,8 @@