Contact detail link to open in Path Calculator
Adds an "Open in Path Calculator" action to the contact detail header. The link navigates to /path with source/destination prefilled (preferring Maidenhead grids over station callsigns, since grids are exact and callsigns go through a QRZ + geocoder round-trip) and the contact's band selected. PathLive's handle_params already auto-runs the calculation when source + destination are present, so the user lands straight on the computed path ready to tweak TX power, antenna heights, and gains.
This commit is contained in:
parent
bcfda54897
commit
67d64109e6
1 changed files with 25 additions and 0 deletions
|
|
@ -721,6 +721,9 @@ defmodule MicrowavepropWeb.ContactLive.Show do
|
|||
<.icon name="hero-flag" class="w-4 h-4" />
|
||||
{if @contact.flagged_invalid, do: "Unflag", else: "Flag as Invalid"}
|
||||
</button>
|
||||
<.link navigate={path_calc_url(@contact)} class="btn btn-sm btn-outline">
|
||||
<.icon name="hero-calculator" class="w-4 h-4" /> Open in Path Calculator
|
||||
</.link>
|
||||
<.link navigate={~p"/contacts"} class="btn btn-sm btn-ghost">
|
||||
<.icon name="hero-arrow-left" class="w-4 h-4" /> Back to Contacts
|
||||
</.link>
|
||||
|
|
@ -2045,4 +2048,26 @@ defmodule MicrowavepropWeb.ContactLive.Show do
|
|||
true -> "badge badge-sm badge-ghost"
|
||||
end
|
||||
end
|
||||
|
||||
defp path_calc_url(contact) do
|
||||
source = prefer_grid(contact.grid1, contact.station1)
|
||||
dest = prefer_grid(contact.grid2, contact.station2)
|
||||
|
||||
params = maybe_put_band(%{"source" => source, "destination" => dest}, contact.band)
|
||||
|
||||
"/path?" <> URI.encode_query(params)
|
||||
end
|
||||
|
||||
defp prefer_grid(grid, _fallback) when is_binary(grid) and grid != "", do: grid
|
||||
defp prefer_grid(_grid, fallback), do: fallback || ""
|
||||
|
||||
defp maybe_put_band(params, nil), do: params
|
||||
|
||||
defp maybe_put_band(params, %Decimal{} = band) do
|
||||
Map.put(params, "band", Decimal.to_string(band, :normal))
|
||||
end
|
||||
|
||||
defp maybe_put_band(params, band) when is_integer(band), do: Map.put(params, "band", Integer.to_string(band))
|
||||
defp maybe_put_band(params, band) when is_binary(band), do: Map.put(params, "band", band)
|
||||
defp maybe_put_band(params, _), do: params
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue