mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-05 01:31:49 -07:00
Enhance scanning state handling and localization updates across multiple language files
This commit is contained in:
@@ -577,11 +577,15 @@ var _nextScanTimeAnchor = null;
|
|||||||
var _currentStateAnchor = null;
|
var _currentStateAnchor = null;
|
||||||
var _scanEtaTickerId = null;
|
var _scanEtaTickerId = null;
|
||||||
var _pluginsData = null;
|
var _pluginsData = null;
|
||||||
|
var _wasImminent = false; // true once the countdown displayed "imminent"; gates the Scanning... label
|
||||||
|
var _imminentForTime = null; // the _nextScanTimeAnchor value that last set _wasImminent
|
||||||
|
// prevents re-arming on the same (already-consumed) timestamp
|
||||||
|
|
||||||
// Returns true when the backend is actively scanning (not idle).
|
// Returns true when the backend is actively scanning (not idle).
|
||||||
// States that indicate scanning: Process: Start, Check scan, Scan processed.
|
// Uses an exclusion approach — only "Process: Idle" and an empty/null state are non-scanning.
|
||||||
|
// This future-proofs against new states added to the scan pipeline (e.g. "Plugin: AVAHISCAN").
|
||||||
function isScanningState(state) {
|
function isScanningState(state) {
|
||||||
return ['Process: Start', 'Check scan', 'Scan processed'].indexOf(state) !== -1;
|
return !!state && state !== 'Process: Idle';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch plugins.json once on page load so we can guard ETA display to device_scanner plugins only.
|
// Fetch plugins.json once on page load so we can guard ETA display to device_scanner plugins only.
|
||||||
@@ -603,31 +607,37 @@ function updateScanEtaDisplay(nextScanTime, currentState) {
|
|||||||
_nextScanTimeAnchor = nextScanTime || _nextScanTimeAnchor;
|
_nextScanTimeAnchor = nextScanTime || _nextScanTimeAnchor;
|
||||||
_currentStateAnchor = currentState || _currentStateAnchor;
|
_currentStateAnchor = currentState || _currentStateAnchor;
|
||||||
|
|
||||||
|
// Reset the imminent gate when the scan finishes back to idle so the next cycle starts clean.
|
||||||
|
if (currentState === 'Process: Idle') { _wasImminent = false; }
|
||||||
|
|
||||||
// Restart the per-second title-bar ticker
|
// Restart the per-second title-bar ticker
|
||||||
if (_scanEtaTickerId !== null) { clearInterval(_scanEtaTickerId); }
|
if (_scanEtaTickerId !== null) { clearInterval(_scanEtaTickerId); }
|
||||||
|
|
||||||
|
function getEtaLabel() {
|
||||||
|
if (!hasEnabledDeviceScanners()) return '';
|
||||||
|
if (isScanningState(_currentStateAnchor) && _wasImminent) return getString('Device_Scanning');
|
||||||
|
var label = computeNextScanLabel(_nextScanTimeAnchor);
|
||||||
|
// Arm _wasImminent only for a NEW next_scan_time anchor — not the already-consumed one.
|
||||||
|
// This prevents the ticker from re-arming immediately after "Process: Idle" resets the flag
|
||||||
|
// while _nextScanTimeAnchor still holds the now-past timestamp.
|
||||||
|
if (label === getString('Device_NextScan_Imminent') && _nextScanTimeAnchor !== _imminentForTime) {
|
||||||
|
_wasImminent = true;
|
||||||
|
_imminentForTime = _nextScanTimeAnchor;
|
||||||
|
}
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
function tickTitleBar() {
|
function tickTitleBar() {
|
||||||
var eta = document.getElementById('nextScanEta');
|
var eta = document.getElementById('nextScanEta');
|
||||||
if (!eta) return;
|
if (!eta) return;
|
||||||
if (!hasEnabledDeviceScanners()) {
|
var label = getEtaLabel();
|
||||||
eta.style.display = 'none';
|
if (!label) { eta.style.display = 'none'; return; }
|
||||||
return;
|
eta.textContent = label;
|
||||||
}
|
|
||||||
// Show 'Scanning...' when the backend is actively scanning, countdown otherwise.
|
|
||||||
eta.textContent = isScanningState(_currentStateAnchor)
|
|
||||||
? getString('Device_Scanning')
|
|
||||||
: computeNextScanLabel(_nextScanTimeAnchor);
|
|
||||||
eta.style.display = '';
|
eta.style.display = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update DataTables empty message once per SSE event — avoids AJAX spam on server-side tables.
|
// Update DataTables empty message once per SSE event — avoids AJAX spam on server-side tables.
|
||||||
// Show 'Scanning...' when active, countdown when idle, nothing when no device_scanner enabled.
|
var label = getEtaLabel();
|
||||||
var label = '';
|
|
||||||
if (hasEnabledDeviceScanners()) {
|
|
||||||
label = isScanningState(_currentStateAnchor)
|
|
||||||
? getString('Device_Scanning')
|
|
||||||
: computeNextScanLabel(_nextScanTimeAnchor);
|
|
||||||
}
|
|
||||||
if ($.fn.DataTable.isDataTable('#tableDevices')) {
|
if ($.fn.DataTable.isDataTable('#tableDevices')) {
|
||||||
var dt = $('#tableDevices').DataTable();
|
var dt = $('#tableDevices').DataTable();
|
||||||
dt.settings()[0].oLanguage.sEmptyTable = buildEmptyDeviceTableMessage(label);
|
dt.settings()[0].oLanguage.sEmptyTable = buildEmptyDeviceTableMessage(label);
|
||||||
|
|||||||
@@ -203,7 +203,7 @@
|
|||||||
"Device_MultiEdit_MassActions": "Mass actions:",
|
"Device_MultiEdit_MassActions": "Mass actions:",
|
||||||
"Device_MultiEdit_No_Devices": "No devices selected.",
|
"Device_MultiEdit_No_Devices": "No devices selected.",
|
||||||
"Device_MultiEdit_Tooltip": "Careful. Clicking this will apply the value on the left to all devices selected above.",
|
"Device_MultiEdit_Tooltip": "Careful. Clicking this will apply the value on the left to all devices selected above.",
|
||||||
"Device_NextScan_Imminent": "imminent",
|
"Device_NextScan_Imminent": "Imminent...",
|
||||||
"Device_NextScan_In": "Next scan in ",
|
"Device_NextScan_In": "Next scan in ",
|
||||||
"Device_NoData_Help": "If devices don't appear after the scan, check your SCAN_SUBNETS setting and <a href=\"https://docs.netalertx.com/SUBNETS\" target=\"_blank\">documentation</a>.",
|
"Device_NoData_Help": "If devices don't appear after the scan, check your SCAN_SUBNETS setting and <a href=\"https://docs.netalertx.com/SUBNETS\" target=\"_blank\">documentation</a>.",
|
||||||
"Device_NoData_Scanning": "Waiting for the first scan - this may take several minutes after the initial setup.",
|
"Device_NoData_Scanning": "Waiting for the first scan - this may take several minutes after the initial setup.",
|
||||||
|
|||||||
Reference in New Issue
Block a user