From e4d6b2f091b86db5ae41f9cc5442d6534251ddce Mon Sep 17 00:00:00 2001 From: Christos Koutsiaris Date: Sun, 4 Dec 2016 18:37:04 +0000 Subject: [PATCH 1/5] Some small changes in updateSummaryData --- js/pihole/index.js | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/js/pihole/index.js b/js/pihole/index.js index be6f9487..6b5382b2 100644 --- a/js/pihole/index.js +++ b/js/pihole/index.js @@ -182,36 +182,30 @@ function objectToArray(p){ // Functions to update data in page function updateSummaryData(runOnce) { + var setTimer = function(timeInMs) { + if (!runOnce) { + setTimeout(updateSummaryData, timeInMs); + } + }; $.getJSON("api.php?summary", function LoadSummaryData(data) { - //$("h3.statistic").addClass("glow"); - if ($("h3#ads_blocked_today").text() != data.ads_blocked_today) { - $("h3#ads_blocked_today").addClass("glow"); - } - if ($("h3#dns_queries_today").text() != data.dns_queries_today) { - $("h3#dns_queries_today").addClass("glow"); - } - if ($("h3#ads_percentage_today").text() != data.ads_percentage_today) { - $("h3#ads_percentage_today").addClass("glow"); - } - window.setTimeout(function(){ + ['ads_blocked_today', 'dns_queries_today', 'ads_percentage_today'].forEach(function(today) { + var todayElement = $("h3#" + today); + todayElement.text() != data[today] && todayElement.addClass("glow"); + }); + + window.setTimeout(function() { $("h3#ads_blocked_today").text(data.ads_blocked_today); $("h3#dns_queries_today").text(data.dns_queries_today); $("h3#domains_being_blocked").text(data.domains_being_blocked); $("h3#ads_percentage_today").text(data.ads_percentage_today + "%"); $("h3.statistic.glow").removeClass("glow") }, 500); - - updateSessionTimer(); }).done(function() { - if (runOnce !== true) { - setTimeout(updateSummaryData, 10000); - } + setTimer(10000); }).fail(function() { - if (runOnce !== true) { - setTimeout(updateSummaryData, (1000 * 60 * 5)); - } - });; + setTimer(300000); + }); } var failures = 0; From d89e47e83fa472762718e6f6b54bb20b291281a5 Mon Sep 17 00:00:00 2001 From: Christos Koutsiaris Date: Sun, 4 Dec 2016 18:44:33 +0000 Subject: [PATCH 2/5] switch to doublequotes --- js/pihole/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/pihole/index.js b/js/pihole/index.js index 6b5382b2..d6abaf68 100644 --- a/js/pihole/index.js +++ b/js/pihole/index.js @@ -189,7 +189,7 @@ function updateSummaryData(runOnce) { }; $.getJSON("api.php?summary", function LoadSummaryData(data) { - ['ads_blocked_today', 'dns_queries_today', 'ads_percentage_today'].forEach(function(today) { + ["ads_blocked_today", "dns_queries_today", "ads_percentage_today"].forEach(function(today) { var todayElement = $("h3#" + today); todayElement.text() != data[today] && todayElement.addClass("glow"); }); From fa254e258f871cef70b245331b4ea239b403ca74 Mon Sep 17 00:00:00 2001 From: Christos Koutsiaris Date: Sun, 4 Dec 2016 18:48:36 +0000 Subject: [PATCH 3/5] codacy bot --- js/pihole/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/pihole/index.js b/js/pihole/index.js index d6abaf68..b59b0a61 100644 --- a/js/pihole/index.js +++ b/js/pihole/index.js @@ -191,7 +191,7 @@ function updateSummaryData(runOnce) { ["ads_blocked_today", "dns_queries_today", "ads_percentage_today"].forEach(function(today) { var todayElement = $("h3#" + today); - todayElement.text() != data[today] && todayElement.addClass("glow"); + todayElement.text() !== data[today] && todayElement.addClass("glow"); }); window.setTimeout(function() { From f7cd5603cd117f7de5b011c2d262b31017125c77 Mon Sep 17 00:00:00 2001 From: Christos Koutsiaris Date: Sun, 4 Dec 2016 21:18:55 +0000 Subject: [PATCH 4/5] code review comments --- js/pihole/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/pihole/index.js b/js/pihole/index.js index b59b0a61..a1a9f6d4 100644 --- a/js/pihole/index.js +++ b/js/pihole/index.js @@ -201,6 +201,8 @@ function updateSummaryData(runOnce) { $("h3#ads_percentage_today").text(data.ads_percentage_today + "%"); $("h3.statistic.glow").removeClass("glow") }, 500); + + updateSessionTimer(); }).done(function() { setTimer(10000); }).fail(function() { From 19b132feae8a7942a64ddd30a5998399126ed387 Mon Sep 17 00:00:00 2001 From: Christos Koutsiaris Date: Tue, 13 Dec 2016 06:43:41 +0000 Subject: [PATCH 5/5] Code review comments --- js/pihole/index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/js/pihole/index.js b/js/pihole/index.js index a1a9f6d4..a0be37d1 100644 --- a/js/pihole/index.js +++ b/js/pihole/index.js @@ -182,9 +182,9 @@ function objectToArray(p){ // Functions to update data in page function updateSummaryData(runOnce) { - var setTimer = function(timeInMs) { + var setTimer = function(timeInSeconds) { if (!runOnce) { - setTimeout(updateSummaryData, timeInMs); + setTimeout(updateSummaryData, timeInSeconds * 1000); } }; $.getJSON("api.php?summary", function LoadSummaryData(data) { @@ -195,18 +195,18 @@ function updateSummaryData(runOnce) { }); window.setTimeout(function() { - $("h3#ads_blocked_today").text(data.ads_blocked_today); - $("h3#dns_queries_today").text(data.dns_queries_today); - $("h3#domains_being_blocked").text(data.domains_being_blocked); - $("h3#ads_percentage_today").text(data.ads_percentage_today + "%"); + ["ads_blocked_today", "dns_queries_today", "domains_being_blocked", "ads_percentage_today"].forEach(function(header, idx) { + var textData = idx === 3 ? data[header] + "%" : data[header]; + $("h3#" + header).text(textData); + }); $("h3.statistic.glow").removeClass("glow") }, 500); - + updateSessionTimer(); }).done(function() { - setTimer(10000); + setTimer(10); }).fail(function() { - setTimer(300000); + setTimer(300); }); }