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

Standardize airport codes

<%= pluralize(changes.size, "code") %> to update · <%= changes.sum(&:flights) %> entries
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.
<% if changes.any? %> <% changes.each do |c| %> <% end %>
LoggedStandardAirportEntries
<%= check_box_tag "codes[]", c.from, c.suggested, id: "code_#{c.from.parameterize}" %> <%= label_tag "code_#{c.from.parameterize}", c.from %> <%= c.to %> <%= c.airport.name %> <%= c.airport.place %> <% if c.note %>
<%= c.note %>
<% end %>
<%= c.flights %>
<% else %> <%= empty_state "All logged codes already match the airport database." %> <% end %>
<% if @standardizer.unknown.any? %>

Not in the airport database

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

<% @standardizer.unknown.each do |u| %>
<%= u.code %>
<%= pluralize(u.flights, "entry") %> →
<%= 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" } %>

<% if u.suggestion %>
Suggested: <%= u.suggestion.name %>, <%= u.suggestion.place %> (letters swapped?)
<% end %>
<% end %>
<% end %>
<% 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" %>
<% end %>