mirror of
https://github.com/pi-hole/web.git
synced 2025-12-20 02:38:28 +00:00
Fix the link on the upstream chart legend (#3606)
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
* This file is copyright under the latest version of the EUPL.
|
* This file is copyright under the latest version of the EUPL.
|
||||||
* Please see LICENSE file for your rights under this license. */
|
* Please see LICENSE file for your rights under this license. */
|
||||||
|
|
||||||
/* global upstreams:false */
|
/* global upstreamIPs:false */
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@@ -63,6 +63,23 @@ globalThis.htmlLegendPlugin = {
|
|||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const li = document.createElement("li");
|
const li = document.createElement("li");
|
||||||
|
|
||||||
|
// Select the corresponding "slice" of the chart when the mouse is over a legend item
|
||||||
|
li.addEventListener("mouseover", () => {
|
||||||
|
chart.setActiveElements([
|
||||||
|
{
|
||||||
|
datasetIndex: 0,
|
||||||
|
index: item.index,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
chart.update();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Deselect all "slices"
|
||||||
|
li.addEventListener("mouseout", () => {
|
||||||
|
chart.setActiveElements([]);
|
||||||
|
chart.update();
|
||||||
|
});
|
||||||
|
|
||||||
// Color checkbox (toggle visibility)
|
// Color checkbox (toggle visibility)
|
||||||
const boxSpan = document.createElement("span");
|
const boxSpan = document.createElement("span");
|
||||||
boxSpan.title = "Toggle visibility";
|
boxSpan.title = "Toggle visibility";
|
||||||
@@ -96,9 +113,19 @@ globalThis.htmlLegendPlugin = {
|
|||||||
|
|
||||||
if (isQueryTypeChart) {
|
if (isQueryTypeChart) {
|
||||||
link.href = `queries?type=${item.text}`;
|
link.href = `queries?type=${item.text}`;
|
||||||
} else if (isForwardDestinationChart) {
|
} else {
|
||||||
// Encode the forward destination as it may contain an "#" character
|
// Encode the forward destination as it may contain an "#" character
|
||||||
link.href = `queries?upstream=${encodeURIComponent(upstreams[item.text])}`;
|
link.href = `queries?upstream=${encodeURIComponent(upstreamIPs[item.index])}`;
|
||||||
|
|
||||||
|
// If server name and IP are different:
|
||||||
|
if (item.text !== upstreamIPs[item.index]) {
|
||||||
|
// replace the title tooltip to include the upstream IP to the text ...
|
||||||
|
link.title = `List ${item.text} (${upstreamIPs[item.index]}) queries`;
|
||||||
|
|
||||||
|
// ... and include the server name (without port) to the querystring, to match
|
||||||
|
// the text used on the SELECT element (sent by suggestions API endpoint)
|
||||||
|
link.href += ` (${item.text.split("#")[0]})`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// no clickable links in other charts
|
// no clickable links in other charts
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ function updateClientsOverTime() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const upstreams = {};
|
const upstreamIPs = [];
|
||||||
function updateForwardDestinationsPie() {
|
function updateForwardDestinationsPie() {
|
||||||
$.getJSON(document.body.dataset.apiurl + "/stats/upstreams", data => {
|
$.getJSON(document.body.dataset.apiurl + "/stats/upstreams", data => {
|
||||||
const v = [];
|
const v = [];
|
||||||
@@ -248,11 +248,8 @@ function updateForwardDestinationsPie() {
|
|||||||
label += "#" + item.port;
|
label += "#" + item.port;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store upstreams for generating links to the Query Log
|
// Store upstreams IPs for generating links to the Query Log
|
||||||
upstreams[label] = item.ip;
|
upstreamIPs.push(item.port > 0 ? item.ip + "#" + item.port : item.ip);
|
||||||
if (item.port > 0) {
|
|
||||||
upstreams[label] += "#" + item.port;
|
|
||||||
}
|
|
||||||
|
|
||||||
const percent = (100 * item.count) / sum;
|
const percent = (100 * item.count) / sum;
|
||||||
values.push([label, percent, THEME_COLORS[i++ % THEME_COLORS.length]]);
|
values.push([label, percent, THEME_COLORS[i++ % THEME_COLORS.length]]);
|
||||||
@@ -893,6 +890,8 @@ $(() => {
|
|||||||
elements: {
|
elements: {
|
||||||
arc: {
|
arc: {
|
||||||
borderColor: $(".box").css("background-color"),
|
borderColor: $(".box").css("background-color"),
|
||||||
|
hoverBorderColor: $(".box").css("background-color"),
|
||||||
|
hoverOffset: 10,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
@@ -917,6 +916,9 @@ $(() => {
|
|||||||
animation: {
|
animation: {
|
||||||
duration: 750,
|
duration: 750,
|
||||||
},
|
},
|
||||||
|
layout: {
|
||||||
|
padding: 10,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -939,6 +941,8 @@ $(() => {
|
|||||||
elements: {
|
elements: {
|
||||||
arc: {
|
arc: {
|
||||||
borderColor: $(".box").css("background-color"),
|
borderColor: $(".box").css("background-color"),
|
||||||
|
hoverBorderColor: $(".box").css("background-color"),
|
||||||
|
hoverOffset: 10,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
@@ -963,6 +967,9 @@ $(() => {
|
|||||||
animation: {
|
animation: {
|
||||||
duration: 750,
|
duration: 750,
|
||||||
},
|
},
|
||||||
|
layout: {
|
||||||
|
padding: 10,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user