From 050e1d1056c60d0f01717536efb6b5f14c54c4d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 24 Oct 2023 23:30:29 +0200 Subject: [PATCH] Fix dashboard when no queries are present 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 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index 6620de17..36c96261 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -16,6 +16,16 @@ var queryTypePieChart, forwardDestinationPieChart; var failures = 0; function updateQueriesOverTime() { $.getJSON("/api/history", function (data) { + // Remove graph if there are no results (e.g. new + // installation or privacy mode enabled) + if (jQuery.isEmptyObject(data.history)) { + $("#queries-over-time").remove(); + return; + } + + // remove last data point for line charts as it is not representative there + if (utils.getGraphType() === "line") data.history.splice(-1, 1); + // Remove possibly already existing data timeLineChart.data.labels = []; timeLineChart.data.datasets = []; @@ -123,7 +133,7 @@ function updateClientsOverTime() { // Remove graph if there are no results (e.g. new // installation or privacy mode enabled) if (jQuery.isEmptyObject(data.history)) { - $("#clients-over-time").parent().remove(); + $("#clients").remove(); return; }