mirror of
https://github.com/pi-hole/web.git
synced 2025-12-20 02:38:28 +00:00
Treat 0.0 response as NULL. Also get the in-memory timetamp, and then use whichever of the two timestamps is smallest (and non-zero)
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
@@ -64,6 +64,7 @@ mg.include('scripts/lua/header_authenticated.lp','r')
|
|||||||
</div>
|
</div>
|
||||||
<input type="button" class="form-control pull-right" id="querytime" value="Click to select date and time range">
|
<input type="button" class="form-control pull-right" id="querytime" value="Click to select date and time range">
|
||||||
</div>
|
</div>
|
||||||
|
<small id="querytime-note" class="form-text text-muted" style="margin-top: 5px;"></small>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<div><input type="checkbox" id="disk"><label for="disk">Query on-disk data. This is <em>a lot</em> slower but necessary if you want to obtain queries older than 24 hours. This option disables live update.</label></div>
|
<div><input type="checkbox" id="disk"><label for="disk">Query on-disk data. This is <em>a lot</em> slower but necessary if you want to obtain queries older than 24 hours. This option disables live update.</label></div>
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
// These values are provided by the API (/info/database).
|
// These values are provided by the API (/info/database).
|
||||||
// We initialize them as null and populate them during page init.
|
// We initialize them as null and populate them during page init.
|
||||||
let beginningOfTime = null; // seconds since epoch (set from API: info/database.earliest_timestamp)
|
let beginningOfTime = null; // seconds since epoch (set from API: info/database.earliest_timestamp)
|
||||||
let endOfTime = null; // seconds since epoch (set to end of today)
|
// endOfTime should be the end of today (local), in seconds since epoch
|
||||||
|
const endOfTime = moment().endOf("day").unix();
|
||||||
let from = null;
|
let from = null;
|
||||||
let until = null;
|
let until = null;
|
||||||
|
|
||||||
@@ -47,24 +48,46 @@ function getDnssecConfig() {
|
|||||||
function getDatabaseInfo() {
|
function getDatabaseInfo() {
|
||||||
$.getJSON(document.body.dataset.apiurl + "/info/database", data => {
|
$.getJSON(document.body.dataset.apiurl + "/info/database", data => {
|
||||||
// earliest_timestamp is provided in seconds since epoch
|
// earliest_timestamp is provided in seconds since epoch
|
||||||
beginningOfTime = Number(data.earliest_timestamp_disk);
|
// We have two sources: earliest_timestamp_disk (on-disk) and earliest_timestamp (in-memory)
|
||||||
// Round down to nearest 5-minute segment (300 seconds)
|
// Use whichever is smallest and non-zero
|
||||||
beginningOfTime = Math.floor(beginningOfTime / 300) * 300;
|
const diskTimestamp = Number(data.earliest_timestamp_disk);
|
||||||
|
const memoryTimestamp = Number(data.earliest_timestamp);
|
||||||
|
|
||||||
// endOfTime should be the end of today (local), in seconds since epoch
|
// Filter out zero/invalid timestamps
|
||||||
endOfTime = moment().endOf("day").unix();
|
const validTimestamps = [diskTimestamp, memoryTimestamp].filter(ts => ts > 0);
|
||||||
|
|
||||||
|
// Use the smallest valid timestamp, or null if none exist
|
||||||
|
beginningOfTime = validTimestamps.length > 0 ? Math.min(...validTimestamps) : null;
|
||||||
|
|
||||||
|
// Round down to nearest 5-minute segment (300 seconds) if valid
|
||||||
|
if (beginningOfTime !== null) {
|
||||||
|
beginningOfTime = Math.floor(beginningOfTime / 300) * 300;
|
||||||
|
}
|
||||||
|
|
||||||
// If from/until were not provided via GET, default them
|
// If from/until were not provided via GET, default them
|
||||||
|
// Only use defaults if beginningOfTime is valid
|
||||||
|
if (beginningOfTime !== null) {
|
||||||
from ??= beginningOfTime;
|
from ??= beginningOfTime;
|
||||||
until ??= endOfTime;
|
until ??= endOfTime;
|
||||||
|
}
|
||||||
|
|
||||||
initDateRangePicker();
|
initDateRangePicker();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function initDateRangePicker() {
|
function initDateRangePicker() {
|
||||||
|
// If there's no valid data in the database, disable the datepicker
|
||||||
|
if (beginningOfTime === null || endOfTime === null) {
|
||||||
|
$("#querytime").prop("disabled", true);
|
||||||
|
$("#querytime").addClass("disabled");
|
||||||
|
$("#querytime-note").text("ℹ️ No data in the database");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const minDateMoment = moment.unix(beginningOfTime);
|
const minDateMoment = moment.unix(beginningOfTime);
|
||||||
const maxDateMoment = moment.unix(endOfTime);
|
const maxDateMoment = moment.unix(endOfTime);
|
||||||
|
const earliestDateStr = minDateMoment.format(dateformat);
|
||||||
|
$("#querytime-note").text(`Earliest date: ${earliestDateStr}`);
|
||||||
|
|
||||||
$("#querytime").daterangepicker(
|
$("#querytime").daterangepicker(
|
||||||
{
|
{
|
||||||
@@ -84,12 +107,12 @@ function initDateRangePicker() {
|
|||||||
],
|
],
|
||||||
"Last 7 Days": [moment().subtract(6, "days"), maxDateMoment],
|
"Last 7 Days": [moment().subtract(6, "days"), maxDateMoment],
|
||||||
"Last 30 Days": [moment().subtract(29, "days"), maxDateMoment],
|
"Last 30 Days": [moment().subtract(29, "days"), maxDateMoment],
|
||||||
"This Month": [moment().startOf("month"), moment().endOf("month")],
|
"This Month": [moment().startOf("month"), maxDateMoment],
|
||||||
"Last Month": [
|
"Last Month": [
|
||||||
moment().subtract(1, "month").startOf("month"),
|
moment().subtract(1, "month").startOf("month"),
|
||||||
moment().subtract(1, "month").endOf("month"),
|
moment().subtract(1, "month").endOf("month"),
|
||||||
],
|
],
|
||||||
"This Year": [moment().startOf("year"), moment().endOf("year")],
|
"This Year": [moment().startOf("year"), maxDateMoment],
|
||||||
"All Time": [minDateMoment, maxDateMoment],
|
"All Time": [minDateMoment, maxDateMoment],
|
||||||
},
|
},
|
||||||
// Don't allow selecting dates outside the database range
|
// Don't allow selecting dates outside the database range
|
||||||
|
|||||||
Reference in New Issue
Block a user