AirTrail sync and export, GPS tracks, airport database with autocomplete

AirTrail (https://github.com/johanohly/AirTrail):
- File export (Flights → Export for AirTrail) in AirTrail's import
  format, validated against its schema; same-day repeat legs get leg
  numbers so AirTrail's de-duplication doesn't merge them.
- Automatic sync through AirTrail's REST API (Profile → AirTrail sync):
  per-user connection with an encrypted API key and scope check; flights
  are created/updated/deleted in background jobs; a full sync first
  links flights already in AirTrail (e.g. from a file import) instead of
  duplicating them; airports are resolved and cached, with manual
  mapping for unknown codes.
- GPS tracks: GPX, KML and CSV track logs are converted to AirTrail's
  track format for both sync and export; the flight page shows a summary.
- Aircraft ICAO type (e.g. C150) for AirTrail's aircraft type.

Airport database (OurAirports, the source AirTrail uses):
- Managed like AirTrail: downloaded in the background on first start,
  updated in place from Admin → Airports (adds, changes, removes; ids
  stable), with admin-managed custom airports that updates never touch.
- Each airport carries AirTrail's code, so logged codes translate to
  AirTrail's exactly (1B9 → K1B9, 4MB → K5M3).
- From/To autocomplete on new flights (airports this aircraft has used
  rank first); From is pre-filled with the last flight's destination;
  codes are normalized to uppercase.
- Flights → Standardize airport codes: rewrite logged codes to the
  standard code, and fix codes not in the database (typos such as 0R8 →
  08R are suggested).

Also: admin pages grouped under an Admin dropdown menu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-05 19:40:20 -05:00
1 parent 0c4803d717
commit 5bf682502b
68 files changed
+2667 -10

No files matched your search

+32
View File
@@ -82,6 +82,38 @@ class PagesTest < ActionDispatch::IntegrationTest
assert_select "a[href='https://drs.faa.gov/browse/excelExternalWindow/ABC.0001']", minimum: 2 # status + history
end
test "new flight pre-fills From with the last flight's destination and offers airport search" do
@a.flight_logs.create!(date: Date.current - 1, tach_time: 1.0, departure_location: "KOQU", destination_location: "kbid")
get new_aircraft_flight_log_path(@a)
assert_select "input[name='flight_log[departure_location]'][value='KBID']"
assert_select "div[data-controller='airport-autocomplete'][data-airport-autocomplete-url-value='#{airport_search_path(aircraft_id: @a.id)}']", count: 2
AirportData.sync!(StringIO.new("ident,type,name,latitude_deg,longitude_deg,elevation_ft,iso_country,iso_region,municipality,gps_code,iata_code,local_code\nKBID,small_airport,Block Island State Airport,41.1,-71.5,108,US,US-RI,Block Island,KBID,BID,BID\n88LL,small_airport,Block Airport,41.9,-89.1,800,US,US-IL,Pearl City,88LL,,88LL\n"))
get airport_search_path(q: "block", aircraft_id: @a.id)
assert_equal %w[KBID 88LL], response.parsed_body.map { _1["code"] } # flown-to airport first
end
test "owner standardizes airport codes from the Flights tab" do
AirportData.sync!(StringIO.new("ident,type,name,latitude_deg,longitude_deg,elevation_ft,iso_country,iso_region,municipality,gps_code,iata_code,local_code\nK1B9,small_airport,Mansfield Municipal Airport,42,-71,122,US,US-MA,Mansfield,1B9,,1B9\n"))
@a.flight_logs.create!(date: Date.current, tach_time: 1, departure_location: "1B9", destination_location: "1B9")
get aircraft_flight_logs_path(@a)
assert_select "a[href='#{aircraft_airport_codes_path(@a)}']"
get aircraft_airport_codes_path(@a)
assert_select "input[name='codes[]'][value='1B9'][checked]"
patch aircraft_airport_codes_path(@a), params: { codes: [ "1B9" ] }
assert_redirected_to aircraft_flight_logs_path(@a)
assert_equal [ "K1B9", "K1B9" ], @a.flight_logs.last.slice(:departure_location, :destination_location).values
# a typo'd code: suggestion pre-filled, fixed only when ticked
@a.flight_logs.create!(date: Date.current, tach_time: 1, departure_location: "K1B9", destination_location: "1K9B")
get aircraft_airport_codes_path(@a)
assert_select "input[name='fixes[1K9B]']"
patch aircraft_airport_codes_path(@a), params: { fixes: { "1K9B" => "1B9" } } # not ticked
assert_equal "1K9B", @a.flight_logs.last.destination_location
patch aircraft_airport_codes_path(@a), params: { fix: [ "1K9B" ], fixes: { "1K9B" => "1B9" } }
assert_equal "K1B9", @a.flight_logs.last.destination_location
end
test "flights tab shows flying stats" do
get aircraft_flight_logs_path(@a)
assert_select "h2", text: "Flight hours by month"