- Rename beacons.power_watts to power_mw (migration multiplies existing values by 1000); form/list/show all relabeled to "Power (mW)" - Fix Add-monitor button alignment on /users/settings by rendering the label above and putting the input and button in a plain flex row so the input wrapper margin no longer offsets the button - Extend the settings page re-auth window from 10 minutes to 24 hours
70 lines
2.1 KiB
Elixir
70 lines
2.1 KiB
Elixir
defmodule MicrowavepropWeb.BeaconLive.Show 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}>
|
|
<.header>
|
|
{@beacon.callsign}
|
|
<:subtitle>{@beacon.frequency_mhz} MHz · {@beacon.grid}</:subtitle>
|
|
<:actions>
|
|
<.button navigate={~p"/beacons"}>
|
|
<.icon name="hero-arrow-left" />
|
|
</.button>
|
|
<.button
|
|
:if={admin?(@current_scope)}
|
|
variant="primary"
|
|
navigate={~p"/beacons/#{@beacon}/edit?return_to=show"}
|
|
>
|
|
<.icon name="hero-pencil-square" /> Edit
|
|
</.button>
|
|
</:actions>
|
|
</.header>
|
|
|
|
<.list>
|
|
<:item title="Frequency (MHz)">{@beacon.frequency_mhz}</:item>
|
|
<:item title="Callsign">{@beacon.callsign}</:item>
|
|
<:item title="Grid">{@beacon.grid}</:item>
|
|
<:item title="Latitude">{@beacon.lat}</:item>
|
|
<:item title="Longitude">{@beacon.lon}</:item>
|
|
<:item title="Power (mW)">{@beacon.power_mw}</:item>
|
|
<:item title="Height above ground (m)">{@beacon.height_m}</:item>
|
|
</.list>
|
|
</Layouts.app>
|
|
"""
|
|
end
|
|
|
|
@impl true
|
|
def mount(%{"id" => id}, _session, socket) do
|
|
if connected?(socket), do: Beacons.subscribe_beacons()
|
|
|
|
{:ok,
|
|
socket
|
|
|> assign(:page_title, "Beacon")
|
|
|> assign(:beacon, Beacons.get_beacon!(id))}
|
|
end
|
|
|
|
@impl true
|
|
def handle_info({:updated, %Beacon{id: id} = beacon}, %{assigns: %{beacon: %{id: id}}} = socket) do
|
|
{:noreply, assign(socket, :beacon, beacon)}
|
|
end
|
|
|
|
def handle_info({:deleted, %Beacon{id: id}}, %{assigns: %{beacon: %{id: id}}} = socket) do
|
|
{:noreply,
|
|
socket
|
|
|> put_flash(:error, "This beacon was deleted.")
|
|
|> push_navigate(to: ~p"/beacons")}
|
|
end
|
|
|
|
def handle_info({type, %Beacon{}}, socket) when type in [:created, :updated, :deleted] do
|
|
{:noreply, socket}
|
|
end
|
|
|
|
defp admin?(%{user: %{is_admin: true}}), do: true
|
|
defp admin?(_), do: false
|
|
end
|