add link to calls on path
This commit is contained in:
parent
4348d34f62
commit
8ca4ea2e2b
2 changed files with 48 additions and 1 deletions
|
|
@ -342,6 +342,38 @@ defmodule AprsmeWeb.InfoLive.Show do
|
|||
|
||||
defp decode_aprs_path(_), do: nil
|
||||
|
||||
@doc """
|
||||
Parses the APRS path and creates linked callsigns where appropriate.
|
||||
Returns a list of tuples: {:text, string} or {:link, callsign, display_text}
|
||||
"""
|
||||
def parse_path_with_links(path) when is_binary(path) and path != "" do
|
||||
path
|
||||
|> String.split(",")
|
||||
|> Enum.map(&parse_path_element_with_link/1)
|
||||
end
|
||||
|
||||
def parse_path_with_links(_), do: []
|
||||
|
||||
defp parse_path_element_with_link(element) do
|
||||
element = String.trim(element)
|
||||
|
||||
# Check if it's a callsign (with or without SSID)
|
||||
if Regex.match?(~r/^[A-Z0-9]{1,6}(-\d{1,2})?(\*)?$/, element) and
|
||||
not String.starts_with?(element, "WIDE") and
|
||||
not String.starts_with?(element, "TRACE") and
|
||||
not String.starts_with?(element, "RELAY") and
|
||||
not String.starts_with?(element, "TCPIP") and
|
||||
not String.starts_with?(element, "q") do
|
||||
# Remove asterisk if present (indicates the packet was digipeated through this station)
|
||||
callsign = String.replace(element, "*", "")
|
||||
display = if String.ends_with?(element, "*"), do: "#{callsign}*", else: callsign
|
||||
{:link, callsign, display}
|
||||
else
|
||||
# Not a linkable callsign, just return as text
|
||||
{:text, element, element}
|
||||
end
|
||||
end
|
||||
|
||||
defp decode_path_element(element) do
|
||||
element = String.trim(element)
|
||||
|
||||
|
|
|
|||
|
|
@ -229,7 +229,22 @@
|
|||
</div>
|
||||
<div>
|
||||
<dt class="text-xs font-medium opacity-70">{gettext("Path")}</dt>
|
||||
<dd class="mt-1 text-sm font-semibold">{@packet.path || ""}</dd>
|
||||
<dd class="mt-1 text-sm font-semibold">
|
||||
<% path_elements = parse_path_with_links(@packet.path) %>
|
||||
<%= for {{type, content, display}, index} <- Enum.with_index(path_elements) do %>
|
||||
<%= case type do %>
|
||||
<% :link -> %>
|
||||
<.link navigate={~p"/info/#{content}"} class="link link-primary">
|
||||
{display}
|
||||
</.link>
|
||||
<% :text -> %>
|
||||
{content}
|
||||
<% end %>
|
||||
<%= if index < length(path_elements) - 1 do %>
|
||||
<span class="opacity-50">,</span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</dd>
|
||||
</div>
|
||||
<%= if @packet.path && @packet.path != "" do %>
|
||||
<div class="col-span-2">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue