diff --git a/lib/dotcom_web/components/system_status/widget.ex b/lib/dotcom_web/components/system_status/widget.ex new file mode 100644 index 0000000000..223eebfb80 --- /dev/null +++ b/lib/dotcom_web/components/system_status/widget.ex @@ -0,0 +1,74 @@ +defmodule DotcomWeb.SystemStatus.Widget do + @moduledoc """ + + A component that renders the given `@statuses` in a table. + + """ + + use DotcomWeb, :component + + @route_ids ["Red", "Orange", "Green", "Blue"] + + def system_status_widget(assigns) do + assigns = assigns |> assign(:route_ids, @route_ids) + + ~H""" +
+ <.line_status + :for={route_id <- @route_ids} + route_id={route_id} + branches_with_statuses={@routes_with_statuses |> Map.get(route_id)} + /> +
+ """ + end + + defp line_status(assigns) do + ~H""" +
+ <.branch_status + :for={branch <- @branches_with_statuses} + route_id={@route_id} + branch_ids={branch.branch_ids} + status_entries={branch.status_entries} + /> +
+ """ + end + + defp branch_status(assigns) do + ~H""" +
+ + {@route_id}{" "}{branch_id}: + + +
+
+ {prefix(status)}: + {description(status)} +
+
+
+ """ + end + + defp description(%{status: :normal}), do: "Normal Service" + defp description(%{status: :delay}), do: "Delays" + defp description(%{status: :shuttle}), do: "Shuttle Buses" + defp description(%{status: :station_closure, multiple: false}), do: "Station Closure" + defp description(%{status: :station_closure, multiple: true}), do: "Station Closures" + defp description(%{status: :suspension, multiple: false}), do: "Suspension" + defp description(%{status: :suspension, multiple: true}), do: "Suspensions" + defp description(status_entry), do: status_entry.status + + defp show_prefix?(status_entries) do + status_entries |> Enum.any?(&future?/1) + end + + defp future?(%{time: {:future, _}}), do: true + defp future?(_), do: false + + defp prefix(%{time: :current}), do: "Now" + defp prefix(%{time: {:future, time}}), do: Util.kitchen_downcase_time(time) +end diff --git a/lib/dotcom_web/live/system_status.ex b/lib/dotcom_web/live/system_status.ex index 1bfb55859c..d2a4570bea 100644 --- a/lib/dotcom_web/live/system_status.ex +++ b/lib/dotcom_web/live/system_status.ex @@ -6,6 +6,8 @@ defmodule DotcomWeb.Live.SystemStatus do use DotcomWeb, :live_view + import DotcomWeb.SystemStatus.Widget + alias Dotcom.SystemStatus def render(assigns) do @@ -18,11 +20,15 @@ defmodule DotcomWeb.Live.SystemStatus do |> assign(:alerts, alerts) |> assign(:statuses, statuses) + Widget + ~H"""

System Status

-
- <.status :for={status <- @statuses} status={status} /> -
+ <.system_status_widget routes_with_statuses={@statuses} /> + +

Examples

+ <.system_status_widget routes_with_statuses={fake_statuses_1()} /> +

Alerts

<.alert :for={alert <- @alerts} alert={alert} /> @@ -30,12 +36,6 @@ defmodule DotcomWeb.Live.SystemStatus do """ end - defp status(assigns) do - ~H""" -
{inspect @status, pretty: true}
- """ - end - defp alert(assigns) do ~H"""
@@ -49,4 +49,54 @@ defmodule DotcomWeb.Live.SystemStatus do
""" end + + defp fake_statuses_1() do + %{ + "Blue" => [ + %{ + branch_ids: [], + status_entries: [%{time: :current, status: :normal, multiple: false}] + } + ], + "Orange" => [ + %{ + branch_ids: [], + status_entries: [ + %{time: :current, status: :delay, multiple: false}, + %{ + time: {:future, Timex.now() |> Timex.set(hour: 20, minute: 30)}, + status: :shuttle, + multiple: false + } + ] + } + ], + "Red" => [ + %{ + branch_ids: [], + status_entries: [%{time: :current, status: :normal, multiple: false}] + }, + %{ + branch_ids: ["Mattapan"], + status_entries: [%{time: :current, status: :suspension, multiple: false}] + } + ], + "Green" => [ + %{ + branch_ids: ["Green-D", "Green-E"], + status_entries: [ + %{ + time: {:future, Timex.now() |> Timex.set(hour: 18, minute: 0)}, + status: :station_closure, + multiple: true + } + ] + }, + %{ + branch_ids: ["Green-B", "Green-C"], + status_entries: [%{time: :current, status: :normal, multiple: false}] + } + ] + } + end end