feat(map): geofence inbox shows cameras and the news line
A hit with evidence keeps the meta line and adds a second line: camera count, the first camera name, and the first headline. A non-empty news url is an anchor; an empty url stays text. Hits without evidence stay the one-liner. snapshot_url is never written into the inbox.
This commit is contained in:
parent
c572f0ee60
commit
3f54fe7df4
2 changed files with 207 additions and 2 deletions
|
|
@ -4367,6 +4367,53 @@ function gfHitTime(p) {
|
|||
if (Number.isNaN(d.getTime())) return String(raw).slice(11, 19) || '—';
|
||||
return d.toISOString().slice(11, 19) + 'Z';
|
||||
}
|
||||
function gfEvidence(p) {
|
||||
if (!p || typeof p !== 'object') return null;
|
||||
let payload = p.payload;
|
||||
if (typeof payload === 'string') {
|
||||
try { payload = JSON.parse(payload); }
|
||||
catch (e) { payload = null; }
|
||||
}
|
||||
if (payload && typeof payload === 'object' && payload.evidence && typeof payload.evidence === 'object') {
|
||||
return payload.evidence;
|
||||
}
|
||||
if (p.evidence && typeof p.evidence === 'object') return p.evidence;
|
||||
return null;
|
||||
}
|
||||
function gfNewsHref(url) {
|
||||
const u = String(url == null ? '' : url).trim();
|
||||
if (!u) return '';
|
||||
const low = u.slice(0, 16).toLowerCase();
|
||||
if (low.startsWith('rtsp:') || low.startsWith('javascript:') || low.startsWith('data:')) return '';
|
||||
return u;
|
||||
}
|
||||
function gfHitEvidenceHtml(ev) {
|
||||
if (!ev || typeof ev !== 'object' || Array.isArray(ev)) return '';
|
||||
const cams = Array.isArray(ev.cameras) ? ev.cameras.slice(0, 5) : [];
|
||||
const news = Array.isArray(ev.news) ? ev.news.slice(0, 3) : [];
|
||||
const bits = [];
|
||||
if (cams.length) {
|
||||
const first = cams[0] && typeof cams[0] === 'object' ? cams[0] : {};
|
||||
const name = first.name == null ? '' : String(first.name).trim();
|
||||
let line = cams.length + ' cams';
|
||||
if (name) line += ' · ' + newsEsc(name);
|
||||
bits.push(line);
|
||||
}
|
||||
const item = news[0] && typeof news[0] === 'object' ? news[0] : null;
|
||||
const headline = item && item.headline != null ? String(item.headline).trim() : '';
|
||||
if (headline) {
|
||||
const href = gfNewsHref(item.url);
|
||||
if (href) {
|
||||
bits.push(
|
||||
`<a href="${newsEsc(href)}" target="_blank" rel="noopener" onclick="event.stopPropagation()">${newsEsc(headline)}</a>`
|
||||
);
|
||||
} else {
|
||||
bits.push(newsEsc(headline));
|
||||
}
|
||||
}
|
||||
if (!bits.length) return '';
|
||||
return `<span class="gf-hit-ev">${bits.join(' · ')}</span>`;
|
||||
}
|
||||
function pushGfInbox(p) {
|
||||
if (!p) return;
|
||||
const box = document.getElementById('gf-inbox');
|
||||
|
|
@ -4379,9 +4426,16 @@ function pushGfInbox(p) {
|
|||
el.dataset.gid = gid;
|
||||
if (p.lat != null) el.dataset.lat = String(p.lat);
|
||||
if (p.lon != null) el.dataset.lon = String(p.lon);
|
||||
el.innerHTML = `<span class="gf-hit-meta">${newsEsc(gfHitTime(p))}</span> · ${newsEsc(name)}` +
|
||||
const meta = `<span class="gf-hit-meta">${newsEsc(gfHitTime(p))}</span> · ${newsEsc(name)}` +
|
||||
` · ${newsEsc(p.source_kind || '')} · ${newsEsc(p.entity_id || '')}`;
|
||||
el.onclick = () => onGfHitClick(el);
|
||||
let ev = '';
|
||||
try { ev = gfHitEvidenceHtml(gfEvidence(p)); } catch (e) { ev = ''; }
|
||||
el.innerHTML = ev ? meta + '<br>' + ev : meta;
|
||||
el.onclick = (clickEv) => {
|
||||
const t = clickEv && clickEv.target;
|
||||
if (t && t.closest && t.closest('a')) return;
|
||||
onGfHitClick(el);
|
||||
};
|
||||
box.prepend(el);
|
||||
while (box.children.length > 50) box.removeChild(box.lastChild);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue