diff --git a/lib/towerops_web/live/device_live/index.html.heex b/lib/towerops_web/live/device_live/index.html.heex index 63d5eea6..4b293c03 100644 --- a/lib/towerops_web/live/device_live/index.html.heex +++ b/lib/towerops_web/live/device_live/index.html.heex @@ -3,9 +3,9 @@ current_scope={@current_scope} active_page="devices" > - <%!-- Compact header --%> -
-
+ <%!-- Header: title + tabs + actions in one row --%> +
+

{@page_title}

<% percent = if @device_quota.limit != :unlimited and @device_quota.limit > 0 do @@ -40,6 +40,41 @@ {@device_quota.current}/{@device_quota.limit} <% end %> + <%!-- Inline tab switcher --%> +
@@ -85,43 +120,6 @@
- <%!-- Tab Navigation --%> -
- -
- <%= case @active_tab do %> <% "existing" -> %> <%= if @sites_enabled && !@has_sites && @has_devices do %> diff --git a/lib/towerops_web/live/device_live/show.ex b/lib/towerops_web/live/device_live/show.ex index af6c6c04..9a484aa8 100644 --- a/lib/towerops_web/live/device_live/show.ex +++ b/lib/towerops_web/live/device_live/show.ex @@ -265,6 +265,7 @@ defmodule ToweropsWeb.DeviceLive.Show do |> assign_checks_data(device_id) |> assign_preseem_data() |> assign_gaiia_data() + |> assign_subscriber_impact() end # -- Selective reload helpers (used by handle_info handlers) -- @@ -532,6 +533,20 @@ defmodule ToweropsWeb.DeviceLive.Show do |> assign(:gaiia_network_site, gaiia_network_site) end + # Subscriber impact data (from Gaiia device-to-subscriber matching). + defp assign_subscriber_impact(socket) do + device = socket.assigns.device + + impact = + try do + Gaiia.get_device_impact(device.id) + rescue + _ -> %{subscriber_count: 0, mrr: nil, accounts: []} + end + + assign(socket, :subscriber_impact, impact) + end + # Preseem tab data. defp assign_preseem_data(socket) do device = socket.assigns.device @@ -1622,6 +1637,15 @@ defmodule ToweropsWeb.DeviceLive.Show do TimeHelpers.format_time_ago(datetime) end + defp format_mrr(nil), do: "$0" + + defp format_mrr(%Decimal{} = d) do + "$#{Decimal.round(d, 2) |> Decimal.to_string(:normal)}" + end + + defp format_mrr(n) when is_number(n), do: "$#{:erlang.float_to_binary(n / 1, decimals: 2)}" + defp format_mrr(_), do: "$0" + defp config_change_dot_color(event) do cond do event.change_size > 50 -> "bg-red-500" diff --git a/lib/towerops_web/live/device_live/show.html.heex b/lib/towerops_web/live/device_live/show.html.heex index 7d932541..2425e16f 100644 --- a/lib/towerops_web/live/device_live/show.html.heex +++ b/lib/towerops_web/live/device_live/show.html.heex @@ -98,6 +98,28 @@
+ + <%= if @subscriber_impact && @subscriber_impact.subscriber_count > 0 do %> +
+
+
+ <.icon name="hero-users" class="h-5 w-5 text-indigo-600 dark:text-indigo-400" /> + + {@subscriber_impact.subscriber_count} {if @subscriber_impact.subscriber_count == 1, do: "subscriber", else: "subscribers"} + +
+ <%= if @can_view_financials && @subscriber_impact.mrr do %> +
+ <.icon name="hero-currency-dollar" class="h-5 w-5 text-indigo-600 dark:text-indigo-400" /> + + {format_mrr(@subscriber_impact.mrr)}/mo + +
+ <% end %> +
+
+ <% end %> +
<% end %> + <%!-- Subscriber Impact Breakdown by Device --%> + <%= if @site_impact && @site_impact.subscriber_count > 0 do %> +
+
+
+

+ <.icon name="hero-users" class="h-4 w-4" /> {t("Subscriber Impact")} +

+
+ {format_number(@site_impact.subscriber_count)} subscribers + <%= if @can_view_financials && @site_impact.mrr do %> + {format_mrr(@site_impact.mrr)}/mo + <% end %> +
+
+
+ <%= if @site_impact.devices != [] do %> +
+ + + + + + <%= if @can_view_financials do %> + + <% end %> + + + + <%= for dev <- @site_impact.devices do %> + + + + <%= if @can_view_financials do %> + + <% end %> + + <% end %> + +
{t("Device")}{t("Subscribers")}{t("MRR")}
+ {dev.name || dev.device_id} + + {dev.count} + + {format_mrr(dev.mrr)} +
+
+ <% end %> +
+ <% end %> +
<%!-- Left Column --%>