From f0f8fab1203b64af04c7c41c6a4a5d7a3cfe88c6 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 24 Jun 2020 20:19:18 -0700 Subject: [PATCH] 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). --- lmno.js | 11 +++++++++-- templates/admin.html | 32 +++++++++----------------------- 2 files changed, 18 insertions(+), 25 deletions(-) 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 @@ -- 2.43.0