[feat](trx-frontend-http): give the AIS list the same log shape
A message was three stacked lines — time and name, then MMSI and route, then motion, distance, position and age — so a screen held eight of them. It is one line now: time, vessel, message type, and what the message says, opening in place for the MMSI, the channel frequency, the route, the age, the fix and a jump to the map. Twenty-two fit where eight did. What a message says depends on what it is. Position reports give the fix and the motion; the static and voyage reports that carry no fix give the callsign and where the vessel is bound. Both fall back to whatever fields are present rather than showing nothing. The row vocabulary the APRS list introduced is no longer APRS-specific — the classes are decode-line and decode-expanded now, shared by both, and identity sits in fixed columns so the summaries line up down the list instead of starting wherever the callsign happens to end. The three summary cards above the list go the way of the APRS ones. Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
@@ -27,6 +27,7 @@ interface AisMessage {
|
||||
}
|
||||
interface AisChannelInfo { label: string; badgeClass: string; freqText: string }
|
||||
interface AisBridge {
|
||||
navigateToAprsMap?: (lat: number, lon: number) => void;
|
||||
getDecodeHistoryRetentionMs?: () => number;
|
||||
trxScheduleUiFrameJob?: (key: string, job: () => void) => void;
|
||||
buildAisVesselUrl?: (mmsi: number | null | undefined) => string | null;
|
||||
@@ -212,8 +213,21 @@ function updateAisSummary() {
|
||||
}
|
||||
}
|
||||
|
||||
/** What the message says, in one line: where the vessel is and what it is
|
||||
* doing, or — for the static reports that carry no fix — where it is going. */
|
||||
function aisSummaryText(msg: AisMessage): string {
|
||||
const parts: string[] = [];
|
||||
if (msg.lat != null && msg.lon != null) parts.push(`${msg.lat.toFixed(4)}, ${msg.lon.toFixed(4)}`);
|
||||
const motion = aisMotionText(msg);
|
||||
if (motion) parts.push(motion);
|
||||
const route = aisRouteText(msg);
|
||||
if (route && parts.length < 2) parts.push(route);
|
||||
if (!parts.length) return route || "no position reported";
|
||||
return parts.join(" · ");
|
||||
}
|
||||
|
||||
function renderAisRow(msg: AisMessage): HTMLElement {
|
||||
const row = document.createElement("div");
|
||||
const row = document.createElement("details");
|
||||
row.className = "ais-message";
|
||||
const ts = msg._ts || new Date().toLocaleTimeString([], {
|
||||
hour: "2-digit",
|
||||
@@ -227,8 +241,9 @@ function renderAisRow(msg: AisMessage): HTMLElement {
|
||||
const route = aisRouteText(msg);
|
||||
const distance = aisDistanceText(msg);
|
||||
const pos = msg.lat != null && msg.lon != null
|
||||
? `<a class="ais-pos-link" href="javascript:void(0)" onclick="window.navigateToAprsMap(${msg.lat},${msg.lon})">${msg.lat.toFixed(4)}, ${msg.lon.toFixed(4)}</a>`
|
||||
? `<a class="ais-pos-link" href="javascript:void(0)" data-ais-map="${msg.lat},${msg.lon}">${msg.lat.toFixed(5)}, ${msg.lon.toFixed(5)}</a>`
|
||||
: "";
|
||||
const vesselUrl = aisWindow.buildAisVesselUrl?.(msg.mmsi) ?? null;
|
||||
row.dataset.filterText = [
|
||||
name,
|
||||
msg.mmsi,
|
||||
@@ -243,23 +258,43 @@ function renderAisRow(msg: AisMessage): HTMLElement {
|
||||
.join(" ")
|
||||
.toUpperCase();
|
||||
row.innerHTML =
|
||||
`<div class="ais-row-head">` +
|
||||
`<span class="ais-time">${ts}</span>` +
|
||||
`<summary class="decode-line">` +
|
||||
`<span class="ais-time">${escapeAisHtml(ts)}</span>` +
|
||||
`<span class="ais-call">${nameHtml}</span>` +
|
||||
`<span class="${channel.badgeClass}">${escapeAisHtml(channel.label)}</span>` +
|
||||
`<span class="ais-badge ais-badge-type">${escapeAisHtml(aisTypeLabel(msg.message_type))}</span>` +
|
||||
`</div>` +
|
||||
`<div class="ais-row-meta">` +
|
||||
`<span>MMSI ${escapeAisHtml(String(msg.mmsi))}</span>` +
|
||||
(route ? `<span class="ais-meta-text">${escapeAisHtml(route)}</span>` : "") +
|
||||
`<span class="ais-meta-text">${escapeAisHtml(channel.freqText)}</span>` +
|
||||
`</div>` +
|
||||
`<div class="ais-row-detail">` +
|
||||
(motion ? `<span>${escapeAisHtml(motion)}</span>` : `<span>No motion data</span>`) +
|
||||
(distance ? `<span>${escapeAisHtml(distance)}</span>` : "") +
|
||||
(pos ? `<span>${pos}</span>` : "") +
|
||||
`<span>${escapeAisHtml(aisAgeText(msg._tsMs))}</span>` +
|
||||
`<span class="decode-line-summary">${escapeAisHtml(aisSummaryText(msg))}</span>` +
|
||||
`<span class="${channel.badgeClass}">${escapeAisHtml(channel.label)}</span>` +
|
||||
(distance ? `<span class="decode-line-distance">${escapeAisHtml(distance)}</span>` : "") +
|
||||
`</summary>` +
|
||||
`<div class="decode-expanded">` +
|
||||
`<div class="decode-expanded-meta">` +
|
||||
`<span>MMSI ${escapeAisHtml(String(msg.mmsi))}</span>` +
|
||||
`<span>${escapeAisHtml(channel.freqText)}</span>` +
|
||||
(route ? `<span>${escapeAisHtml(route)}</span>` : "") +
|
||||
(motion ? `<span>${escapeAisHtml(motion)}</span>` : "") +
|
||||
`<span>${escapeAisHtml(aisAgeText(msg._tsMs))}</span>` +
|
||||
(pos ? `<span>${pos}</span>` : "") +
|
||||
`</div>` +
|
||||
`<div class="aprs-row-actions">` +
|
||||
(msg.lat != null && msg.lon != null
|
||||
? `<button class="aprs-inline-btn" type="button" data-ais-map="${msg.lat},${msg.lon}">Map</button>`
|
||||
: "") +
|
||||
(vesselUrl
|
||||
? `<a class="aprs-inline-btn" href="${escapeAisHtml(vesselUrl)}" target="_blank" rel="noopener">Vessel</a>`
|
||||
: "") +
|
||||
`</div>` +
|
||||
`</div>`;
|
||||
|
||||
row.querySelectorAll<HTMLElement>("[data-ais-map]").forEach((element) => {
|
||||
element.addEventListener("click", (event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const [lat, lon] = (element.dataset.aisMap ?? "").split(",").map(Number);
|
||||
if (lat == null || lon == null || !Number.isFinite(lat) || !Number.isFinite(lon)) return;
|
||||
aisWindow.navigateToAprsMap?.(lat, lon);
|
||||
});
|
||||
});
|
||||
|
||||
applyAisFilterToRow(row);
|
||||
return row;
|
||||
}
|
||||
|
||||
@@ -333,19 +333,19 @@ export function renderAprsPacketRow(packet: AprsPacket, options: AprsRowOptions
|
||||
const qrzHref = `https://qrzcq.com/call/${encodeURIComponent(packet.srcCall || "")}`;
|
||||
|
||||
row.innerHTML =
|
||||
`<summary class="aprs-line">` +
|
||||
`<summary class="decode-line">` +
|
||||
`<span class="aprs-time">${escapeAprsHtml(time)}</span>` +
|
||||
(options.badge ? `<span class="aprs-badge aprs-badge-band">${escapeAprsHtml(options.badge)}</span>` : "") +
|
||||
renderLocalAprsSymbol(packet, escapeAprsHtml) +
|
||||
`<span class="aprs-call">${escapeAprsHtml(packet.srcCall ?? "")}</span>` +
|
||||
`<span class="aprs-badge aprs-badge-type aprs-badge-type-${category}">` +
|
||||
`${escapeAprsHtml(aprsCategoryLabel(category))}</span>` +
|
||||
`<span class="aprs-line-summary">${summary ? escapeAprsHtml(summary) : renderAprsInfo(packet)}</span>` +
|
||||
`<span class="decode-line-summary">${summary ? escapeAprsHtml(summary) : renderAprsInfo(packet)}</span>` +
|
||||
(packet.crcOk ? "" : '<span class="aprs-badge aprs-badge-crc">CRC</span>') +
|
||||
(options.distance ? `<span class="aprs-line-distance">${escapeAprsHtml(options.distance)}</span>` : "") +
|
||||
(options.distance ? `<span class="decode-line-distance">${escapeAprsHtml(options.distance)}</span>` : "") +
|
||||
`</summary>` +
|
||||
`<div class="aprs-expanded">` +
|
||||
`<div class="aprs-expanded-meta">` +
|
||||
`<div class="decode-expanded">` +
|
||||
`<div class="decode-expanded-meta">` +
|
||||
`<span>>${escapeAprsHtml(packet.destCall || "--")}</span>` +
|
||||
`<span>${escapeAprsHtml(packet.path || "no path")}</span>` +
|
||||
`<span>${escapeAprsHtml(aprsAgeText(packet._tsMs))}</span>` +
|
||||
@@ -355,9 +355,9 @@ export function renderAprsPacketRow(packet: AprsPacket, options: AprsRowOptions
|
||||
+ `${packet.lat?.toFixed(5)}, ${packet.lon?.toFixed(5)}</a>`
|
||||
: "") +
|
||||
`</div>` +
|
||||
`<div class="aprs-expanded-raw">${renderAprsInfo(packet)}</div>` +
|
||||
`<div class="decode-expanded-raw">${renderAprsInfo(packet)}</div>` +
|
||||
(packet.info_bytes?.length
|
||||
? `<div class="aprs-expanded-bytes">${escapeAprsHtml(aprsHexBytes(packet.info_bytes))}</div>`
|
||||
? `<div class="decode-expanded-bytes">${escapeAprsHtml(aprsHexBytes(packet.info_bytes))}</div>`
|
||||
: "") +
|
||||
`<div class="aprs-row-actions">` +
|
||||
(hasPosition ? `<button class="aprs-inline-btn" type="button" data-aprs-map="${packet.lat},${packet.lon}">Map</button>` : "") +
|
||||
|
||||
@@ -178,7 +178,20 @@ const APRS_FRAMES = [
|
||||
...frame,
|
||||
}));
|
||||
|
||||
const aprsFixture = await startWebFixture({ spectrum: true, history: { aprs: APRS_FRAMES } });
|
||||
// The AIS list is the same shape: a line per message, saying where the vessel
|
||||
// is and what it is doing, with the identifiers behind it.
|
||||
const AIS_MESSAGES = [
|
||||
{ message_type: 1, mmsi: 244660001, vessel_name: "NEDERLAND", channel: "A",
|
||||
lat: 54.35, lon: 18.65, sog_knots: 8.2, cog_deg: 91.4 },
|
||||
{ message_type: 5, mmsi: 244660002, vessel_name: "STENA SPIRIT", channel: "B",
|
||||
callsign: "PBTX", destination: "GDANSK" },
|
||||
].map((message, index) => ({ rig_id: "rig-a", ts_ms: Date.now() - index * 1000, ...message }));
|
||||
|
||||
const aprsFixture = await startWebFixture({
|
||||
spectrum: true,
|
||||
mode: "AIS",
|
||||
history: { aprs: APRS_FRAMES, ais: AIS_MESSAGES },
|
||||
});
|
||||
const aprs = await startBrowser(chromium);
|
||||
|
||||
try {
|
||||
@@ -194,7 +207,7 @@ try {
|
||||
tag: row.tagName,
|
||||
height: Math.round(row.getBoundingClientRect().height),
|
||||
type: row.querySelector(".aprs-badge-type")?.textContent?.trim() ?? "",
|
||||
summary: row.querySelector(".aprs-line-summary")?.textContent?.trim() ?? "",
|
||||
summary: row.querySelector(".decode-line-summary")?.textContent?.trim() ?? "",
|
||||
})));
|
||||
// Newest first, so find each by the type it carries rather than by position.
|
||||
const summaryOf = (type) => rows.find((row) => row.type === type)?.summary ?? "";
|
||||
@@ -213,20 +226,49 @@ try {
|
||||
|
||||
// The frame as it arrived is still there, one click away.
|
||||
await aprs.page.locator("#aprs-packets .aprs-packet", { hasText: "25 °C" })
|
||||
.locator(".aprs-line").first().click();
|
||||
.locator(".decode-line").first().click();
|
||||
await aprs.page.waitForTimeout(200);
|
||||
const expanded = await aprs.page.evaluate(() => {
|
||||
const row = document.querySelector("#aprs-packets .aprs-packet[open]");
|
||||
return {
|
||||
open: row.hasAttribute("open"),
|
||||
raw: row.querySelector(".aprs-expanded-raw")?.textContent?.trim() ?? "",
|
||||
meta: row.querySelector(".aprs-expanded-meta")?.textContent ?? "",
|
||||
raw: row.querySelector(".decode-expanded-raw")?.textContent?.trim() ?? "",
|
||||
meta: row.querySelector(".decode-expanded-meta")?.textContent ?? "",
|
||||
};
|
||||
});
|
||||
assert.equal(expanded.open, true, "the frame did not open");
|
||||
assert.match(expanded.raw, /^_10090556c220s004g005t077/, `raw frame: ${expanded.raw}`);
|
||||
assert.match(expanded.meta, /WIDE1-1/, `expanded meta: ${expanded.meta}`);
|
||||
|
||||
// AIS, on the same row.
|
||||
await aprs.page.locator('.sub-tab[data-subtab="ais"]').click();
|
||||
await aprs.page.waitForTimeout(300);
|
||||
const aisRows = await aprs.page.evaluate(() =>
|
||||
[...document.querySelectorAll("#ais-messages .ais-message")].map((row) => ({
|
||||
tag: row.tagName,
|
||||
height: Math.round(row.getBoundingClientRect().height),
|
||||
name: row.querySelector(".ais-call")?.textContent?.trim() ?? "",
|
||||
summary: row.querySelector(".decode-line-summary")?.textContent?.trim() ?? "",
|
||||
})));
|
||||
assert.equal(aisRows.length, AIS_MESSAGES.length, `rendered ${aisRows.length} messages`);
|
||||
for (const row of aisRows) {
|
||||
assert.equal(row.tag, "DETAILS", "an AIS message is not expandable in place");
|
||||
assert.ok(row.height < 44, `an AIS message is ${row.height}px tall`);
|
||||
}
|
||||
const positionRow = aisRows.find((row) => row.name === "NEDERLAND");
|
||||
const staticRow = aisRows.find((row) => row.name === "STENA SPIRIT");
|
||||
assert.match(positionRow?.summary ?? "", /54\.3500, 18\.6500/, `position: ${positionRow?.summary}`);
|
||||
assert.match(positionRow?.summary ?? "", /8\.2 kn/, `position: ${positionRow?.summary}`);
|
||||
// A static report carries no fix, so it says where the vessel is going.
|
||||
assert.match(staticRow?.summary ?? "", /PBTX -> GDANSK/, `static: ${staticRow?.summary}`);
|
||||
|
||||
await aprs.page.locator("#ais-messages .ais-message .decode-line").first().click();
|
||||
await aprs.page.waitForTimeout(200);
|
||||
const aisExpanded = await aprs.page.evaluate(() =>
|
||||
document.querySelector("#ais-messages .ais-message[open] .decode-expanded-meta")?.textContent ?? "");
|
||||
assert.match(aisExpanded, /MMSI 2446600/, `expanded AIS: ${aisExpanded}`);
|
||||
assert.match(aisExpanded, /MHz/, `expanded AIS: ${aisExpanded}`);
|
||||
|
||||
assert.deepEqual(aprs.runtimeErrors, []);
|
||||
} finally {
|
||||
await aprs.browser.close();
|
||||
|
||||
Reference in New Issue
Block a user