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).
if (list)
return list.filter(e => e.active === true);
else
if (list)
return list.filter(e => e.active === true);
else
});
njx.addFilter('idle', function(list) {
if (list)
return list.filter(e => e.active === false);
else
});
njx.addFilter('idle', function(list) {
if (list)
return list.filter(e => e.active === false);
else
+ 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.
});
/* Load each of our game mini-apps.
<ul>
{% for game in games.active %}
<li>
<ul>
{% for game in games.active %}
<li>
- {{game.meta.name}}: {{ game.id }} {{ game.players.length }} players
- <ul>
- <li>
- Active players:
- {% for player in game.players|active %}
- {{ player.name }}
- {% endfor %}
- </li>
- <li>
- Idle players:
- {% for player in game.players|idle %}
- {{ player.name }}
- {% endfor %}
- </li>
- </ul>
+ {{game.meta.name}}: {{ game.id }} ({{ game.players|active|length }}/{{ game.players.length }})
+ <strong>
+ Active:
+ {{ game.players|active|map_prop("name")|join(", ") }}
+ </strong>
+ Idle:
+ {{ game.players|idle|map_prop("name")|join(", ") }}
<ul>
{% for game in games.idle %}
<li>
<ul>
{% for game in games.idle %}
<li>
- {{game.meta.name}}: {{ game.id }} {{ game.players.length }} players
- <ul>
- <li>
- {% for player in game.players %}
- {{ player.name }}
- {% endfor %}
- </li>
- </ul>
+ {{game.meta.name}}: {{ game.id }} ({{ game.players.length }}):
+ {{ game.players|map_prop("name")|join(", ") }}