Support two-callsign search on contacts page to find contacts between a pair
This commit is contained in:
parent
f411045242
commit
4759c65809
3 changed files with 39 additions and 3 deletions
|
|
@ -82,9 +82,24 @@ defmodule Microwaveprop.Radio do
|
|||
defp maybe_search(query, ""), do: query
|
||||
|
||||
defp maybe_search(query, search) do
|
||||
pattern = "%" <> String.upcase(search) <> "%"
|
||||
terms = search |> String.split() |> Enum.map(&String.trim/1) |> Enum.reject(&(&1 == ""))
|
||||
|
||||
where(query, [q], ilike(q.station1, ^pattern) or ilike(q.station2, ^pattern))
|
||||
case terms do
|
||||
[a, b] ->
|
||||
pa = "%" <> String.upcase(a) <> "%"
|
||||
pb = "%" <> String.upcase(b) <> "%"
|
||||
|
||||
where(
|
||||
query,
|
||||
[q],
|
||||
(ilike(q.station1, ^pa) and ilike(q.station2, ^pb)) or
|
||||
(ilike(q.station1, ^pb) and ilike(q.station2, ^pa))
|
||||
)
|
||||
|
||||
_ ->
|
||||
pattern = "%" <> String.upcase(search) <> "%"
|
||||
where(query, [q], ilike(q.station1, ^pattern) or ilike(q.station2, ^pattern))
|
||||
end
|
||||
end
|
||||
|
||||
defp sort_opts(opts) do
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ defmodule MicrowavepropWeb.ContactLive.Index do
|
|||
<input
|
||||
name="search"
|
||||
value={@search}
|
||||
placeholder="Search by callsign..."
|
||||
placeholder="Search callsign or pair (e.g. W5LUA W5HN)..."
|
||||
type="text"
|
||||
class="input input-bordered input-sm w-64"
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -79,6 +79,27 @@ defmodule MicrowavepropWeb.ContactLiveTest do
|
|||
assert aa_pos < zz_pos
|
||||
end
|
||||
|
||||
test "search by single callsign matches either station", %{conn: conn} do
|
||||
create_contact(%{station1: "W5LUA", station2: "W5HN"})
|
||||
create_contact(%{station1: "K5TR", station2: "N5AC"})
|
||||
|
||||
{:ok, _lv, html} = live(conn, ~p"/contacts?search=W5LUA")
|
||||
assert html =~ "W5LUA"
|
||||
refute html =~ "K5TR"
|
||||
end
|
||||
|
||||
test "search by two callsigns finds contacts between that pair", %{conn: conn} do
|
||||
create_contact(%{station1: "W5LUA", station2: "W5HN"})
|
||||
create_contact(%{station1: "W5HN", station2: "W5LUA"})
|
||||
create_contact(%{station1: "W5LUA", station2: "K5TR"})
|
||||
|
||||
{:ok, _lv, html} = live(conn, ~p"/contacts?search=W5LUA+W5HN")
|
||||
assert html =~ "W5LUA"
|
||||
assert html =~ "W5HN"
|
||||
# The W5LUA-K5TR contact should not appear
|
||||
refute html =~ "K5TR"
|
||||
end
|
||||
|
||||
test "pagination works", %{conn: conn} do
|
||||
for i <- 1..25 do
|
||||
ts = DateTime.add(~U[2026-01-01 00:00:00Z], i * 3600, :second)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue