forked from kontur-courses/old-testing-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaderboard.html
42 lines (39 loc) · 1.3 KB
/
leaderboard.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<html>
<head>
<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.min.css">
</head>
<body>
<div id="container" />
<script>
console.log("hi!");
var fb = new Firebase("https://testing-challenge.firebaseio.com/");
fb.once("value", function(snapshot) {
console.log("!");
var res = snapshot.val();
var html = "<table class='table table-condensed'>";
html += "<tr>";
["Name", "C", "E", "L", "CR", "E2", "E3", "E4", "L2", "L3", "L4", "O1", "O2", "O3", "O4", "O5", "123", "998", "999", "QWE", "STA"].forEach(
v => html += "<th>" + v + "</th>");
html += "</tr>";
var names = Object.keys(res);
names.sort((a,b) => -countNonzero(res[a]) + countNonzero(res[b]));
names.forEach(function(name){
html += "<tr><td>" + name + "</td>";
res[name].forEach(v => html += formatCell(v));
html += "</tr>";
});
html += "</table>";
console.log(html);
document.getElementById("container").innerHTML = html;
});
function countNonzero(arr){
return arr.filter(v => v > 0).length;
}
function formatCell(v){
var clazz = v == 0 ? "bg-danger" : (v == 1 ? "bg-warning" : "bg-success");
return "<td class='" + clazz + "'>" + v + "</td>";
}
</script>
</body>
</html>