Profile page:
* New MicrowavepropWeb.UserProfileLive at /u/:callsign is a public
page showing a user's contacts and beacons. Resolves case-
insensitively so /u/w5isp and /u/W5ISP are the same thing; unknown
callsigns redirect to /. Uses daisyUI card / stats / table
components with an avatar-placeholder initial and hero icons.
* Accounts.get_user_by_callsign/1 (case-insensitive) plus
Radio.list_contacts_for_user/1 and Beacons.list_beacons_for_user/1
back the page. Beacons list includes both approved and pending so
owners see their drafts.
* The top nav bar and the three LiveView sidebars (MapLive,
WeatherMapLive, ContactMapLive) now render the logged-in callsign
as a navigate link to /u/:callsign instead of a static label.
* Nine new tests cover the lookup, the LiveView render, and the
ownership-scoped queries.
Flexible band input:
* New Microwaveprop.Radio.BandResolver module converts any of:
ADIF wavelength labels ("33cm", "1.25cm", "6mm", case/whitespace
insensitive), numeric frequency strings ("903.100", "10368.000"),
and canonical MHz integers into the one of the site's known bands.
Returns the nearest allowed band for numeric inputs >= 900 MHz,
nil otherwise.
* 902 MHz is added to Contact.@allowed_bands, ContactEdit.@allowed_bands,
AdifImport.@allowed_bands, and the BandResolver list so "33cm"
round-trips end-to-end.
* AdifImport and CsvImport now delegate band resolution to
BandResolver, and Radio.create_contact/2 normalizes the :band attr
on the way in so the manual form and any API callers benefit too.
CsvImport's "invalid band" tests previously used 99999 MHz which
the new resolver snaps to the nearest allowed band; swapped to
"notaband" which is truly unresolvable.
Contacts and beacons list UX:
* Remove the "Submitted" column from /contacts — it duplicated info
already visible on the detail page and was pushing the real
columns off narrow viewports. submitted_cell/1 and its three
column-specific tests go with it.
* Hide the Lat / Lon columns from /beacons — six decimal places of
coordinates weren't useful next to the grid square and took a
disproportionate amount of row width.
167 lines
5.4 KiB
Elixir
167 lines
5.4 KiB
Elixir
defmodule MicrowavepropWeb.BeaconLive.Index do
|
|
@moduledoc false
|
|
use MicrowavepropWeb, :live_view
|
|
|
|
alias Microwaveprop.Beacons
|
|
alias Microwaveprop.Beacons.Beacon
|
|
|
|
@impl true
|
|
def render(assigns) do
|
|
~H"""
|
|
<Layouts.app flash={@flash} current_scope={@current_scope} max_width="max-w-6xl">
|
|
<.header>
|
|
Beacons
|
|
<:subtitle>Microwave beacons tracked by NTMS.</:subtitle>
|
|
<:actions>
|
|
<.button variant="primary" navigate={~p"/beacons/new"}>
|
|
<.icon name="hero-plus" /> Submit Beacon
|
|
</.button>
|
|
</:actions>
|
|
</.header>
|
|
|
|
<.table
|
|
id="beacons"
|
|
rows={@streams.beacons}
|
|
row_click={fn {_id, beacon} -> JS.navigate(~p"/beacons/#{beacon}") end}
|
|
>
|
|
<:col :let={{_id, beacon}} label="Frequency (MHz)">
|
|
{Beacon.format_freq(beacon.frequency_mhz)}
|
|
</:col>
|
|
<:col :let={{_id, beacon}} label="Call">{beacon.callsign}</:col>
|
|
<:col :let={{_id, beacon}} label="Grid">{beacon.grid}</:col>
|
|
<:col :let={{_id, beacon}} label="EIRP (mW)">{Beacon.format_mw(beacon.power_mw)}</:col>
|
|
<:col :let={{_id, beacon}} label="Height AGL (ft)">{beacon.height_ft}</:col>
|
|
<:col :let={{_id, beacon}} label="Keying">{Beacon.keying_label(beacon.keying)}</:col>
|
|
<:col :let={{_id, beacon}} label="On air">
|
|
<span class={["badge badge-sm", (beacon.on_the_air && "badge-success") || "badge-ghost"]}>
|
|
{if beacon.on_the_air, do: "Yes", else: "No"}
|
|
</span>
|
|
</:col>
|
|
<:action :let={{_id, beacon}}>
|
|
<div class="sr-only">
|
|
<.link navigate={~p"/beacons/#{beacon}"}>Show</.link>
|
|
</div>
|
|
<.link :if={admin?(@current_scope)} navigate={~p"/beacons/#{beacon}/edit"}>Edit</.link>
|
|
</:action>
|
|
<:action :let={{id, beacon}}>
|
|
<.link
|
|
:if={admin?(@current_scope)}
|
|
phx-click={JS.push("delete", value: %{id: beacon.id}) |> hide("##{id}")}
|
|
data-confirm="Delete this beacon?"
|
|
>
|
|
Delete
|
|
</.link>
|
|
</:action>
|
|
</.table>
|
|
|
|
<div :if={admin?(@current_scope) and @pending != []} class="mt-10">
|
|
<.header>
|
|
Pending approval
|
|
<:subtitle>Submitted beacons waiting for admin review.</:subtitle>
|
|
</.header>
|
|
|
|
<.table
|
|
id="pending-beacons"
|
|
rows={@streams.pending}
|
|
row_click={fn {_id, beacon} -> JS.navigate(~p"/beacons/#{beacon}") end}
|
|
>
|
|
<:col :let={{_id, beacon}} label="Frequency (MHz)">
|
|
{Beacon.format_freq(beacon.frequency_mhz)}
|
|
</:col>
|
|
<:col :let={{_id, beacon}} label="Call">{beacon.callsign}</:col>
|
|
<:col :let={{_id, beacon}} label="Grid">{beacon.grid}</:col>
|
|
<:col :let={{_id, beacon}} label="EIRP (mW)">{Beacon.format_mw(beacon.power_mw)}</:col>
|
|
<:col :let={{_id, beacon}} label="Height AGL (ft)">{beacon.height_ft}</:col>
|
|
<:col :let={{_id, beacon}} label="Submitted">
|
|
{Calendar.strftime(beacon.inserted_at, "%Y-%m-%d %H:%M UTC")}
|
|
</:col>
|
|
<:action :let={{_id, beacon}}>
|
|
<.link
|
|
phx-click={JS.push("approve", value: %{id: beacon.id})}
|
|
data-confirm="Approve this beacon?"
|
|
>
|
|
Approve
|
|
</.link>
|
|
</:action>
|
|
<:action :let={{id, beacon}}>
|
|
<.link
|
|
phx-click={JS.push("delete", value: %{id: beacon.id}) |> hide("##{id}")}
|
|
data-confirm="Delete this beacon?"
|
|
>
|
|
Delete
|
|
</.link>
|
|
</:action>
|
|
</.table>
|
|
</div>
|
|
</Layouts.app>
|
|
"""
|
|
end
|
|
|
|
@impl true
|
|
def mount(_params, _session, socket) do
|
|
if connected?(socket), do: Beacons.subscribe_beacons()
|
|
|
|
pending =
|
|
if admin?(socket.assigns.current_scope) do
|
|
Beacons.list_pending_beacons()
|
|
else
|
|
[]
|
|
end
|
|
|
|
{:ok,
|
|
socket
|
|
|> assign(:page_title, "Beacons")
|
|
|> assign(:pending, pending)
|
|
|> stream(:beacons, Beacons.list_beacons())
|
|
|> stream(:pending, pending)}
|
|
end
|
|
|
|
@impl true
|
|
def handle_event("delete", %{"id" => id}, socket) do
|
|
if admin?(socket.assigns.current_scope) do
|
|
beacon = Beacons.get_beacon!(id)
|
|
{:ok, _} = Beacons.delete_beacon(beacon)
|
|
|
|
{:noreply,
|
|
socket
|
|
|> stream_delete(:beacons, beacon)
|
|
|> stream_delete(:pending, beacon)}
|
|
else
|
|
{:noreply, put_flash(socket, :error, "Admins only.")}
|
|
end
|
|
end
|
|
|
|
def handle_event("approve", %{"id" => id}, socket) do
|
|
if admin?(socket.assigns.current_scope) do
|
|
beacon = Beacons.get_beacon!(id)
|
|
{:ok, approved} = Beacons.approve_beacon(beacon)
|
|
|
|
{:noreply,
|
|
socket
|
|
|> put_flash(:info, "Approved #{approved.callsign}.")
|
|
|> stream_delete(:pending, beacon)
|
|
|> stream_insert(:beacons, approved)}
|
|
else
|
|
{:noreply, put_flash(socket, :error, "Admins only.")}
|
|
end
|
|
end
|
|
|
|
@impl true
|
|
def handle_info({type, %Beacon{}}, socket) when type in [:created, :updated, :deleted] do
|
|
pending =
|
|
if admin?(socket.assigns.current_scope) do
|
|
Beacons.list_pending_beacons()
|
|
else
|
|
[]
|
|
end
|
|
|
|
{:noreply,
|
|
socket
|
|
|> assign(:pending, pending)
|
|
|> stream(:beacons, Beacons.list_beacons(), reset: true)
|
|
|> stream(:pending, pending, reset: true)}
|
|
end
|
|
|
|
defp admin?(%{user: %{is_admin: true}}), do: true
|
|
defp admin?(_), do: false
|
|
end
|