Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion situation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1483,7 +1504,7 @@ function renderUnitsList() {
+ (u.status_text_color ? 'color:' + esc(u.status_text_color) + ';' : '')
+ 'font-size:0.62rem;">' + esc(u.status_name || '') + '</span></td>' +
'<td>' + esc(addr) + '</td>' +
'<td class="text-body-secondary" style="font-size:0.68rem;">' + sitAgo(u.status_updated || u.updated) + '</td>' +
'<td class="text-body-secondary" style="font-size:0.68rem;">' + sitLatestAgo(u.last_track, u.status_updated, u.updated) + '</td>' +
'</tr>';
}
tbody.innerHTML = html;
Expand Down
7 changes: 7 additions & 0 deletions tests/test_situation_map_fixes.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ function t($label, $cond) { global $passed, $failed; echo ($cond ? "[PASS] " : "
strpos($s, 'refreshInterval: <?php echo (int) ($sitUnitRefreshSecs') !== false &&
strpos($s, '}, <?php echo (int) ($sitBoardRefreshSecs') !== false);

// GH #71 — GPS ingest can advance while the unit status remains unchanged.
// The EOC Updated cell must include the resolved last_track timestamp and
// compare it with status/unit timestamps instead of using a stale first value.
t("GH#71: EOC unit Updated cell uses the newest GPS/status/unit timestamp",
strpos($s, 'function sitLatestAgo()') !== false &&
strpos($s, 'sitLatestAgo(u.last_track, u.status_updated, u.updated)') !== false);

// ── #60/#46 — situation control gets the shared per-category markup overlays ──
t("#60: situation.php attaches MapPrefs.addMarkupOverlays (dashboard-parity layer toggles)",
(bool) preg_match('/MapPrefs\.addMarkupOverlays\(map, sitLayersControl\)/', $s) &&
Expand Down