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

@@ -0,0 +1,31 @@
require "test_helper"
class AirTrailExportFlowTest < ActionDispatch::IntegrationTest
setup do
@pilot = create_user("ricky@example.com")
@a = create_aircraft(pilot: @pilot, owner: create_user, tail_number: "N12345")
@a.flight_logs.create!(date: Date.current, departure_location: "KOQU", destination_location: "KBID", tach_time: 0.5)
sign_in @pilot
end
test "pilot downloads the AirTrail file" do
get aircraft_flight_logs_path(@a)
assert_select "a[href='#{new_aircraft_air_trail_export_path(@a)}']", text: "Export for AirTrail"
get new_aircraft_air_trail_export_path(@a)
assert_response :success
assert_select "input[name='username'][value='ricky']"
assert_select "form[data-turbo='false']"
post aircraft_air_trail_export_path(@a), params: { username: "ricky", aircraft_type: "C150", scope: "all" }
assert_response :success
assert_equal "application/json", response.media_type
assert_match(/attachment; filename="n12345-airtrail-.*\.json"/, response.headers["Content-Disposition"])
assert_equal "KBID", JSON.parse(response.body)["flights"].first["to"]["code"]
end
test "invalid username re-renders the form" do
post aircraft_air_trail_export_path(@a), params: { username: "x" }
assert_response :unprocessable_entity
assert_match "3–20 letters", response.body
end
end