From 57c262a704e69bbebb257f7c85beb9a35b70f8e4 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 21 Nov 2016 17:32:51 +0100 Subject: [PATCH] Be able to call queries.js with preset filters from the main page --- js/pihole/index.js | 17 ++++++++++++++--- js/pihole/queries.js | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/js/pihole/index.js b/js/pihole/index.js index f67bf18a..809631e7 100644 --- a/js/pihole/index.js +++ b/js/pihole/index.js @@ -224,7 +224,8 @@ function updateTopClientsChart() { $.getJSON("api.php?summaryRaw&getQuerySources", function(data) { var clienttable = $('#client-frequency').find('tbody:last'); for (domain in data.top_sources) { - clienttable.append(' ' + domain + + var url = ''+domain+''; + clienttable.append(' ' + url + ' ' + data.top_sources[domain] + '
'); } @@ -260,14 +261,24 @@ function updateTopLists() { $.getJSON("api.php?summaryRaw&topItems", function(data) { var domaintable = $('#domain-frequency').find('tbody:last'); var adtable = $('#ad-frequency').find('tbody:last'); + var url; for (domain in data.top_queries) { - domaintable.append(' ' + domain + + if(domain !== "pi.hole") + { + url = ''+domain+''; + } + else + { + url = domain; + } + domaintable.append(' ' + url + ' ' + data.top_queries[domain] + '
'); } for (domain in data.top_ads) { - adtable.append(' ' + domain + + url = ''+domain+''; + adtable.append(' ' + url + ' ' + data.top_ads[domain] + '
'); } diff --git a/js/pihole/queries.js b/js/pihole/queries.js index 29d388a1..ec55a7f1 100644 --- a/js/pihole/queries.js +++ b/js/pihole/queries.js @@ -40,6 +40,33 @@ $(document).ready(function() { add(data[2],"black"); } } ); + + // Do we want to filter queries? + var GETDict = {} + location.search.substr(1).split("&").forEach(function(item) {GETDict[item.split("=")[0]] = item.split("=")[1]}) + if("client" in GETDict) + { + if(GETDict["client"] == "localhost(127.0.0.1)") + { + // Have to use normal search, as regexp of DataTable is broken + // It should be fixed in next release which might come up next + // year. In the meantime, we work around using normal search. + tableApi.column(3).search("localhost"); + } + else + { + // Search in third column (zero indexed) + // Use regular expression to only show exact matches, i.e. + // don't show 192.168.0.100 when searching for 192.168.0.1 + // true = use regex, false = don't use smart search + tableApi.column(3).search("^"+GETDict["client"]+"$",true,false); + } + } + if("domain" in GETDict) + { + // Search in second column (zero indexed) + tableApi.column(2).search("^"+GETDict["domain"]+"$",true,false); + } } ); function refreshData() {