From 1897f6846795c652f2177c59a1938fc76e0927c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 8 Jul 2024 18:46:34 +0000 Subject: [PATCH] Apply suggestions from code review 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 | 82 +++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index c3ea4e0ac1..1da97c816c 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -295,31 +295,32 @@ 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)) + - " " - ); - }); + return; } + // 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 +353,26 @@ 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)) + - " " - ); - }); + return; } + // 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);