diff --git a/lib/towerops_web/helpers/time_helpers.ex b/lib/towerops_web/helpers/time_helpers.ex index 0510c126..c45b2c8c 100644 --- a/lib/towerops_web/helpers/time_helpers.ex +++ b/lib/towerops_web/helpers/time_helpers.ex @@ -181,8 +181,21 @@ defmodule ToweropsWeb.TimeHelpers do end @doc """ - Formats a DateTime into a short date string in UTC. + Formats a DateTime into a short "Mon DD HH:MM" string in the given timezone. """ + @spec format_short_datetime(DateTime.t() | nil, String.t()) :: String.t() + def format_short_datetime(nil, _timezone), do: "—" + + def format_short_datetime(datetime, timezone) do + case to_user_timezone(datetime, timezone || "UTC") do + {:ok, shifted_dt, _tz_abbr} -> + Calendar.strftime(shifted_dt, "%b %d %H:%M") + + {:error, _} -> + Calendar.strftime(datetime, "%b %d %H:%M") + end + end + @spec format_date(DateTime.t() | nil) :: String.t() def format_date(datetime), do: format_date(datetime, "UTC") diff --git a/lib/towerops_web/live/dashboard_live.ex b/lib/towerops_web/live/dashboard_live.ex index 43149a1f..d88a811a 100644 --- a/lib/towerops_web/live/dashboard_live.ex +++ b/lib/towerops_web/live/dashboard_live.ex @@ -27,7 +27,9 @@ defmodule ToweropsWeb.DashboardLive do socket |> assign(:page_title, organization.name) |> assign(:device_count, device_count) - |> assign(:insight_source, nil)} + |> assign(:insight_source, nil) + |> assign(:timezone, socket.assigns.current_scope.timezone) + |> assign(:time_format, socket.assigns.current_scope.time_format)} end @impl true @@ -259,10 +261,6 @@ defmodule ToweropsWeb.DashboardLive do end end - defp site_health_border(:red), do: "border-red-300 bg-red-50/50 dark:border-red-800 dark:bg-red-950/20" - defp site_health_border(:yellow), do: "border-yellow-300 bg-yellow-50/50 dark:border-yellow-800 dark:bg-yellow-950/20" - defp site_health_border(_), do: "border-gray-200 bg-white dark:border-white/10 dark:bg-gray-800/50" - defp site_health_dot(:red), do: "bg-red-500" defp site_health_dot(:yellow), do: "bg-yellow-500" defp site_health_dot(_), do: "bg-green-500" @@ -287,4 +285,8 @@ defmodule ToweropsWeb.DashboardLive do defp format_qoe(nil), do: "—" defp format_qoe(score), do: :erlang.float_to_binary(score / 1, decimals: 1) + + defp format_short_datetime(datetime, timezone) do + ToweropsWeb.TimeHelpers.format_short_datetime(datetime, timezone) + end end diff --git a/lib/towerops_web/live/dashboard_live.html.heex b/lib/towerops_web/live/dashboard_live.html.heex index 134f9356..2764c1ec 100644 --- a/lib/towerops_web/live/dashboard_live.html.heex +++ b/lib/towerops_web/live/dashboard_live.html.heex @@ -14,7 +14,7 @@ <%= if assigns[:last_updated] do %>
- Updated {Calendar.strftime(@last_updated, "%H:%M:%S UTC")} + Updated {ToweropsWeb.TimeHelpers.format_datetime(@last_updated, @timezone, @time_format)}
- {Calendar.strftime(change.changed_at, "%b %d %H:%M")} + {format_short_datetime(change.changed_at, @timezone)} <% end %> @@ -592,48 +592,85 @@ View all → -
- <.link - :for={site <- @site_impact_summaries} - navigate={~p"/sites/#{site.site_id}"} - class={[ - "rounded-lg border px-4 py-3 transition hover:shadow-sm", - site_health_border(site.site_health) - ]} - > -
- - - - {site.name} - -
-
- {site.device_count} devices - <%= if site.devices_down > 0 do %> - {site.devices_down} down - <% end %> - <%= if site.avg_qoe do %> - - QoE {format_qoe(site.avg_qoe)} - - <% end %> - <%= if site.subscribers do %> - {site.subscribers} subs - <% end %> -
- <%= if site.subscribers_affected > 0 do %> -
- {format_number(site.subscribers_affected)} affected - <%= if mrr_at_risk_positive?(site.mrr_at_risk) do %> - · {format_mrr(site.mrr_at_risk)}/mo at risk - <% end %> -
- <% end %> - +
+ + + + + + + + + + + + + + + + + + + +
+ Site + + Devices + + Down + + QoE + + Subscribers +
+ <.link + navigate={~p"/sites/#{site.site_id}"} + class="flex items-center gap-2 text-sm font-medium text-gray-900 hover:text-blue-600 dark:text-white dark:hover:text-blue-400" + > + + + {site.name} + + + {site.device_count} + + <%= if site.devices_down > 0 do %> + {site.devices_down} + <% else %> + 0 + <% end %> + + <%= if site.avg_qoe do %> + "text-red-600 dark:text-red-400" + site.avg_qoe < 4.0 -> "text-yellow-600 dark:text-yellow-400" + true -> "text-green-600 dark:text-green-400" + end + }> + {format_qoe(site.avg_qoe)} + + <% else %> + + <% end %> + + <%= if site.subscribers do %> + {site.subscribers} + <%= if site.subscribers_affected > 0 do %> + + ({format_number(site.subscribers_affected)} affected) + + <% end %> + <% else %> + + <% end %> +
<% end %> @@ -663,7 +700,7 @@ {activity.summary}

- {Calendar.strftime(activity.timestamp, "%b %d %H:%M")} + {format_short_datetime(activity.timestamp, @timezone)}