Skip to content

Commit

Permalink
Fix NaN error message when FTL is offline (#2548)
Browse files Browse the repository at this point in the history
  • Loading branch information
rdwebdesign authored Mar 22, 2023
2 parents 94448ed + e40d43e commit 6de61a1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions scripts/pi-hole/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,6 @@ function updateSummaryData(runOnce) {
updateTopLists();
}

var formatter = new Intl.NumberFormat();
//Element name might have a different name to the property of the API so we split it at |
[
"ads_blocked_today|queries_blocked_today",
Expand All @@ -691,9 +690,17 @@ function updateSummaryData(runOnce) {
var apiName = apiElName[0];
var elName = apiElName[1];
var $todayElement = elName ? $("span#" + elName) : $("span#" + apiName);
// Round to one decimal place and format locale-aware
var text = formatter.format(Math.round(data[apiName] * 10) / 10);
var textData = idx === 2 && data[apiName] !== "to" ? text + "%" : text;

var textData = data[apiName];
if (!FTLoffline) {
// Only format as number if FTL is online
var formatter = new Intl.NumberFormat();

// Round to one decimal place and format locale-aware
var text = formatter.format(Math.round(data[apiName] * 10) / 10);
textData = idx === 2 && data[apiName] !== "to" ? text + "%" : text;
}

if ($todayElement.text() !== textData && $todayElement.text() !== textData + "%") {
$todayElement.addClass("glow");
$todayElement.text(textData);
Expand Down

0 comments on commit 6de61a1

Please sign in to comment.