From 8ca4ea2e2bcdda502d1f62937d5847ca0aaffc30 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sun, 13 Jul 2025 09:21:26 -0500 Subject: [PATCH] add link to calls on path --- lib/aprsme_web/live/info_live/show.ex | 32 ++++++++++++++++++++ lib/aprsme_web/live/info_live/show.html.heex | 17 ++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/aprsme_web/live/info_live/show.ex b/lib/aprsme_web/live/info_live/show.ex index 2fd3a4b..38f7ccc 100644 --- a/lib/aprsme_web/live/info_live/show.ex +++ b/lib/aprsme_web/live/info_live/show.ex @@ -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) diff --git a/lib/aprsme_web/live/info_live/show.html.heex b/lib/aprsme_web/live/info_live/show.html.heex index e8bf174..b50ad3e 100644 --- a/lib/aprsme_web/live/info_live/show.html.heex +++ b/lib/aprsme_web/live/info_live/show.html.heex @@ -229,7 +229,22 @@
{gettext("Path")}
-
{@packet.path || ""}
+
+ <% 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} + + <% :text -> %> + {content} + <% end %> + <%= if index < length(path_elements) - 1 do %> + , + <% end %> + <% end %> +
<%= if @packet.path && @packet.path != "" do %>