diff --git a/lib/microwaveprop/radio/adif_import.ex b/lib/microwaveprop/radio/adif_import.ex index d5753c13..dbba9e87 100644 --- a/lib/microwaveprop/radio/adif_import.ex +++ b/lib/microwaveprop/radio/adif_import.ex @@ -213,6 +213,12 @@ defmodule Microwaveprop.Radio.AdifImport do raw when is_binary(raw) -> raw |> String.trim() |> String.upcase() end + # Operator commentary: prefer ADIF (multi-line detailed + # field) over (short one-liner). Whitespace-only values + # collapse to nil so the column reflects "no notes" instead of an + # empty string — mirrors the normalizer on the submission changeset. + notes = adif_notes(fields) + case {band, timestamp} do {nil, _} -> {:invalid, %{row_num: row_num, messages: ["could not determine a valid microwave band"]}} @@ -230,7 +236,8 @@ defmodule Microwaveprop.Radio.AdifImport do "mode" => mode, "qso_timestamp" => DateTime.to_iso8601(dt), "submitter_email" => submitter_email, - "user_declared_prop_mode" => prop_mode + "user_declared_prop_mode" => prop_mode, + "notes" => notes } changeset = Contact.submission_changeset(%Contact{}, attrs) @@ -244,6 +251,20 @@ defmodule Microwaveprop.Radio.AdifImport do end end + defp adif_notes(fields) do + Enum.find_value([fields["NOTES"], fields["COMMENT"]], fn + nil -> nil + value when is_binary(value) -> non_blank_or_nil(value) + end) + end + + defp non_blank_or_nil(value) do + case String.trim(value) do + "" -> nil + _ -> value + end + end + # -- band resolution ------------------------------------------------------- defp resolve_band(fields) do diff --git a/lib/microwaveprop_web/live/submit_live.ex b/lib/microwaveprop_web/live/submit_live.ex index 16c35028..3a4b7694 100644 --- a/lib/microwaveprop_web/live/submit_live.ex +++ b/lib/microwaveprop_web/live/submit_live.ex @@ -565,6 +565,10 @@ defmodule MicrowavepropWeb.SubmitLive do
  • Contacts on amateur bands from 50 MHz and up will be imported
  • HF contacts (below 50 MHz) are silently skipped
  • Frequencies are fuzzy-matched to the nearest amateur band
  • +
  • + Operator commentary from NOTES + is carried over (falling back to COMMENT) +
  • diff --git a/test/microwaveprop/radio/adif_import_test.exs b/test/microwaveprop/radio/adif_import_test.exs index eee37c20..2936ed4c 100644 --- a/test/microwaveprop/radio/adif_import_test.exs +++ b/test/microwaveprop/radio/adif_import_test.exs @@ -66,6 +66,42 @@ defmodule Microwaveprop.Radio.AdifImportTest do assert row.attrs["user_declared_prop_mode"] == nil end + test "captures ADIF NOTES into notes" do + adif = """ + W5XDK5TREM00EM1210368.000CW20260328180000Rare Es along TX/OK front + """ + + assert {:ok, preview} = AdifImport.preview(adif, @submitter) + assert [row] = preview.valid + assert row.attrs["notes"] == "Rare Es along TX/OK front" + end + + test "falls back to ADIF COMMENT when NOTES is absent" do + adif = """ + W5XDK5TREM00EM1210368.000CW20260328180000nice qso!! + """ + + assert {:ok, preview} = AdifImport.preview(adif, @submitter) + assert [row] = preview.valid + assert row.attrs["notes"] == "nice qso!!" + end + + test "prefers NOTES over COMMENT when both are present" do + adif = """ + W5XDK5TREM00EM1210368.000CW20260328180000detailedshort + """ + + assert {:ok, preview} = AdifImport.preview(adif, @submitter) + assert [row] = preview.valid + assert row.attrs["notes"] == "detailed" + end + + test "missing NOTES / COMMENT leaves notes nil" do + assert {:ok, preview} = AdifImport.preview(@valid_adif, @submitter) + [row] = preview.valid + assert row.attrs["notes"] == nil + end + test "parses ADIF with BAND field instead of FREQ" do adif = """ W5XDK5TREM00EM1223cmCW20260328180000