diff --git a/lib/microwaveprop_web/live/rover_planning_live.ex b/lib/microwaveprop_web/live/rover_planning_live.ex index d55e39b7..66b2f386 100644 --- a/lib/microwaveprop_web/live/rover_planning_live.ex +++ b/lib/microwaveprop_web/live/rover_planning_live.ex @@ -8,6 +8,7 @@ defmodule MicrowavepropWeb.RoverPlanningLive do alias Microwaveprop.Accounts.User alias Microwaveprop.RoverPlanning + alias Microwaveprop.RoverPlanning.Mission def table_options do %{sorting: %{default_sort: [inserted_at: :desc]}} @@ -18,7 +19,7 @@ defmodule MicrowavepropWeb.RoverPlanningLive do id: %{label: "ID", hidden: true}, user_id: %{label: "Owner", hidden: true}, name: %{label: "Mission", sortable: true, searchable: true, renderer: &name_cell/2}, - band_mhz: %{label: "Band", sortable: true, renderer: &band_cell/1}, + band_mhz: %{label: "Bands", sortable: true, renderer: &bands_cell/2}, only_known_good: %{label: "Scope", sortable: true, renderer: &scope_cell/1}, inserted_at: %{label: "Created", sortable: true, renderer: &format_ts/1} ] @@ -136,18 +137,26 @@ defmodule MicrowavepropWeb.RoverPlanningLive do """ end - defp band_cell(nil), do: "โ€”" - - defp band_cell(mhz) when is_integer(mhz) do - if mhz >= 1000 do - ghz = mhz / 1000 - label = if ghz == trunc(ghz), do: "#{trunc(ghz)}", else: Float.to_string(Float.round(ghz, 1)) - "#{label} GHz" - else - "#{mhz} MHz" + # Renders the full bands list (multi-band missions can have several; + # the bound column is `band_mhz` so the table can still sort by the + # primary band, but the cell shows every band the matrix scores). + defp bands_cell(_value, record) do + case Mission.bands(struct(Mission, Map.take(record, [:band_mhz, :bands_mhz]))) do + [] -> "โ€”" + [single] -> band_label(single) + list -> Enum.map_join(list, " ยท ", &band_label/1) end end + defp band_label(mhz) when is_integer(mhz) and mhz >= 1000 do + ghz = mhz / 1000 + label = if ghz == trunc(ghz), do: "#{trunc(ghz)}", else: Float.to_string(Float.round(ghz, 1)) + "#{label} GHz" + end + + defp band_label(mhz) when is_integer(mhz), do: "#{mhz} MHz" + defp band_label(_), do: "โ€”" + defp scope_cell(true) do assigns = %{} ~H|Known good only|