use underscorejs for nodes table template

This commit is contained in:
Stephen Birarda 2014-06-26 15:40:10 -07:00
parent c21b202b63
commit e56f4aba0a
2 changed files with 19 additions and 21 deletions

View file

@ -18,7 +18,20 @@
</tr>
</thead>
<tbody>
</tbody>
<script id="nodes-template" type="text/template">
<% _.each(nodes, function(node, node_index){ %>
<tr>
<td><%- node.type %></td>
<td><a href="stats/?uuid=<%- node.uuid %>"><%- node.uuid %></a></td>
<td><%- node.pool %></td>
<td><%- node.public.ip %><span class='port'><%- node.public.port %></span></td>
<td><%- node.local.ip %><span class='port'><%- node.local.port %></span></td>
<td><%- ((Date.now() - node.wake_timestamp) / 1000).toLocaleString() %></td>
<td><%- (typeof node.pending_credits == 'number' ? node.pending_credits.toLocaleString() : 'N/A') %></td>
<td><span class='glyphicon glyphicon-remove' data-uuid="<%- node.uuid %>"></span></td>
</tr>
<% }); %>
</script>
</table>
<div id="queued-lead" class="table-lead"><h3>Queued Assignments</h3><div class="lead-line"></div></div>
@ -35,4 +48,5 @@
</table>
<!--#include file="footer.html"-->
<script src='js/tables.js'></script>
<script src='js/underscore-1.5.0.min.js'></script>
<!--#include file="page-end.html"-->

View file

@ -1,4 +1,7 @@
$(document).ready(function(){
// setup the underscore templates
var nodeTemplate = _.template($('#nodes-template').html());
// setup a function to grab the assignments
function getNodesAndAssignments() {
$.getJSON("nodes.json", function(json){
@ -29,26 +32,7 @@ $(document).ready(function(){
}
});
nodesTableBody = "";
$.each(json.nodes, function(index, data) {
nodesTableBody += "<tr>";
nodesTableBody += "<td>" + data.type + "</td>";
nodesTableBody += "<td><a href='stats/?uuid=" + data.uuid + "'>" + data.uuid + "</a></td>";
nodesTableBody += "<td>" + (data.pool ? data.pool : "") + "</td>";
nodesTableBody += "<td>" + data.public.ip + "<span class='port'>:" + data.public.port + "</span></td>";
nodesTableBody += "<td>" + data.local.ip + "<span class='port'>:" + data.local.port + "</span></td>";
var uptimeSeconds = (Date.now() - data.wake_timestamp) / 1000;
nodesTableBody += "<td>" + uptimeSeconds.toLocaleString() + "</td>";
nodesTableBody += "<td>" + (typeof data.pending_credits == 'number' ? data.pending_credits.toLocaleString() : 'N/A') + "</td>";
nodesTableBody += "<td><span class='glyphicon glyphicon-remove' data-uuid=" + data.uuid + "></span></td>";
nodesTableBody += "</tr>";
});
$('#nodes-table tbody').html(nodesTableBody);
$('#nodes-table tbody').html(nodeTemplate(json));
});
$.getJSON("assignments.json", function(json){