mirror of
https://github.com/pi-hole/web.git
synced 2025-12-20 10:48:26 +00:00
Query Log: Simplify specifying "type" via URI parameters (via types pie chart)
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -5,8 +5,6 @@
|
|||||||
* 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 querytypeids:false */
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
var THEME_COLORS = [
|
var THEME_COLORS = [
|
||||||
"#f56954",
|
"#f56954",
|
||||||
@@ -81,7 +79,7 @@ const htmlLegendPlugin = {
|
|||||||
|
|
||||||
textLink.addEventListener("click", () => {
|
textLink.addEventListener("click", () => {
|
||||||
if (chart.canvas.id === "queryTypePieChart") {
|
if (chart.canvas.id === "queryTypePieChart") {
|
||||||
window.location.href = "queries.lp?querytype=" + querytypeids[item.index];
|
window.location.href = "queries.lp?type=" + item.text;
|
||||||
} else if (chart.canvas.id === "forwardDestinationPieChart") {
|
} else if (chart.canvas.id === "forwardDestinationPieChart") {
|
||||||
window.location.href = "queries.lp?forwarddest=" + encodeURIComponent(item.text);
|
window.location.href = "queries.lp?forwarddest=" + encodeURIComponent(item.text);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,6 @@ function updateQueriesOverTime() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var querytypeids = [];
|
|
||||||
function updateQueryTypesPie() {
|
function updateQueryTypesPie() {
|
||||||
$.getJSON("/api/stats/query_types", function (data) {
|
$.getJSON("/api/stats/query_types", function (data) {
|
||||||
var v = [],
|
var v = [],
|
||||||
@@ -89,13 +88,11 @@ function updateQueryTypesPie() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Fill chart with data (only include query types which appeared recently)
|
// Fill chart with data (only include query types which appeared recently)
|
||||||
querytypeids = [];
|
|
||||||
Object.keys(data.types).forEach(function (item) {
|
Object.keys(data.types).forEach(function (item) {
|
||||||
if (data.types[item] > 0) {
|
if (data.types[item] > 0) {
|
||||||
v.push((100 * data.types[item]) / sum);
|
v.push((100 * data.types[item]) / sum);
|
||||||
c.push(THEME_COLORS[i % THEME_COLORS.length]);
|
c.push(THEME_COLORS[i % THEME_COLORS.length]);
|
||||||
k.push(item);
|
k.push(item);
|
||||||
querytypeids.push(i + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ var filters = [
|
|||||||
"dnssec",
|
"dnssec",
|
||||||
];
|
];
|
||||||
|
|
||||||
function init_datepicker() {
|
function initDateRangePicker() {
|
||||||
$("#querytime").daterangepicker(
|
$("#querytime").daterangepicker(
|
||||||
{
|
{
|
||||||
timePicker: true,
|
timePicker: true,
|
||||||
@@ -423,8 +423,7 @@ function parseFilters() {
|
|||||||
|
|
||||||
function filterOn(param, dict) {
|
function filterOn(param, dict) {
|
||||||
const typ = typeof dict[param];
|
const typ = typeof dict[param];
|
||||||
console.log([param, dict, typ]);
|
return param in dict && (typ === "number" || (typ === "string" && dict[param].length > 0));
|
||||||
return param in dict && (typ === "number" || typ === "string" && dict[param].length > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAPIURL(filters) {
|
function getAPIURL(filters) {
|
||||||
@@ -432,17 +431,13 @@ function getAPIURL(filters) {
|
|||||||
for (var key in filters) {
|
for (var key in filters) {
|
||||||
if (Object.hasOwnProperty.call(filters, key)) {
|
if (Object.hasOwnProperty.call(filters, key)) {
|
||||||
var filter = filters[key];
|
var filter = filters[key];
|
||||||
if (filterOn(key, filters))
|
if (filterOn(key, filters)) {
|
||||||
{
|
if (!apiurl.endsWith("?")) apiurl += "&";
|
||||||
if(!apiurl.endsWith("?")) apiurl += "&";
|
|
||||||
apiurl += key + "=" + filter;
|
apiurl += key + "=" + filter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(filters);
|
|
||||||
console.log(apiurl);
|
|
||||||
|
|
||||||
// Omit from/until filtering if we cannot reach these times. This will speed
|
// Omit from/until filtering if we cannot reach these times. This will speed
|
||||||
// up the database lookups notably on slow devices.
|
// up the database lookups notably on slow devices.
|
||||||
if (from > beginningOfTime) apiurl += "&from=" + from;
|
if (from > beginningOfTime) apiurl += "&from=" + from;
|
||||||
@@ -478,15 +473,17 @@ $(function () {
|
|||||||
getSuggestions(GETDict);
|
getSuggestions(GETDict);
|
||||||
var apiurl = getAPIURL(GETDict);
|
var apiurl = getAPIURL(GETDict);
|
||||||
|
|
||||||
if("from" in GETDict) {
|
if ("from" in GETDict) {
|
||||||
from = GETDict["from"];
|
from = GETDict.from;
|
||||||
$("#from").val(moment.unix(from).format("Y-MM-DD HH:mm:ss"));
|
$("#from").val(moment.unix(from).format("Y-MM-DD HH:mm:ss"));
|
||||||
}
|
}
|
||||||
if("until" in GETDict) {
|
|
||||||
until = GETDict["until"];
|
if ("until" in GETDict) {
|
||||||
|
until = GETDict.until;
|
||||||
$("#until").val(moment.unix(until).format("Y-MM-DD HH:mm:ss"));
|
$("#until").val(moment.unix(until).format("Y-MM-DD HH:mm:ss"));
|
||||||
}
|
}
|
||||||
init_datepicker();
|
|
||||||
|
initDateRangePicker();
|
||||||
|
|
||||||
table = $("#all-queries").DataTable({
|
table = $("#all-queries").DataTable({
|
||||||
ajax: {
|
ajax: {
|
||||||
@@ -617,8 +614,8 @@ function refreshTable() {
|
|||||||
|
|
||||||
// Source data from API
|
// Source data from API
|
||||||
var filters = parseFilters();
|
var filters = parseFilters();
|
||||||
filters["from"] = from;
|
filters.from = from;
|
||||||
filters["until"] = until;
|
filters.until = until;
|
||||||
var apiurl = getAPIURL(filters);
|
var apiurl = getAPIURL(filters);
|
||||||
table.ajax.url(apiurl).draw();
|
table.ajax.url(apiurl).draw();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user