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

+16
View File
@@ -0,0 +1,16 @@
<%= form_with model: [:admin, airport], class: "card card-body space-y-4 max-w-2xl" do |f| %>
<%= f.errors_summary %>
<div class="grid gap-4 sm:grid-cols-3">
<%= f.field :ident, label: "Code", required: true, hint: "The code you log, e.g. 0R8." %>
<%= f.field :name, required: true, wrapper: { class: "sm:col-span-2" } %>
<%= f.field :kind, as: :select, label: "Type", collection: Airport::KINDS.map { [_1.humanize, _1] } %>
<%= f.field :municipality, label: "Town" %>
<%= f.field :region, placeholder: "US-RI", hint: "ISO region" %>
<%= f.field :latitude, as: :number, step: "any" %>
<%= f.field :longitude, as: :number, step: "any" %>
<%= f.field :elevation_ft, as: :number, label: "Elevation (ft)" %>
</div>
<p class="hint">Custom airports are kept when the database is updated from OurAirports. To sync flights at this airport to AirTrail, add it there too with the same code (or map it on your AirTrail sync page).</p>
<div class="flex gap-2"><%= f.submit "Save" %><%= link_to "Cancel", admin_airports_path, class: "btn-secondary" %></div>
<% end %>
<% if airport.persisted? %><div class="mt-4"><%= delete_button "Remove #{airport.ident}", admin_airport_path(airport) %></div><% end %>
+2
View File
@@ -0,0 +1,2 @@
<h1 class="mb-4 text-2xl font-bold">Edit <%= @airport.ident %></h1>
<%= render "form", airport: @airport %>
+87
View File
@@ -0,0 +1,87 @@
<% content_for :title, "Airports" %>
<div class="mb-4 flex items-center justify-between">
<h1 class="text-2xl font-bold">Airports</h1>
<%= link_to "+ Custom Airport", new_admin_airport_path, class: "btn-primary" %>
</div>
<div class="grid gap-5 lg:grid-cols-3">
<section class="card lg:col-span-2">
<div class="card-header">
<h2 class="card-title">Airport database</h2>
<% if @running %>
<span class="badge-blue">Updating…</span>
<% else %>
<%= button_to "Update from OurAirports", refresh_admin_airports_path, class: "btn-secondary",
form: { data: { turbo_confirm: "Download the latest airport data from OurAirports? Custom airports are kept." } } %>
<% end %>
</div>
<div class="card-body space-y-3 text-sm">
<div class="grid grid-cols-3 gap-3 text-center">
<div><div class="text-2xl font-semibold"><%= number_with_delimiter(@total) %></div><div class="text-xs text-slate-500">airports</div></div>
<div><div class="text-2xl font-semibold"><%= @custom.size %></div><div class="text-xs text-slate-500">custom</div></div>
<div><div class="text-sm font-semibold"><%= @last_success ? "#{time_ago_in_words(@last_success.finished_at)} ago" : "never" %></div><div class="text-xs text-slate-500">last updated</div></div>
</div>
<% if @total.zero? %>
<p class="rounded-md bg-amber-50 px-3 py-2 text-amber-900 ring-1 ring-amber-200">No airport data yet. It downloads automatically when the app starts. Use “Update from OurAirports” if that didn't happen.</p>
<% end %>
<p class="hint">Airport data comes from <a href="https://ourairports.com/data/" class="link" target="_blank" rel="noopener noreferrer">OurAirports</a> (public domain), the same source AirTrail uses. It's used for From/To autocomplete and to match airport codes when syncing to AirTrail. Updates add new airports, apply changes and remove closed-out entries; custom airports are never changed.</p>
<% if @updates.any? %>
<table class="table">
<thead><tr><th>Started</th><th>By</th><th>Status</th><th>Result</th></tr></thead>
<tbody>
<% @updates.each do |u| %>
<tr>
<td class="whitespace-nowrap text-xs"><%= l(u.created_at, format: :short) %></td>
<td class="text-xs"><%= u.requested_by&.display_name || "Startup" %></td>
<td><%= tag.span u.status.capitalize, class: { "done" => "badge-green", "failed" => "badge-red" }.fetch(u.status, "badge-blue") %></td>
<td class="text-xs"><%= u.done? ? u.summary : u.error %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>
</section>
<section class="card">
<div class="card-header"><h2 class="card-title">Look up</h2></div>
<div class="card-body space-y-2">
<%= form_with url: admin_airports_path, method: :get, class: "flex gap-2" do |f| %>
<%= f.search_field :q, value: @query, class: "input", placeholder: "Code or name" %>
<%= f.submit "Search", class: "btn-secondary" %>
<% end %>
<% if @query.present? %>
<% if @results.any? %>
<ul class="divide-y divide-slate-100 text-sm">
<% @results.each do |a| %>
<li class="py-1.5"><span class="font-mono font-semibold"><%= a.code %></span> <%= a.name %>
<div class="text-xs text-slate-500"><%= [a.place, "AirTrail #{a.airtrail_code}", (a.custom? ? "custom" : nil), Airport::KIND_LABELS[a.kind]].compact_blank.join(" · ") %></div></li>
<% end %>
</ul>
<% else %>
<p class="text-sm text-slate-600">No match for “<%= @query %>”. <%= link_to "Add it as a custom airport", new_admin_airport_path(ident: @query.upcase), class: "link" %>.</p>
<% end %>
<% end %>
</div>
</section>
</div>
<section class="card mt-5">
<div class="card-header"><h2 class="card-title">Custom airports</h2></div>
<% if @custom.any? %>
<table class="table">
<thead><tr><th>Code</th><th>Name</th><th>Location</th><th>Type</th><th></th></tr></thead>
<tbody>
<% @custom.each do |a| %>
<tr>
<td class="font-mono font-semibold"><%= a.ident %></td><td><%= a.name %></td><td class="text-xs"><%= a.place %></td>
<td class="text-xs"><%= a.kind.to_s.humanize %></td>
<td class="text-right"><%= link_to "Edit", edit_admin_airport_path(a), class: "btn-secondary btn-sm" %></td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<%= empty_state "None. Add private strips or fields that aren't in OurAirports." %>
<% end %>
</section>
+2
View File
@@ -0,0 +1,2 @@
<h1 class="mb-4 text-2xl font-bold">New Custom Airport</h1>
<%= render "form", airport: @airport %>
@@ -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>
+43
View File
@@ -0,0 +1,43 @@
<% content_for :title, "Export for AirTrail" %>
<%= render "shared/aircraft_header", aircraft: @aircraft %>
<div class="grid gap-5 lg:grid-cols-3">
<%= form_with url: aircraft_air_trail_export_path(@aircraft), class: "card card-body space-y-4 lg:col-span-2", data: { turbo: false } do |f| %>
<h2 class="card-title">Export flights for AirTrail</h2>
<% if @export.errors.any? %>
<div class="rounded-md bg-red-50 p-3 text-sm text-red-700 ring-1 ring-red-200"><ul class="list-disc pl-5"><% @export.errors.each do |e| %><li><%= e %></li><% end %></ul></div>
<% end %>
<div class="grid gap-4 sm:grid-cols-2">
<div>
<%= label_tag :username, "Your AirTrail username", class: "label" %>
<%= text_field_tag :username, params[:username].presence || @export.as_json[:users].first[:username], class: "input", required: true, autocomplete: "off" %>
<p class="hint">AirTrail assigns the flights to the account with this username (you can also pick the account while importing).</p>
</div>
<div>
<%= label_tag :aircraft_type, "Aircraft type (ICAO, optional)", class: "label" %>
<%= text_field_tag :aircraft_type, params[:aircraft_type].presence || @aircraft.icao_type, class: "input", placeholder: "C150", maxlength: 4 %>
<p class="hint">ICAO type designator, e.g. C150, C172, PA28.</p>
</div>
</div>
<fieldset class="space-y-1 text-sm">
<legend class="label">Flights</legend>
<label class="flex items-center gap-2"><%= radio_button_tag :scope, "all", params[:scope] != "mine" %> All <%= @aircraft.tail_number %> flights</label>
<label class="flex items-center gap-2"><%= radio_button_tag :scope, "mine", params[:scope] == "mine" %> Only flights I logged</label>
</fieldset>
<% all = AirTrailExport.new(@aircraft, username: "preview") %>
<p class="text-sm text-slate-600">
<%= pluralize(all.exportable.size, "flight") %> ready to export<% if all.skipped.positive? %>; <%= all.skipped %> skipped because the From or To airport is missing or isn't a code AirTrail can look up<% end %>.
</p>
<%= f.submit "Download AirTrail file", class: "btn-primary" %>
<% end %>
<section class="card card-body space-y-2 text-sm text-slate-700">
<h3 class="font-semibold">Importing into AirTrail</h3>
<ol class="list-decimal space-y-1 pl-4 text-xs">
<li>In AirTrail, open <strong>Settings → Import</strong> and choose <strong>AirTrail</strong> as the source.</li>
<li>Select the downloaded file.</li>
<li>Map any airports AirTrail doesn't recognize (small private fields may need this).</li>
</ol>
<p class="text-xs">Each flight is imported with you in the pilot seat, the tail number as the registration, and its tach/Hobbs time in the note. Duration comes from Hobbs time (or tach). GPS track logs (GPX, KML or CSV) are included.</p>
<p class="text-xs">Prefer automatic? <%= link_to "Set up AirTrail sync", air_trail_connection_path, class: "link" %> to push new flights as you log them.</p>
<p class="text-xs">Re-importing later is safe with AirTrail's de-duplication left on; repeat legs on the same day and route are numbered #2, #3… so they aren't merged.</p>
</section>
</div>
+1
View File
@@ -7,6 +7,7 @@
<%= f.field :serial_number %>
<%= f.field :purchased, as: :date %>
<%= f.field :status, as: :select, collection: Aircraft::STATUSES.invert %>
<%= f.field :icao_type, label: "ICAO type", placeholder: "C150", maxlength: 4, hint: "Type designator, used for AirTrail." %>
</div>
<%= f.field :description, as: :textarea, rows: 3 %>
<div class="grid gap-4 sm:grid-cols-4">
+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 %>
+1 -1
View File
@@ -2,7 +2,7 @@
<%= render "shared/aircraft_header", aircraft: @aircraft %>
<% if @stats.any? %><%= render "flight_logs/stats", stats: @stats %><% end %>
<section class="card">
<div class="card-header"><h2 class="card-title">Flight Log</h2><div class="flex gap-2"><% if owner? %><%= link_to "Import from spreadsheet", new_aircraft_flight_import_path(@aircraft), class: "btn-secondary" %><% end %><%= link_to "+ Log Flight", new_aircraft_flight_log_path(@aircraft), class: "btn-primary" %></div></div>
<div class="card-header"><h2 class="card-title">Flight Log</h2><div class="flex gap-2"><%= link_to "Export for AirTrail", new_aircraft_air_trail_export_path(@aircraft), class: "btn-secondary" %><% if owner? %><%= link_to "Standardize airport codes", aircraft_airport_codes_path(@aircraft), class: "btn-secondary" %><%= link_to "Import from spreadsheet", new_aircraft_flight_import_path(@aircraft), class: "btn-secondary" %><% end %><%= link_to "+ Log Flight", new_aircraft_flight_log_path(@aircraft), class: "btn-primary" %></div></div>
<% if @flight_logs.any? %>
<div class="overflow-x-auto">
<table class="table">
+2 -2
View File
@@ -4,8 +4,8 @@
<%= f.errors_summary %>
<div class="grid gap-4 sm:grid-cols-3">
<%= f.field :date, as: :date, required: true %>
<%= f.field :departure_location, label: "From", placeholder: "KPVD" %>
<%= f.field :destination_location, label: "To", placeholder: "KBID" %>
<%= render "shared/airport_field", f: f, attribute: :departure_location, label: "From", aircraft: @aircraft, placeholder: "KOQU" %>
<%= render "shared/airport_field", f: f, attribute: :destination_location, label: "To", aircraft: @aircraft, placeholder: "Code or name" %>
</div>
<fieldset class="grid gap-4 sm:grid-cols-3">
<legend class="mb-2 text-sm font-semibold">Tach (required)</legend>
+11 -1
View File
@@ -9,7 +9,17 @@
<dt class="text-slate-500">Oil added</dt><dd><%= @flight_log.oil_added ? "#{@flight_log.oil_added} qt #{@flight_log.oil_added_type}" : "—" %></dd>
<dt class="text-slate-500">Fuel added</dt><dd><%= @flight_log.fuel_added ? "#{@flight_log.fuel_added} gal #{@flight_log.fuel_added_type}" : "—" %></dd>
<dt class="text-slate-500">Pilot</dt><dd><%= @flight_log.user&.display_name || "—" %></dd>
<dt class="text-slate-500">Track log</dt><dd><%= @flight_log.track_log.attached? ? link_to(@flight_log.track_log.filename, rails_blob_path(@flight_log.track_log, disposition: :attachment), class: "link") : "—" %></dd>
<dt class="text-slate-500">Track log</dt><dd class="col-span-3"><%= @flight_log.track_log.attached? ? link_to(@flight_log.track_log.filename, rails_blob_path(@flight_log.track_log, disposition: :attachment), class: "link") : "—" %>
<% if @track %><span class="text-xs text-slate-500"> · <%= number_with_delimiter(@track.points) %> GPS points<%= " · max #{number_with_delimiter(@track.max_altitude_ft)} ft" if @track.max_altitude_ft %></span>
<% elsif @track_error %><span class="text-xs text-amber-700"> · <%= @track_error %></span><% end %></dd>
<% if @air_trail_sync || @air_trail_connection %>
<dt class="text-slate-500">AirTrail</dt>
<dd class="col-span-3 text-xs">
<% if @air_trail_sync&.status == "synced" %><span class="badge-green">Synced</span> <%= time_ago_in_words(@air_trail_sync.synced_at) %> ago
<% elsif @air_trail_sync&.status == "error" %><span class="badge-red">Not synced</span> <%= @air_trail_sync.last_error %>
<% else %><span class="badge-gray">Pending</span><% end %>
</dd>
<% end %>
</dl>
<% if @flight_log.notes.present? %><div class="border-t border-slate-100 px-4 py-3 text-sm"><%= simple_format @flight_log.notes %></div><% end %>
</section>
+10 -2
View File
@@ -25,8 +25,16 @@
<nav class="flex items-center gap-4 text-sm">
<%= link_to "Fleet", root_path, class: "hover:text-sky-300" %>
<% if current_user.admin? %>
<%= link_to "Users", admin_users_path, class: "hover:text-sky-300" %>
<%= link_to "Component Types", admin_component_types_path, class: "hover:text-sky-300 hidden sm:inline" %>
<details class="relative" data-controller="dropdown" data-action="click@window->dropdown#closeOutside keydown.esc@window->dropdown#close">
<summary class="flex cursor-pointer list-none items-center gap-1 hover:text-sky-300 [&::-webkit-details-marker]:hidden">
Admin <span aria-hidden="true" class="text-xs">▾</span>
</summary>
<div class="absolute right-0 z-30 mt-2 w-48 rounded-md bg-white py-1 text-slate-700 shadow-lg ring-1 ring-slate-200">
<% [ [ "Users", admin_users_path ], [ "Component Types", admin_component_types_path ], [ "Airports", admin_airports_path ] ].each do |label, path| %>
<%= link_to label, path, class: [ "block px-4 py-2 text-sm hover:bg-slate-100", ("font-semibold text-sky-700" if current_page?(path)) ] %>
<% end %>
</div>
</details>
<% end %>
<%= link_to current_user.display_name, edit_profile_path, class: "text-slate-300 hover:text-sky-300 hidden sm:inline" %>
<%= button_to "Sign out", session_path, method: :delete, class: "rounded bg-slate-700 px-2 py-1 hover:bg-slate-600" %>
+8
View File
@@ -7,3 +7,11 @@
<%= f.field :password_confirmation, as: :password, label: "Confirm new password" %>
<%= f.submit "Save" %>
<% end %>
<section class="card card-body mt-5 max-w-md">
<h2 class="card-title">Integrations</h2>
<p class="mt-1 text-sm text-slate-600">
<%= link_to "AirTrail sync", air_trail_connection_path, class: "link" %>:
<%= current_user.air_trail_connection&.enabled? ? "on" : "off" %>. Push the flights you log to your AirTrail flight map automatically.
</p>
</section>
+11
View File
@@ -0,0 +1,11 @@
<%# Airport code input with autocomplete. locals: f, attribute, label, aircraft %>
<div class="relative" data-controller="airport-autocomplete"
data-airport-autocomplete-url-value="<%= airport_search_path(aircraft_id: aircraft.id) %>">
<%= f.label attribute, label, class: "label" %>
<%= f.text_field attribute, class: "input font-mono uppercase placeholder:normal-case placeholder:font-sans", placeholder: local_assigns[:placeholder], maxlength: 10,
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>