diff --git a/lib/towerops_web/live/agent_live/helpers.ex b/lib/towerops_web/live/agent_live/helpers.ex index 77dc8513..60b6bbfc 100644 --- a/lib/towerops_web/live/agent_live/helpers.ex +++ b/lib/towerops_web/live/agent_live/helpers.ex @@ -89,4 +89,39 @@ defmodule ToweropsWeb.AgentLive.Helpers do end def format_uptime(_), do: "Unknown" + + @doc """ + Formats a DateTime into a full date and time string. + + Returns strings like "Jan 15, 2026 at 2:34 PM UTC". + """ + def format_datetime(nil), do: "Never" + + def format_datetime(datetime) do + Calendar.strftime(datetime, "%b %d, %Y at %I:%M %p %Z") + end + + @doc """ + Formats a DateTime into a short date string. + + Returns strings like "Jan 15, 2026". + """ + def format_date(nil), do: "Never" + + def format_date(datetime) do + Calendar.strftime(datetime, "%b %d, %Y") + end + + @doc """ + Formats a DateTime into a relative time with full datetime in parentheses. + + Returns strings like "5m ago (Jan 15, 2026 at 2:34 PM UTC)". + """ + def format_last_seen_with_date(nil), do: "Never" + + def format_last_seen_with_date(datetime) do + relative = format_last_seen(datetime) + full = format_datetime(datetime) + "#{relative} (#{full})" + end end diff --git a/lib/towerops_web/live/agent_live/index.html.heex b/lib/towerops_web/live/agent_live/index.html.heex index 1199dee9..83daba3a 100644 --- a/lib/towerops_web/live/agent_live/index.html.heex +++ b/lib/towerops_web/live/agent_live/index.html.heex @@ -98,11 +98,16 @@ <:col :let={agent} label="Last Seen"> -
+
{format_last_seen(agent.last_seen_at)}
+ <%= if agent.last_seen_at do %> +
+ {format_datetime(agent.last_seen_at)} +
+ <% end %> <%= if agent.last_ip do %> -
+
{agent.last_ip}
<% end %> diff --git a/lib/towerops_web/live/agent_live/show.html.heex b/lib/towerops_web/live/agent_live/show.html.heex index ca0768b4..ec3c09b1 100644 --- a/lib/towerops_web/live/agent_live/show.html.heex +++ b/lib/towerops_web/live/agent_live/show.html.heex @@ -55,18 +55,23 @@
-
+

Last Seen

{format_last_seen(@agent_token.last_seen_at)}

+ <%= if @agent_token.last_seen_at do %> +

+ {format_datetime(@agent_token.last_seen_at)} +

+ <% end %> <%= if @agent_token.last_ip do %>

{@agent_token.last_ip}

<% end %>
- <.icon name="hero-clock" class="h-8 w-8 text-zinc-400 dark:text-zinc-600" /> + <.icon name="hero-clock" class="h-8 w-8 text-zinc-400 dark:text-zinc-600 flex-shrink-0" />
@@ -130,6 +135,57 @@
<% end %> + +
+

+ Timestamps +

+
+
+
Created
+
+ {format_datetime(@agent_token.inserted_at)} +
+
+ {format_last_seen(@agent_token.inserted_at)} (created) +
+
+ +
+
Last Updated
+
+ {format_datetime(@agent_token.updated_at)} +
+
+ {format_last_seen(@agent_token.updated_at)} +
+
+ +
+
+ Last Seen (Heartbeat) +
+
+ {format_datetime(@agent_token.last_seen_at)} +
+ <%= if @agent_token.last_seen_at do %> +
+ {format_last_seen(@agent_token.last_seen_at)} +
+ <% end %> +
+ + <%= if @agent_token.last_ip do %> +
+
Last IP Address
+
+ {@agent_token.last_ip} +
+
+ <% end %> +
+
+