From 2f4ffde91670478f939340c9693de4dbe3f23d84 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 5 Sep 2021 20:44:53 +0200 Subject: [PATCH] Recalculate stats with protocol filter applied closes #49 --- static/list.js | 17 ++++++++++++++++- static/servers.jst | 4 +--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/static/list.js b/static/list.js index 1250f0e..3bf05c8 100644 --- a/static/list.js +++ b/static/list.js @@ -80,8 +80,23 @@ function draw(json) { if (json == null) return; + // pre-filter by chosen protocol range + var tmp = master.proto_range ? JSON.parse(master.proto_range) : null; + if (tmp) { + json = { + list: json.list.filter(function(server) { + return !(tmp[0] > server.proto_max || tmp[1] < server.proto_min); + }), + total: {clients: 0}, + total_max: {clients: "?", servers: "?"} + }; + json.list.forEach(function(server) { json.total.clients += server.clients; }); + json.total.servers = json.list.length; + } + var html = window.render.servers(json); jQuery(master.output).html(html); + jQuery('.proto_select', master.output).on('change', function(e) { master.proto_range = e.target.value; draw(master.cached_json); // re-render @@ -110,6 +125,6 @@ toast(master.root + 'style.css', master.root + 'servers.js', function() { if (typeof(jQuery) != 'undefined') return loaded(); else - toast('//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js', loaded); + toast('//ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js', loaded); }); diff --git a/static/servers.jst b/static/servers.jst index 76e93ab..0b4bd10 100644 --- a/static/servers.jst +++ b/static/servers.jst @@ -8,7 +8,7 @@ , Protocol: {{?}} {{?}} @@ -24,11 +24,9 @@ {{? !master.no_ping}}Ping, Lag{{?}} - {{ var tmp = master.proto_range ? JSON.parse(master.proto_range) : null;}} {{~it.list :server:index}} {{ if (master.limit && index + 1 > master.limit) break;}} {{ if (master.min_clients && server.clients < master.min_clients) continue;}} - {{ if (tmp && (tmp[0] > server.proto_max || tmp[1] < server.proto_min)) continue;}} {{? !master.no_address}}