diff --git a/situation.php b/situation.php index 1e85110..220cfc9 100644 --- a/situation.php +++ b/situation.php @@ -1209,6 +1209,27 @@ function sitAgo(mysqlDt) { return Math.floor(s / 86400) + 'd ago'; } + // A GPS fix is a unit update too. Keep the EOC Units table aligned with + // the map by showing the newest of the tracking, status, and unit-row + // timestamps instead of reporting an old status change while fresh + // Traccar/OwnTracks positions continue to arrive. + function sitLatestAgo() { + var latest = ''; + var latestMs = -Infinity; + var fallback = ''; + for (var i = 0; i < arguments.length; i++) { + var value = arguments[i]; + if (!value) continue; + if (!fallback) fallback = value; + var parsed = new Date(String(value).replace(' ', 'T')).getTime(); + if (!isNaN(parsed) && parsed > latestMs) { + latest = value; + latestMs = parsed; + } + } + return sitAgo(latest || fallback); + } + // GH #49 (round 3) — respect the CONFIGURED facility-status colors, exactly // like the (correct) Facilities page does (facilities.js: uses f.bg_color / // f.text_color / f.status_name straight from api/facilities.php). The old @@ -1483,7 +1504,7 @@ function renderUnitsList() { + (u.status_text_color ? 'color:' + esc(u.status_text_color) + ';' : '') + 'font-size:0.62rem;">' + esc(u.status_name || '') + '' + '' + esc(addr) + '' + - '' + sitAgo(u.status_updated || u.updated) + '' + + '' + sitLatestAgo(u.last_track, u.status_updated, u.updated) + '' + ''; } tbody.innerHTML = html; diff --git a/tests/test_situation_map_fixes.php b/tests/test_situation_map_fixes.php index 77e166c..e8bd085 100644 --- a/tests/test_situation_map_fixes.php +++ b/tests/test_situation_map_fixes.php @@ -87,6 +87,13 @@ function t($label, $cond) { global $passed, $failed; echo ($cond ? "[PASS] " : " strpos($s, 'refreshInterval: