From 33cdb85bd4954ef6f94d05f79f086844779f0d1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 8 Jul 2024 20:29:52 +0200 Subject: [PATCH] Don't try to fill client/domain tables if there is no data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- scripts/pi-hole/js/index.js | 80 ++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index c5505189d8..c3ea4e0ac1 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -295,31 +295,31 @@ function updateTopClientsTable(blocked) { // Add note if there are no results (e.g. privacy mode enabled) if (jQuery.isEmptyObject(data.clients)) { clienttable.append('
- No data -
'); + } else { + // Populate table with content + data.clients.forEach(function (client) { + // Sanitize client + let clientname = client.name; + if (clientname.length === 0) clientname = client.ip; + url = + '' + + utils.escapeHtml(clientname) + + ""; + percentage = (client.count / sum) * 100; + + // Add row to table + clienttable.append( + " " + + utils.addTD(url) + + utils.addTD(client.count) + + utils.addTD(utils.colorBar(percentage, sum, style)) + + " " + ); + }); } - // Populate table with content - data.clients.forEach(function (client) { - // Sanitize client - let clientname = client.name; - if (clientname.length === 0) clientname = client.ip; - url = - '' + - utils.escapeHtml(clientname) + - ""; - percentage = (client.count / sum) * 100; - - // Add row to table - clienttable.append( - " " + - utils.addTD(url) + - utils.addTD(client.count) + - utils.addTD(utils.colorBar(percentage, sum, style)) + - " " - ); - }); - // Hide overlay overlay.hide(); }).fail(function (data) { @@ -352,25 +352,25 @@ function updateTopDomainsTable(blocked) { // Add note if there are no results (e.g. privacy mode enabled) if (jQuery.isEmptyObject(data.domains)) { domaintable.append('
- No data -
'); + } else { + // Populate table with content + data.domains.forEach(function (item) { + // Sanitize domain + domain = encodeURIComponent(item.domain); + // Substitute "." for empty domain lookups + urlText = domain === "" ? "." : domain; + url = '' + urlText + ""; + percentage = (item.count / sum) * 100; + domaintable.append( + " " + + utils.addTD(url) + + utils.addTD(item.count) + + utils.addTD(utils.colorBar(percentage, sum, style)) + + " " + ); + }); } - // Populate table with content - data.domains.forEach(function (item) { - // Sanitize domain - domain = encodeURIComponent(item.domain); - // Substitute "." for empty domain lookups - urlText = domain === "" ? "." : domain; - url = '' + urlText + ""; - percentage = (item.count / sum) * 100; - domaintable.append( - " " + - utils.addTD(url) + - utils.addTD(item.count) + - utils.addTD(utils.colorBar(percentage, sum, style)) + - " " - ); - }); - overlay.hide(); }).fail(function (data) { apiFailure(data);