Show submitter callsign on the contacts index
When a contact is linked to a logged-in user account, display that user's callsign in the Submitted column instead of a generic "Yes". Anonymous submissions still show "Yes"; scraped contacts show an em dash.
This commit is contained in:
parent
a3f729962f
commit
a40ea0d62d
4 changed files with 40 additions and 4 deletions
|
|
@ -28,6 +28,7 @@ defmodule Microwaveprop.Radio do
|
|||
|> limit(^@per_page)
|
||||
|> offset(^offset)
|
||||
|> Repo.all()
|
||||
|> Repo.preload(:user)
|
||||
|
||||
%{
|
||||
entries: entries,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ defmodule Microwaveprop.Radio.Contact do
|
|||
|
||||
import Ecto.Changeset
|
||||
|
||||
alias Microwaveprop.Accounts.User
|
||||
alias Microwaveprop.Radio.Maidenhead
|
||||
|
||||
@primary_key {:id, :binary_id, autogenerate: true}
|
||||
|
|
@ -39,9 +40,10 @@ defmodule Microwaveprop.Radio.Contact do
|
|||
|
||||
field :user_submitted, :boolean, default: false
|
||||
field :submitter_email, :string
|
||||
field :user_id, :binary_id
|
||||
field :flagged_invalid, :boolean, default: false
|
||||
|
||||
belongs_to :user, User
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -80,6 +80,10 @@ defmodule MicrowavepropWeb.ContactLive.Index do
|
|||
]
|
||||
@done_statuses [:complete, :unavailable]
|
||||
|
||||
defp submitted_cell(%{user: %{callsign: callsign}}) when is_binary(callsign), do: callsign
|
||||
defp submitted_cell(%{user_submitted: true}), do: "Yes"
|
||||
defp submitted_cell(_), do: "—"
|
||||
|
||||
defp enrichment_badge(contact) do
|
||||
details =
|
||||
Enum.map(@enrichment_fields, fn {field, name} ->
|
||||
|
|
@ -183,7 +187,7 @@ defmodule MicrowavepropWeb.ContactLive.Index do
|
|||
<td>{primary.band}</td>
|
||||
<td>{primary.mode}</td>
|
||||
<td>{primary.distance_km}</td>
|
||||
<td>{if primary.user_submitted, do: "Yes", else: "—"}</td>
|
||||
<td>{submitted_cell(primary)}</td>
|
||||
<td>{enrichment_badge(primary)}</td>
|
||||
<td class="text-center">{if primary.flagged_invalid, do: "🚩"}</td>
|
||||
<td>{Calendar.strftime(primary.qso_timestamp, "%Y-%m-%d %H:%M")}</td>
|
||||
|
|
@ -202,7 +206,7 @@ defmodule MicrowavepropWeb.ContactLive.Index do
|
|||
<td>{recip.band}</td>
|
||||
<td>{recip.mode}</td>
|
||||
<td>{recip.distance_km}</td>
|
||||
<td>{if recip.user_submitted, do: "Yes", else: "—"}</td>
|
||||
<td>{submitted_cell(recip)}</td>
|
||||
<td>{enrichment_badge(recip)}</td>
|
||||
<td class="text-center">{if recip.flagged_invalid, do: "🚩"}</td>
|
||||
<td>{Calendar.strftime(recip.qso_timestamp, "%Y-%m-%d %H:%M")}</td>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
defmodule MicrowavepropWeb.ContactLiveTest do
|
||||
use MicrowavepropWeb.ConnCase, async: true
|
||||
|
||||
import Microwaveprop.AccountsFixtures
|
||||
import Phoenix.LiveViewTest
|
||||
|
||||
alias Microwaveprop.Radio.Contact
|
||||
|
|
@ -36,9 +37,12 @@ defmodule MicrowavepropWeb.ContactLiveTest do
|
|||
distance_km: Decimal.new("295")
|
||||
}
|
||||
|
||||
{changeset_attrs, direct_attrs} = Map.split(Map.merge(default, attrs), [:user_submitted])
|
||||
|
||||
{:ok, contact} =
|
||||
%Contact{}
|
||||
|> Contact.changeset(Map.merge(default, attrs))
|
||||
|> Contact.changeset(direct_attrs)
|
||||
|> Ecto.Changeset.change(changeset_attrs)
|
||||
|> Repo.insert()
|
||||
|
||||
contact
|
||||
|
|
@ -112,6 +116,31 @@ defmodule MicrowavepropWeb.ContactLiveTest do
|
|||
{:ok, _lv, html2} = live(conn, ~p"/contacts?page=2")
|
||||
assert html2 =~ "Page 2 of 2"
|
||||
end
|
||||
|
||||
test "Submitted column shows the user's callsign when linked to an account", %{conn: conn} do
|
||||
user = user_fixture(%{callsign: "W5UNIQ"})
|
||||
create_contact(%{station1: "K5ONE", user_submitted: true, user_id: user.id})
|
||||
|
||||
{:ok, _lv, html} = live(conn, ~p"/contacts?search=K5ONE")
|
||||
assert html =~ "W5UNIQ"
|
||||
end
|
||||
|
||||
test "Submitted column shows 'Yes' when user_submitted but no user linked", %{conn: conn} do
|
||||
create_contact(%{station1: "K5ANON", user_submitted: true, user_id: nil})
|
||||
|
||||
{:ok, _lv, html} = live(conn, ~p"/contacts?search=K5ANON")
|
||||
# Locate the row containing our station and assert "Yes" appears in it
|
||||
[row] = Regex.run(~r/<tr[^>]*>(?:(?!<\/tr>).)*K5ANON(?:(?!<\/tr>).)*<\/tr>/s, html) || [""]
|
||||
assert row =~ ">Yes<"
|
||||
end
|
||||
|
||||
test "Submitted column shows dash for scraped contacts", %{conn: conn} do
|
||||
create_contact(%{station1: "K5SCRAPE", user_submitted: false})
|
||||
|
||||
{:ok, _lv, html} = live(conn, ~p"/contacts?search=K5SCRAPE")
|
||||
[row] = Regex.run(~r/<tr[^>]*>(?:(?!<\/tr>).)*K5SCRAPE(?:(?!<\/tr>).)*<\/tr>/s, html) || [""]
|
||||
refute row =~ ">Yes<"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue