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

+65
View File
@@ -0,0 +1,65 @@
<% content_for :title, "Standardize airport codes" %>
<%= render "shared/aircraft_header", aircraft: @aircraft %>
<% changes = @standardizer.changes %>
<%= form_with url: aircraft_airport_codes_path(@aircraft), method: :patch, class: "space-y-5" do |f| %>
<section class="card">
<div class="card-header">
<h2 class="card-title">Standardize airport codes</h2>
<span class="text-xs text-slate-500"><%= pluralize(changes.size, "code") %> to update · <%= changes.sum(&:flights) %> entries</span>
</div>
<div class="card-body text-sm text-slate-600">
Rewrites the airport codes in <%= @aircraft.tail_number %>'s flight log to the airport database's standard code: the ICAO-style code AirTrail uses (e.g. 1B9 → K1B9). New flights picked from autocomplete already use these codes. Untick anything you'd rather keep as is.
</div>
<% if changes.any? %>
<table class="table">
<thead><tr><th class="w-8"><input type="checkbox" checked aria-label="Select all" onclick="this.closest('table').querySelectorAll('tbody input[type=checkbox]').forEach(c => c.checked = this.checked)"></th><th>Logged</th><th>Standard</th><th>Airport</th><th class="text-right">Entries</th></tr></thead>
<tbody>
<% changes.each do |c| %>
<tr>
<td><%= check_box_tag "codes[]", c.from, c.suggested, id: "code_#{c.from.parameterize}" %></td>
<td class="font-mono"><%= label_tag "code_#{c.from.parameterize}", c.from %></td>
<td class="font-mono font-semibold"><%= c.to %></td>
<td><%= c.airport.name %> <span class="text-xs text-slate-500"><%= c.airport.place %></span>
<% if c.note %><div class="text-xs text-amber-700"><%= c.note %></div><% end %></td>
<td class="text-right tabular-nums"><%= c.flights %></td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<%= empty_state "All logged codes already match the airport database." %>
<% end %>
</section>
<% if @standardizer.unknown.any? %>
<section class="card">
<div class="card-header"><h2 class="card-title">Not in the airport database</h2></div>
<div class="card-body space-y-3 text-sm">
<p class="text-slate-600">Often a typo. Tick “Fix” and choose the airport these entries should be. Unticked codes are left unchanged.<% if current_user.admin? %> For a private strip that isn't listed, add it as a <%= link_to "custom airport", admin_airports_path, class: "link" %>.<% end %></p>
<% @standardizer.unknown.each do |u| %>
<div class="flex flex-wrap items-start gap-3">
<label class="mt-2 flex items-center gap-2"><%= check_box_tag "fix[]", u.code, u.suggestion.present?, id: "fix_#{u.code.parameterize}" %> Fix</label>
<div class="mt-2 w-16 font-mono"><%= u.code %></div>
<div class="mt-2 text-xs text-slate-500"><%= pluralize(u.flights, "entry") %> →</div>
<div class="relative w-72" data-controller="airport-autocomplete"
data-airport-autocomplete-url-value="<%= airport_search_path(aircraft_id: @aircraft.id) %>">
<%= text_field_tag "fixes[#{u.code}]", u.suggestion&.code, class: "input font-mono uppercase placeholder:normal-case placeholder:font-sans",
placeholder: "Airport code or name", "aria-label": "Airport for #{u.code}",
data: { airport_autocomplete_target: "input",
action: "input->airport-autocomplete#search keydown->airport-autocomplete#keydown blur->airport-autocomplete#blur" } %>
<ul data-airport-autocomplete-target="list" role="listbox" hidden
class="absolute z-20 mt-1 max-h-72 w-[min(28rem,90vw)] overflow-auto rounded-md bg-white py-1 shadow-lg ring-1 ring-slate-200"></ul>
<p class="hint min-h-4" data-airport-autocomplete-target="hint"></p>
</div>
<% if u.suggestion %><div class="mt-2 text-xs text-sky-800">Suggested: <%= u.suggestion.name %>, <%= u.suggestion.place %> (letters swapped?)</div><% end %>
</div>
<% end %>
</div>
</section>
<% end %>
<div class="flex gap-2">
<% if changes.any? || @standardizer.unknown.any? %><%= f.submit "Update selected codes", class: "btn-primary", data: { turbo_confirm: "Rewrite the selected airport codes in #{@aircraft.tail_number}'s flight log?" } %><% end %>
<%= link_to "Back to flights", aircraft_flight_logs_path(@aircraft), class: "btn-secondary" %>
</div>
<% end %>