<% content_for :title, "AirTrail sync" %>

AirTrail sync

Push the flights you log to your AirTrail flight map, with GPS tracks.

<%= form_with model: @connection, url: air_trail_connection_path, method: (@connection.persisted? ? :patch : :post), class: "card card-body space-y-4" do |f| %>

Connection

<%= 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." %>
<%= f.submit(@connection.persisted? ? "Save & test" : "Connect") %>
<% end %> <% if @connection.persisted? %>

Status

<% if @connection.ok? %>Connected as <%= @connection.remote_username %><% else %>Needs attention<% end %>
<% if @connection.last_error.present? %>

<%= @connection.last_error %>

<% end %>
<%= @counts["synced"] %>
synced
<%= @counts["pending"] %>
pending
<%= @counts["error"] %>
failed

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." %>

<%= 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" %>

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.

<% if @unresolved.any? %>

Airports AirTrail doesn't know

Flights using these codes can't sync yet. Enter the code AirTrail uses for the same airport (e.g. its ICAO or GPS code).

<% @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 %> <%= code %>→ <%= 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 %>
<% end %> <% if @failed.any? %>

Flights that didn't sync

<% @failed.each do |s| f = s.flight_log %> <% end %>
<%= link_to fmt_date(f.date), aircraft_flight_log_path(f.aircraft, f), class: "link" %> <%= f.route_summary %><%= s.last_error %>
<% end %>
<%= delete_button "Disconnect AirTrail", air_trail_connection_path, confirm: "Stop syncing to AirTrail? Flights already there stay." %>
<% end %>

Setting up the API key

In AirTrail, open Settings → Security and create an API key with these scopes:

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.

Each aircraft's ICAO type (Edit aircraft) sets the aircraft type in AirTrail.