fix: All-time range fills the date pickers with the DB's first record date
CI/CD Pipeline - Northern Thailand Ping River Monitor / Test Suite (3.11) (push) Failing after 1m4s
CI/CD Pipeline - Northern Thailand Ping River Monitor / Build Docker Image (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Integration Test with Services (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Deploy to Staging (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Deploy to Production (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Performance Test (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Code Quality (push) Successful in 30s
CI/CD Pipeline - Northern Thailand Ping River Monitor / Cleanup (push) Successful in 3s

Uses first_timestamp from /api/stats (2018-08-01 fallback) as the start
date and today as the end, instead of clearing the pickers.
This commit is contained in:
2026-08-11 17:02:31 +07:00
parent b89c7e1915
commit d2d0e655aa
+8 -9
View File
@@ -1278,6 +1278,7 @@
if (!response.ok) { strip.style.display = 'none'; return; } if (!response.ok) { strip.style.display = 'none'; return; }
const stats = await response.json(); const stats = await response.json();
const fmtDate = (value) => new Date(value).toLocaleDateString([], { day: 'numeric', month: 'short', year: 'numeric' }); const fmtDate = (value) => new Date(value).toLocaleDateString([], { day: 'numeric', month: 'short', year: 'numeric' });
state.dbFirstDate = String(stats.first_timestamp).slice(0, 10); // feeds the All-time date range
$('db-total').textContent = Number(stats.total_measurements).toLocaleString(); $('db-total').textContent = Number(stats.total_measurements).toLocaleString();
if (stats.rid_measurements != null) { if (stats.rid_measurements != null) {
const fmtNum = (value) => Number(value || 0).toLocaleString(); const fmtNum = (value) => Number(value || 0).toLocaleString();
@@ -1320,15 +1321,13 @@
if ($('history-range').value === 'custom') return; if ($('history-range').value === 'custom') return;
state.useDates = false; state.useDates = false;
const hours = Number($('history-range').value); const hours = Number($('history-range').value);
if (hours >= 876000) { // Mirror the chosen range into the date pickers (local dates)
$('history-start').value = ''; $('history-end').value = ''; const isoLocal = (d) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
} else { const now = new Date();
// Mirror the chosen range into the date pickers (local dates) $('history-end').value = isoLocal(now);
const isoLocal = (d) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; $('history-start').value = hours >= 876000
const now = new Date(); ? (state.dbFirstDate || '2018-08-01') // All time: DB's first record
$('history-end').value = isoLocal(now); : isoLocal(new Date(now.getTime() - hours * 3600 * 1000));
$('history-start').value = isoLocal(new Date(now.getTime() - hours * 3600 * 1000));
}
if (state.selectedStation) loadHistory(state.selectedStation); if (state.selectedStation) loadHistory(state.selectedStation);
else $('history-status').textContent = 'Select a station first — click one on the map or in the list'; else $('history-status').textContent = 'Select a station first — click one on the map or in the list';
}); });