diff --git a/lib/towerops_web/components/core_components.ex b/lib/towerops_web/components/core_components.ex index 818b8574..c66324f6 100644 --- a/lib/towerops_web/components/core_components.ex +++ b/lib/towerops_web/components/core_components.ex @@ -777,6 +777,7 @@ defmodule ToweropsWeb.CoreComponents do attr :timezone, :string, default: "UTC", doc: "User's timezone for full timestamp" attr :class, :string, default: "", doc: "Additional CSS classes" attr :format, :string, default: "relative", doc: "Display format: 'relative' or 'absolute'" + attr :now, :any, default: nil, doc: "Current time for live-ticking relative timestamps" def timestamp(assigns) do assigns = diff --git a/lib/towerops_web/live/agent_live/index.ex b/lib/towerops_web/live/agent_live/index.ex index b273058a..5c192765 100644 --- a/lib/towerops_web/live/agent_live/index.ex +++ b/lib/towerops_web/live/agent_live/index.ex @@ -21,6 +21,7 @@ defmodule ToweropsWeb.AgentLive.Index do # Subscribe to agent health updates for real-time status changes if connected?(socket) do _ = Phoenix.PubSub.subscribe(Towerops.PubSub, "agents:health") + :timer.send_interval(1000, :tick) end # If superadmin (including when impersonating), also load cloud pollers and global default @@ -70,6 +71,7 @@ defmodule ToweropsWeb.AgentLive.Index do |> assign(:agent_image, agent_image) |> assign(:new_token, nil) |> assign(:show_token_modal, false) + |> assign(:now, DateTime.utc_now()) |> assign(:agent_form, to_form(%{"name" => "", "is_cloud_poller" => false}))} end @@ -363,6 +365,11 @@ defmodule ToweropsWeb.AgentLive.Index do |> put_flash(:info, message)} end + @impl true + def handle_info(:tick, socket) do + {:noreply, assign(socket, :now, DateTime.utc_now())} + end + # Handle real-time agent status updates # Only process events for this organization's agents, or cloud pollers if superuser @impl true diff --git a/lib/towerops_web/live/agent_live/index.html.heex b/lib/towerops_web/live/agent_live/index.html.heex index a898c583..64335f31 100644 --- a/lib/towerops_web/live/agent_live/index.html.heex +++ b/lib/towerops_web/live/agent_live/index.html.heex @@ -112,7 +112,7 @@ <:col :let={{_id, agent}} label="Last Seen">