mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
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:
1 parent
0c4803d717
commit
5bf682502b
68 files changed
+2667
-10
No files matched your search
@@ -0,0 +1,83 @@
|
||||
<% content_for :title, "AirTrail sync" %>
|
||||
<h1 class="mb-1 text-2xl font-bold">AirTrail sync</h1>
|
||||
<p class="mb-5 text-sm text-slate-600">Push the flights you log to your <a href="https://github.com/johanohly/AirTrail" class="link" target="_blank" rel="noopener noreferrer">AirTrail</a> flight map, with GPS tracks.</p>
|
||||
|
||||
<div class="grid gap-5 lg:grid-cols-3">
|
||||
<div class="space-y-5 lg:col-span-2">
|
||||
<%= form_with model: @connection, url: air_trail_connection_path, method: (@connection.persisted? ? :patch : :post), class: "card card-body space-y-4" do |f| %>
|
||||
<h2 class="card-title">Connection</h2>
|
||||
<%= f.errors_summary %>
|
||||
<%= f.field :base_url, label: "AirTrail URL", placeholder: "https://airtrail.example.com", required: true %>
|
||||
<%= f.field :api_key, as: :password, label: "API key", autocomplete: "off",
|
||||
placeholder: (@connection.persisted? ? "•••••••• (leave blank to keep)" : ""),
|
||||
hint: "Create one in AirTrail under Settings → Security → API keys." %>
|
||||
<%= f.field :enabled, as: :checkbox, label: "Sync automatically", hint: "Flights you log, or delete, are pushed to AirTrail in the background." %>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<%= f.submit(@connection.persisted? ? "Save & test" : "Connect") %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @connection.persisted? %>
|
||||
<section class="card">
|
||||
<div class="card-header">
|
||||
<h2 class="card-title">Status</h2>
|
||||
<% if @connection.ok? %><span class="badge-green">Connected as <%= @connection.remote_username %></span><% else %><span class="badge-red">Needs attention</span><% end %>
|
||||
</div>
|
||||
<div class="card-body space-y-3 text-sm">
|
||||
<% if @connection.last_error.present? %><p class="rounded-md bg-red-50 px-3 py-2 text-red-800 ring-1 ring-red-200"><%= @connection.last_error %></p><% end %>
|
||||
<div class="grid grid-cols-3 gap-3 text-center">
|
||||
<div><div class="text-2xl font-semibold"><%= @counts["synced"] %></div><div class="text-xs text-slate-500">synced</div></div>
|
||||
<div><div class="text-2xl font-semibold"><%= @counts["pending"] %></div><div class="text-xs text-slate-500">pending</div></div>
|
||||
<div><div class="text-2xl font-semibold <%= 'text-red-700' if @counts['error'].positive? %>"><%= @counts["error"] %></div><div class="text-xs text-slate-500">failed</div></div>
|
||||
</div>
|
||||
<p class="text-xs text-slate-500">You've logged <%= pluralize(@flight_count, "flight") %>.
|
||||
<%= @connection.backfilled_at ? "Last full sync #{time_ago_in_words(@connection.backfilled_at)} ago." : "Run a full sync to send your existing flights." %></p>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<%= button_to "Sync all my flights now", sync_air_trail_connection_path, class: "btn-primary" %>
|
||||
<%= button_to "Test connection", test_air_trail_connection_path, class: "btn-secondary" %>
|
||||
</div>
|
||||
<p class="hint">A full sync first links flights that are already in AirTrail (e.g. from a file import), so nothing is duplicated, then sends the rest.</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<% if @unresolved.any? %>
|
||||
<section class="card">
|
||||
<div class="card-header"><h2 class="card-title">Airports AirTrail doesn't know</h2></div>
|
||||
<div class="card-body space-y-2">
|
||||
<p class="text-xs text-slate-600">Flights using these codes can't sync yet. Enter the code AirTrail uses for the same airport (e.g. its ICAO or GPS code).</p>
|
||||
<% @unresolved.each do |code| %>
|
||||
<%= form_with url: map_airport_air_trail_connection_path, class: "flex items-center gap-2" do |f| %>
|
||||
<%= hidden_field_tag :code, code %>
|
||||
<span class="w-16 font-mono text-sm"><%= code %></span><span class="text-slate-400">→</span>
|
||||
<%= text_field_tag :airtrail_code, nil, class: "input w-32", placeholder: "AirTrail code", required: true %>
|
||||
<%= f.submit "Map", class: "btn-secondary btn-sm" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</section>
|
||||
<% end %>
|
||||
|
||||
<% if @failed.any? %>
|
||||
<section class="card">
|
||||
<div class="card-header"><h2 class="card-title">Flights that didn't sync</h2></div>
|
||||
<table class="table"><tbody>
|
||||
<% @failed.each do |s| f = s.flight_log %>
|
||||
<tr><td class="whitespace-nowrap"><%= link_to f.date, aircraft_flight_log_path(f.aircraft, f), class: "link" %></td>
|
||||
<td><%= f.route_summary %></td><td class="text-xs text-red-700"><%= s.last_error %></td></tr>
|
||||
<% end %>
|
||||
</tbody></table>
|
||||
</section>
|
||||
<% end %>
|
||||
|
||||
<div><%= delete_button "Disconnect AirTrail", air_trail_connection_path, confirm: "Stop syncing to AirTrail? Flights already there stay." %></div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<section class="card card-body space-y-2 text-sm text-slate-700">
|
||||
<h3 class="font-semibold">Setting up the API key</h3>
|
||||
<p class="text-xs">In AirTrail, open <strong>Settings → Security</strong> and create an API key with these scopes:</p>
|
||||
<ul class="list-disc pl-5 font-mono text-xs"><% AirTrailConnection::REQUIRED_SCOPES.each do |s| %><li><%= s %></li><% end %></ul>
|
||||
<p class="text-xs">The key is stored encrypted. Flights go to the AirTrail account of the pilot who logged them, with you in the pilot seat, the tail number as registration, and the GPS track if one is attached.</p>
|
||||
<p class="text-xs">Each aircraft's <strong>ICAO type</strong> (Edit aircraft) sets the aircraft type in AirTrail.</p>
|
||||
</section>
|
||||
</div>
|
||||
Reference in new issue
Block a user