feat(contact-detail): render band in MHz below 1 GHz, GHz above
The detail page was hard-coding GHz formatting, so 50/144/222/432/902 rendered as 0.1/0.4/0.9 GHz instead of the MHz labels every amateur operator actually uses. Switch to MHz when band < 1000, keep GHz for microwave bands. Also surface band and mode in the header subtitle so the key QSO metadata is visible before SRTM/terrain enrichment completes (the elevation-profile block that previously rendered them is gated on that enrichment).
This commit is contained in:
parent
040667263e
commit
1a8ca44de3
2 changed files with 49 additions and 8 deletions
|
|
@ -748,7 +748,11 @@ defmodule MicrowavepropWeb.ContactLive.Show do
|
|||
{@contact.station1} / {@contact.station2}
|
||||
</span>
|
||||
<:subtitle>
|
||||
{Calendar.strftime(@contact.qso_timestamp, "%Y-%m-%d %H:%M UTC")}
|
||||
{format_band(@contact.band)}
|
||||
<%= if @contact.mode do %>
|
||||
· {@contact.mode}
|
||||
<% end %>
|
||||
· {Calendar.strftime(@contact.qso_timestamp, "%Y-%m-%d %H:%M UTC")}
|
||||
<%= if @contact.flagged_invalid do %>
|
||||
<span class="badge badge-error badge-sm ml-2">Flagged Invalid</span>
|
||||
<% end %>
|
||||
|
|
@ -871,7 +875,7 @@ defmodule MicrowavepropWeb.ContactLive.Show do
|
|||
<%= if @elevation_profile do %>
|
||||
<div class="mb-4">
|
||||
<div class="text-sm font-mono mb-2 text-center">
|
||||
{format_band_ghz(@contact.band)} · {@contact.mode} · {format_dist(
|
||||
{format_band(@contact.band)} · {@contact.mode} · {format_dist(
|
||||
@elevation_profile.dist_km
|
||||
)} · {@contact.grid1 || "—"} → {@contact.grid2 || "—"}
|
||||
</div>
|
||||
|
|
@ -1464,16 +1468,25 @@ defmodule MicrowavepropWeb.ContactLive.Show do
|
|||
"#{String.pad_leading(to_string(whole), 3, "0")}.#{frac}\u00B0"
|
||||
end
|
||||
|
||||
defp format_band_ghz(nil), do: "—"
|
||||
defp format_band(nil), do: "—"
|
||||
|
||||
defp format_band_ghz(band) do
|
||||
defp format_band(band) do
|
||||
mhz = Decimal.to_float(band)
|
||||
ghz = mhz / 1000
|
||||
|
||||
if ghz == Float.round(ghz, 0) do
|
||||
"#{trunc(ghz)} GHz"
|
||||
if mhz < 1000 do
|
||||
if mhz == Float.round(mhz, 0) do
|
||||
"#{trunc(mhz)} MHz"
|
||||
else
|
||||
"#{:erlang.float_to_binary(mhz, decimals: 1)} MHz"
|
||||
end
|
||||
else
|
||||
"#{:erlang.float_to_binary(ghz, decimals: 1)} GHz"
|
||||
ghz = mhz / 1000
|
||||
|
||||
if ghz == Float.round(ghz, 0) do
|
||||
"#{trunc(ghz)} GHz"
|
||||
else
|
||||
"#{:erlang.float_to_binary(ghz, decimals: 1)} GHz"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -150,6 +150,34 @@ defmodule MicrowavepropWeb.ContactLiveTest do
|
|||
assert render(lv) =~ contact.station1
|
||||
end
|
||||
|
||||
# Band display on the detail page: below 1 GHz renders in MHz, at/above
|
||||
# 1 GHz renders in GHz. Amateur band labels match the unit operators use
|
||||
# in QSO logs — you work 432 MHz, you work 10 GHz.
|
||||
test "renders sub-GHz bands in MHz", %{conn: conn} do
|
||||
contact = create_contact(%{band: Decimal.new("432")})
|
||||
{:ok, _lv, html} = live(conn, ~p"/contacts/#{contact.id}")
|
||||
assert html =~ "432 MHz"
|
||||
refute html =~ "0.4 GHz"
|
||||
end
|
||||
|
||||
test "renders 50 MHz in MHz", %{conn: conn} do
|
||||
contact = create_contact(%{band: Decimal.new("50")})
|
||||
{:ok, _lv, html} = live(conn, ~p"/contacts/#{contact.id}")
|
||||
assert html =~ "50 MHz"
|
||||
end
|
||||
|
||||
test "renders GHz bands in GHz", %{conn: conn} do
|
||||
contact = create_contact(%{band: Decimal.new("10000")})
|
||||
{:ok, _lv, html} = live(conn, ~p"/contacts/#{contact.id}")
|
||||
assert html =~ "10 GHz"
|
||||
end
|
||||
|
||||
test "renders 1296 MHz as 1.3 GHz (above the 1 GHz threshold)", %{conn: conn} do
|
||||
contact = create_contact(%{band: Decimal.new("1296")})
|
||||
{:ok, _lv, html} = live(conn, ~p"/contacts/#{contact.id}")
|
||||
assert html =~ "1.3 GHz"
|
||||
end
|
||||
|
||||
test "raises for bad UUID", %{conn: conn} do
|
||||
assert_raise Ecto.NoResultsError, fn ->
|
||||
live(conn, ~p"/contacts/#{Ecto.UUID.generate()}")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue