Skip to content

Commit ba0077a

Browse files
committedAug 13, 2019
Add dropdown that filters by protocol version
1 parent 04810a0 commit ba0077a

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed
 

Diff for: ‎static/index.html

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
color: #336BA1;
1515
}
1616
</style>
17+
<script>
18+
var master = {show_proto_select: true};
19+
</script>
1720
</head>
1821
<body>
1922
<div id="server_list"></div>

Diff for: ‎static/list.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ if (!master.output) master.output = '#server_list';
55
if (!master.list) master.list = "list";
66
if (!master.list_root) master.list_root = master.root;
77
if (!master.list_url) master.list_url = master.list_root + master.list;
8+
master.cached_json = null;
89

910
// Utility functions used by the templating code
1011

@@ -81,12 +82,22 @@ function constantWidth(str, width) {
8182
// Code that fetches & displays the actual list
8283

8384
function draw(json) {
85+
if (json == null)
86+
return;
87+
8488
var html = window.render.servers(json);
8589
jQuery(master.output).html(html);
90+
jQuery('.proto_select', master.output).on('change', function(e) {
91+
master.proto_range = e.target.value;
92+
draw(master.cached_json); // re-render
93+
});
8694
}
8795

8896
function get() {
89-
jQuery.getJSON(master.list_url, draw);
97+
jQuery.getJSON(master.list_url, function(json) {
98+
master.cached_json = json;
99+
draw(json);
100+
});
90101
}
91102

92103
function loaded(){

Diff for: ‎static/servers.jst

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
{{? !master.no_total}}
2-
<div class="total">
3-
Players: {{=it.total.clients}}/{{=it.total_max.clients}}&nbsp;
4-
Servers: {{=it.total.servers}}/{{=it.total_max.servers}}
2+
<div>
3+
<span class="header_total">
4+
Players: {{=it.total.clients}}/{{=it.total_max.clients}}&nbsp;
5+
Servers: {{=it.total.servers}}/{{=it.total_max.servers}}
6+
</span>
7+
{{? master.show_proto_select}}
8+
, Protocol: <select class="proto_select">
9+
<option value="">All</option>
10+
<option value="[11,32]" {{? master.proto_range=='[11,32]'}}selected{{?}}>11-32 (Minetest 0.4)</option>
11+
<option value="[37,99]" {{? master.proto_range=='[37,99]'}}selected{{?}}>37 (Minetest 5.0)</option>
12+
</select>{{?}}
513
</div>
614
{{?}}
715
<table>
@@ -19,6 +27,8 @@
1927
{{~it.list :server:index}}
2028
{{ if (master.limit && index + 1 > master.limit) break;}}
2129
{{ if (master.min_clients && server.clients < master.min_clients) continue;}}
30+
{{ var tmp = master.proto_range ? JSON.parse(master.proto_range) : null;}}
31+
{{ if (tmp && (server.proto_min < tmp[0] || server.proto_max > tmp[1])) continue;}}
2232
<tr>
2333
{{? !master.no_address}}
2434
<td class ="address">

Diff for: ‎static/style.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#server_list .total {
1+
#server_list .header_total {
22
font-weight: bold;
33
}
44

0 commit comments

Comments
 (0)
Please sign in to comment.