prop/lib/microwaveprop_web/live/user_management_live/index.ex
Graham McIntire ff950f9e40
docs/tests: moduledocs on 18 LiveViews, MapLive event coverage, Rust pipeline roundtrip
- Add one-line moduledocs to 18 LiveViews that were carrying
  @moduledoc false. Each line names the route and summarizes what
  the page does so a future reader knows where to look before
  opening the file.
- Add MapLive handle_event tests for toggle_radar, select_time /
  set_selected_time, point_detail, map_bounds, retry_initial_scores.
  Assertions focus on socket-state transitions and "didn't crash"
  rather than raw HTML — map_bounds in particular has no visible
  render-side effect (it push_events the new scores to the JS hook).
- Rust pipeline: integration-shaped test that hand-builds a 2-cell
  surface + pressure grid, runs merge → cell_to_conditions →
  precompute_band_invariants → composite_score_with → write_atomic
  → decode, asserting header + body length round-trip. Closes the
  'pipeline's happy path is only covered by unit tests' gap.
2026-04-21 17:16:12 -05:00

103 lines
2.7 KiB
Elixir

defmodule MicrowavepropWeb.UserManagementLive.Index do
@moduledoc "Admin user list at `/admin/users`."
use MicrowavepropWeb, :live_view
use MicrowavepropWeb.LiveTableResource, schema: Microwaveprop.Accounts.User
alias Microwaveprop.Accounts
def table_options do
%{exports: %{formats: [:csv]}}
end
@impl true
def mount(_params, _session, socket) do
{:ok, assign(socket, :page_title, "Users")}
end
def fields do
[
id: %{label: "ID", hidden: true},
callsign: %{label: "Callsign", sortable: true, searchable: true},
name: %{label: "Name", sortable: true, searchable: true},
email: %{label: "Email", sortable: true, searchable: true},
is_admin: %{label: "Admin", sortable: true, renderer: &admin_badge/1},
confirmed_at: %{label: "Confirmed", sortable: true, renderer: &confirmed_cell/1}
]
end
def filters, do: []
def actions do
[
edit: fn %{record: user} ->
assigns = %{user: user}
~H"""
<.link navigate={~p"/users/#{@user.id}/edit"} class="btn btn-xs btn-ghost">Edit</.link>
"""
end,
delete: fn %{record: user} ->
assigns = %{user: user}
~H"""
<.link
phx-click={JS.push("delete", value: %{id: @user.id})}
data-confirm={"Delete user #{@user.callsign}? This cannot be undone."}
class="btn btn-xs btn-ghost text-error"
>
Delete
</.link>
"""
end
]
end
@impl true
def render(assigns) do
~H"""
<Layouts.app flash={@flash} current_scope={@current_scope} max_width="max-w-6xl">
<.header>
Users
<:subtitle>Manage registered accounts and admin flags.</:subtitle>
</.header>
<.live_table
fields={fields()}
filters={filters()}
options={@options}
streams={@streams}
actions={actions()}
/>
</Layouts.app>
"""
end
@impl true
def handle_event("delete", %{"id" => id}, socket) do
user = Accounts.get_user!(id)
if user.id == socket.assigns.current_scope.user.id do
{:noreply, put_flash(socket, :error, "You cannot delete your own account here.")}
else
{:ok, _} = Accounts.delete_user(user)
{:noreply, stream_delete(socket, :resources, user)}
end
end
defp admin_badge(true) do
assigns = %{}
~H|<span class="badge badge-primary badge-sm">admin</span>|
end
defp admin_badge(_), do: Phoenix.HTML.raw("<span class=\"opacity-50\">&mdash;</span>")
defp confirmed_cell(nil) do
assigns = %{}
~H|<span class="opacity-50">pending</span>|
end
defp confirmed_cell(%DateTime{} = dt), do: Calendar.strftime(dt, "%Y-%m-%d")
defp confirmed_cell(_), do: ""
end