Unverified transcriptions, PM templates, ICA inspections, W&B, AD watch

- Entries transcribed by Claude are unverified (with Claude's confidence)
  until an owner checks them against the scan: badge, filter, "mark
  verified" stepping through the rest
- Preventive maintenance templates on new logbook entries, keyed to Part 43
  Appendix A(c), setting the entry type and pilot certificate (43.3(g))
- An STC's ICA can become a tracked recurring inspection, linked from its
  major record
- Weight & balance: history of empty weight/CG (linked to the 337 that
  changed them), loading stations and CG envelope from the POH, and a live
  calculator for takeoff and landing weight/CG; shown on the status report
- New ADs: weekly Federal Register search per aircraft (aircraft, engine
  and propeller models, or custom terms); track or dismiss each; included
  in the weekly reminder
- Archives carry the new records; brakeman: explicit params, reviewed
  About-page links

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-07 10:49:29 -05:00
1 parent bed07386ef
commit 6cab81332e
49 files changed
+1197 -35

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@
<p class="font-mono text-2xl font-semibold" data-revision>
<%= info.revision_url ? link_to(info.revision, info.revision_url, class: "link", target: "_blank", rel: "noopener", title: "This commit on GitHub") : info.revision %>
</p>
<p class="mt-1 text-sm"><%= link_to "Source code", info.repository_url, class: "link", target: "_blank", rel: "noopener" %></p>
<% if info.repository_url %><p class="mt-1 text-sm"><%= link_to "Source code", info.repository_url, class: "link", target: "_blank", rel: "noopener" %></p><% end %>
</div>
<dl class="grid grid-cols-2 gap-x-6 gap-y-1 text-sm sm:grid-cols-3">
<div><dt class="text-slate-500">Built</dt><dd class="font-medium"><%= info.built_at ? l(info.built_at.in_time_zone, format: :short) : "—" %></dd></div>
@@ -51,6 +51,48 @@
<% end %>
</section>
<section class="card mt-5" id="new-ads">
<div class="card-header">
<div>
<h2 class="card-title">Newly published ADs that may apply</h2>
<p class="text-xs text-slate-500">Searched weekly in the Federal Register for <%= AdWatch.new(@aircraft).terms.to_sentence.presence || "the aircraft, engine and propeller models" %><%= " · last checked #{time_ago_in_words(@aircraft.ad_watch_checked_at)} ago" if @aircraft.ad_watch_checked_at %>.</p>
</div>
<% if owner? %><%= button_to "Check now", check_aircraft_ad_alerts_path(@aircraft), class: "btn-secondary btn-sm", data: { turbo_submits_with: "Checking…" } %><% end %>
</div>
<% if @alerts.any? %>
<ul class="divide-y divide-slate-100">
<% @alerts.each do |alert| %>
<li class="flex flex-wrap items-start justify-between gap-3 px-4 py-3">
<div class="min-w-0 flex-1 text-sm">
<div class="font-medium"><%= alert.ad_number ? "AD #{alert.ad_number}" : alert.fr_document_number %> · <%= alert.title.to_s.delete_prefix("Airworthiness Directives; ") %></div>
<div class="text-xs text-slate-500"><%= [ (alert.effective_on && "Effective #{alert.effective_on}"), "published #{alert.publication_date}", "matched “#{alert.matched_term}”" ].compact.join(" · ") %></div>
<p class="mt-1 text-xs text-slate-600"><%= alert.abstract.to_s.truncate(400) %></p>
<%= link_to "Read it in the Federal Register", alert.html_url, class: "link text-xs", target: "_blank", rel: "noopener" %>
</div>
<% if owner? %>
<div class="flex gap-2">
<%= button_to "Track", track_aircraft_ad_alert_path(@aircraft, alert), class: "btn-primary btn-sm", title: "Add it to this aircraft's ADs" %>
<%= button_to "Dismiss", dismiss_aircraft_ad_alert_path(@aircraft, alert), class: "btn-secondary btn-sm", title: "Doesn't apply" %>
</div>
<% end %>
</li>
<% end %>
</ul>
<% else %>
<%= empty_state "Nothing new to review." %>
<% end %>
<% if owner? %>
<%= form_with url: terms_aircraft_ad_alerts_path(@aircraft), method: :patch, class: "flex flex-wrap items-end gap-2 border-t border-slate-100 px-4 py-3" do %>
<div class="min-w-0 flex-1">
<%= label_tag :ad_watch_terms, "Search terms", class: "label" %>
<%= text_field_tag :ad_watch_terms, @aircraft.ad_watch_terms, class: "input", placeholder: AdWatch.default_terms(@aircraft).join(", ").presence || "e.g. 172N, O-320, 1C160" %>
</div>
<%= submit_tag "Save", class: "btn-secondary" %>
<p class="hint w-full">Comma-separated model names. Left blank, the aircraft, engine and propeller models are used. Matches are only possibly applicable: check each AD's applicability (and serial number ranges) before tracking it.</p>
<% end %>
<% end %>
</section>
<section class="card mt-5">
<div class="card-header"><h2 class="card-title">Compliance History</h2></div>
<% if @history.any? %>
@@ -1,5 +1,9 @@
<%= form_with model: inspection_type, url: inspection_type.new_record? ? aircraft_inspection_types_path(aircraft) : aircraft_inspection_type_path(aircraft, inspection_type), class: "card card-body space-y-4 max-w-2xl" do |f| %>
<%= f.errors_summary %>
<% if @major_record %>
<%= hidden_field_tag :major_record_id, @major_record.id %>
<p class="rounded-md bg-sky-50 px-3 py-2 text-sm text-sky-900 ring-1 ring-sky-200">For the Instructions for Continued Airworthiness of <strong><%= @major_record.title %></strong><%= " (STC #{@major_record.stc_number})" if @major_record.stc_number.present? %>. Set the interval the ICA gives.<%= " ICA notes: #{@major_record.ica_notes}" if @major_record.ica_notes.present? %></p>
<% end %>
<%= f.field :name, required: true, placeholder: "Annual Inspection" %>
<%= f.field :effect, as: :select, label: "When overdue", collection: InspectionType::EFFECTS.invert,
hint: "An overdue pitot-static check (91.411) only rules out IFR, and an overdue transponder check (91.413) only rules out using the transponder. Neither grounds the aircraft." %>
+43
View File
@@ -0,0 +1,43 @@
<% content_for :title, "#{@aircraft.tail_number} Loading setup" %>
<%= render "shared/aircraft_header", aircraft: @aircraft %>
<% stations = @setup.stations + Array.new([ 8 - @setup.stations.size, 2 ].max) { nil } %>
<% points = @setup.envelope + Array.new([ 10 - @setup.envelope.size, 2 ].max) { nil } %>
<%= form_with url: aircraft_loading_setup_path(@aircraft), method: :patch, class: "card card-body max-w-3xl space-y-5" do %>
<div>
<h2 class="card-title">Loading setup</h2>
<p class="mt-1 text-sm text-slate-600">From the POH's weight and balance section. Arms are inches aft of the datum.</p>
</div>
<% if @setup.errors.any? %>
<div class="rounded-md bg-red-50 p-3 text-sm text-red-700 ring-1 ring-red-200" role="alert"><ul class="list-disc pl-5"><% @setup.errors.full_messages.each do |m| %><li><%= m %></li><% end %></ul></div>
<% end %>
<fieldset>
<legend class="label">Stations</legend>
<div class="grid grid-cols-[1fr_6rem_6rem_auto] gap-2 text-xs text-slate-500"><span>Name</span><span>Arm (in)</span><span>Max</span><span>Fuel (gal)</span></div>
<% stations.each_with_index do |st, i| %>
<div class="mt-1 grid grid-cols-[1fr_6rem_6rem_auto] items-center gap-2">
<%= text_field_tag "setup[stations][#{i}][name]", st&.name, class: "input", placeholder: ("Front seats" if i.zero?), "aria-label": "Station #{i + 1} name" %>
<%= text_field_tag "setup[stations][#{i}][arm]", st&.arm&.to_s&.sub(/\.0\z/, ""), class: "input", inputmode: "decimal", "aria-label": "Station #{i + 1} arm" %>
<%= text_field_tag "setup[stations][#{i}][max]", st&.max&.to_s&.sub(/\.0\z/, ""), class: "input", inputmode: "decimal", "aria-label": "Station #{i + 1} maximum" %>
<%= check_box_tag "setup[stations][#{i}][fuel]", "1", st&.fuel, class: "mx-auto h-4 w-4", "aria-label": "Station #{i + 1} is fuel" %>
</div>
<% end %>
<p class="hint">Tick "Fuel" for fuel tanks: their quantity is entered in gallons and the max is the usable capacity. Other maximums are in pounds.</p>
</fieldset>
<div class="max-w-xs">
<%= label_tag "setup[fuel_lb_per_gal]", "Fuel weight (lb per gallon)", class: "label" %>
<%= text_field_tag "setup[fuel_lb_per_gal]", @setup.fuel_lb_per_gal.to_s.sub(/\.0\z/, ""), class: "input", inputmode: "decimal" %>
<p class="hint">6 for avgas, 6.7 for Jet-A.</p>
</div>
<fieldset>
<legend class="label">CG envelope</legend>
<p class="hint !mt-0 mb-2">The corners of the normal-category envelope, in order around it (e.g. forward limit at low weight, forward limit at gross, aft limit at gross, aft limit at low weight).</p>
<div class="grid max-w-sm grid-cols-2 gap-2 text-xs text-slate-500"><span>Weight (lb)</span><span>CG (in)</span></div>
<% points.each_with_index do |pt, i| %>
<div class="mt-1 grid max-w-sm grid-cols-2 gap-2">
<%= text_field_tag "setup[envelope][#{i}][weight]", pt&.first&.to_s&.sub(/\.0\z/, ""), class: "input", inputmode: "decimal", "aria-label": "Envelope point #{i + 1} weight" %>
<%= text_field_tag "setup[envelope][#{i}][cg]", pt&.last&.to_s&.sub(/\.0\z/, ""), class: "input", inputmode: "decimal", "aria-label": "Envelope point #{i + 1} CG" %>
</div>
<% end %>
</fieldset>
<div class="flex gap-2"><%= submit_tag "Save", class: "btn-primary" %><%= link_to "Cancel", aircraft_weight_balance_records_path(@aircraft), class: "btn-secondary" %></div>
<% end %>
+19 -4
View File
@@ -1,17 +1,29 @@
<%= form_with model: [aircraft, entry], class: "card card-body space-y-4 max-w-3xl" do |f| %>
<%= form_with model: [aircraft, entry], class: "card card-body space-y-4 max-w-3xl", data: { controller: "entry-template" } do |f| %>
<%= f.errors_summary %>
<% if entry.new_record? %>
<div>
<%= label_tag :template, "Preventive maintenance template", class: "label" %>
<select id="template" class="input" data-entry-template-target="template" data-action="entry-template#apply">
<option value="">— Write it yourself —</option>
<% PreventiveMaintenance::ITEMS.each do |item| %>
<option value="<%= item.key %>" data-text="<%= PreventiveMaintenance.text_for(item) %>"><%= item.label %> (<%= item.paragraphs.join(", ") %>)</option>
<% end %>
</select>
<p class="hint">For a pilot doing preventive maintenance on an aircraft they own or operate (14 CFR 43.3(g)). Fill in the blanks (__) and add your name and pilot certificate number. The item list is paraphrased from Part 43 Appendix A(c); the rule sets each item's limits.</p>
</div>
<% end %>
<div class="grid gap-4 sm:grid-cols-4">
<%= f.field :date, as: :date %>
<%= f.field :log_type, as: :select, label: "Logbook", collection: LogbookEntry::LOG_TYPES.invert %>
<%= f.field :entry_type, as: :select, label: "Entry type", collection: LogbookEntry::ENTRY_TYPES.invert %>
<%= f.field :entry_type, as: :select, label: "Entry type", collection: LogbookEntry::ENTRY_TYPES.invert, data: { entry_template_target: "entryType" } %>
<%= f.field :aircraft_hours_at_entry, as: :number, step: 0.1, label: "Aircraft hours" %>
</div>
<%= f.field :text, as: :textarea, label: "Entry text", rows: 8 %>
<%= f.field :text, as: :textarea, label: "Entry text", rows: 8, data: { entry_template_target: "text" } %>
<p class="hint !mt-1">A maintenance entry needs a description of the work, the date, and the name, signature, certificate number and kind of certificate of whoever approved the return to service (14 CFR 43.9). An inspection entry also needs the type and extent of the inspection, the aircraft's time in service, and the result (43.11).</p>
<div class="grid gap-4 sm:grid-cols-3">
<%= f.field :signoff_person, label: "Signed off by", placeholder: "Name" %>
<%= f.field :signoff_certificate_type, as: :select, label: "Kind of certificate", include_blank: "—",
collection: LogbookEntry::CERTIFICATE_TYPES.invert %>
collection: LogbookEntry::CERTIFICATE_TYPES.invert, data: { entry_template_target: "certificate" } %>
<%= f.field :signoff_certificate_number, label: "Certificate number", placeholder: "e.g. 1234567" %>
</div>
<div class="grid gap-4 sm:grid-cols-2">
@@ -21,6 +33,9 @@
<%= f.field :document_id, as: :select, label: "Scanned page document", collection: document_options(aircraft) %>
<%= f.field :page_number, as: :number, label: "Page # in document" %>
</div>
<% if entry.persisted? && !entry.verified_was %>
<%= f.field :verified, as: :checkbox, label: "I've checked this against the scan", hint: "Transcribed by Claude; it stays marked unverified until someone checks it." %>
<% end %>
<div class="flex gap-2"><%= f.submit "Save Entry" %><%= link_to "Cancel", aircraft_logbook_entries_path(aircraft), class: "btn-secondary" %></div>
<% end %>
<% if entry.persisted? %><div class="mt-4"><%= delete_button "Delete entry", aircraft_logbook_entry_path(aircraft, entry) %></div><% end %>
+5 -1
View File
@@ -7,6 +7,9 @@
<%= form_with url: aircraft_logbook_entries_path(@aircraft), method: :get, class: "flex w-full flex-wrap gap-2 sm:w-auto" do |f| %>
<%= f.search_field :q, value: @query, placeholder: "Search entries…", class: "input min-w-0 flex-1 sm:w-48 sm:flex-none" %>
<%= f.select :log_type, LogbookEntry::LOG_TYPES.invert, { include_blank: "All logs", selected: @log_type }, class: "input w-32" %>
<% if @unverified_count.positive? || @unverified_only %>
<label class="flex items-center gap-1 text-sm text-slate-700"><%= f.check_box :unverified, { checked: @unverified_only }, "1", nil %> Unverified (<%= @unverified_count %>)</label>
<% end %>
<%= f.submit "Filter", class: "btn-secondary" %>
<% end %>
<% if owner? %><%= link_to "Import scans", new_aircraft_logbook_import_path(@aircraft), class: "btn-secondary" %><%= link_to "+ New Entry", new_aircraft_logbook_entry_path(@aircraft), class: "btn-primary" %><% end %>
@@ -23,7 +26,8 @@
<td><span class="badge-gray"><%= LogbookEntry::LOG_TYPES[e.log_type] %></span></td>
<td class="text-xs"><%= LogbookEntry::ENTRY_TYPES[e.entry_type] %></td>
<td class="text-right tabular-nums"><%= hours(e.aircraft_hours_at_entry) %></td>
<td class="max-w-xl"><%= e.text.truncate(220) %> <%= "📄" if e.document %></td>
<td class="max-w-xl"><%= e.text.truncate(220) %> <%= "📄" if e.document %>
<% unless e.verified? %><span class="badge-orange" title="Transcribed by Claude<%= " (#{e.transcription_confidence} confidence)" if e.transcription_confidence %>; check it against the scan">Unverified</span><% end %></td>
<td class="text-xs text-slate-500"><%= e.signoff_person %><%= " ##{e.signoff_certificate_number}" if e.signoff_certificate_number %><% if e.signoff_location.present? %><br><%= e.signoff_location %><% end %>
<% if (missing = e.missing_record_items).any? %><br><span class="badge-orange" title="Missing: <%= missing.to_sentence %>">Incomplete</span><% end %></td>
</tr>
+6
View File
@@ -5,6 +5,12 @@
<% if owner? %><%= link_to "Edit", edit_aircraft_logbook_entry_path(@aircraft, @entry), class: "btn-secondary btn-sm" %><% end %>
</div>
<div class="card-body space-y-3">
<% unless @entry.verified? %>
<div class="flex flex-wrap items-center justify-between gap-2 rounded-md bg-amber-50 px-3 py-2 text-sm text-amber-900 ring-1 ring-amber-200">
<span>Transcribed by Claude<%= " (#{@entry.transcription_confidence} confidence)" if @entry.transcription_confidence %> and not yet checked. Compare it with the scan<%= @entry.document ? "" : " or the paper logbook" %> before relying on it.</span>
<% if owner? %><%= button_to "Matches the scan: mark verified", verify_aircraft_logbook_entry_path(@aircraft, @entry), method: :patch, class: "btn-secondary btn-sm" %><% end %>
</div>
<% end %>
<div class="flex flex-wrap gap-4 text-sm text-slate-600">
<span>Type: <%= LogbookEntry::ENTRY_TYPES[@entry.entry_type] %></span>
<span>Aircraft hours: <%= hours(@entry.aircraft_hours_at_entry) %></span>
+2 -1
View File
@@ -23,7 +23,8 @@
<%= @import.transcribe ? "Done: #{pluralize(@import.entries_created, 'logbook entry')} added." : "Pages saved." %>
</p>
<% if @import.transcribe && @import.entries_created.positive? %>
<p class="text-slate-600">Check the new entries against the scans: handwriting isn't always read perfectly.</p>
<p class="text-slate-600">The new entries are marked unverified until someone checks them against the scans, since handwriting isn't always read perfectly.
<%= link_to "Check them now", aircraft_logbook_entries_path(@aircraft, unverified: 1), class: "link" %></p>
<% end %>
<% else %>
<p class="font-medium text-red-700">The import stopped: <%= @import.error %></p>
@@ -136,6 +136,13 @@
<% else %><p class="mt-1 text-sm text-slate-500">None recorded.</p><% end %>
</section>
<section class="<%= section %>">
<h2 class="text-base font-semibold">Weight and balance</h2>
<% if (wb = a.current_weight_balance) %>
<p class="mt-1 text-sm">Empty weight <strong><%= number_with_precision(wb.empty_weight, precision: 1, delimiter: ",") %> lb</strong>, CG <strong><%= number_with_precision(wb.empty_arm, precision: 2) %> in</strong><%= ", useful load #{number_with_precision(wb.useful_load, precision: 1, delimiter: ',')} lb" if wb.useful_load %>, as of <%= wb.date %><%= " (#{wb.reason})" if wb.reason.present? %>.</p>
<% else %><p class="mt-1 text-sm text-slate-500">None recorded.</p><% end %>
</section>
<section class="<%= section %>">
<h2 class="text-base font-semibold">Open discrepancies</h2>
<% if (squawks = @report.open_squawks.to_a).any? %>
+18 -1
View File
@@ -11,7 +11,24 @@
<dt class="text-slate-500">STC</dt><dd><%= [@record.stc_number, @record.stc_holder].compact_blank.join(" · ").presence || "—" %>
<%= link_to("(docs)", aircraft_document_path(@aircraft, @record.stc_document), class: "link") if @record.stc_document %></dd>
<dt class="text-slate-500">Logbook</dt><dd><%= @record.logbook_entry ? link_to(@record.logbook_entry.date, aircraft_logbook_entry_path(@aircraft, @record.logbook_entry), class: "link") : "—" %></dd>
<dt class="text-slate-500">ICAs</dt><dd><%= @record.has_ica? ? "Yes" : "No" %></dd>
<dt class="text-slate-500">Weight & balance</dt>
<dd>
<% if (wb = @aircraft.weight_balance_records.where(major_record: @record).recent_first.first) %>
<%= link_to "#{wb.date}: #{number_with_precision(wb.empty_weight, precision: 1)} lb @ #{number_with_precision(wb.empty_arm, precision: 2)} in", aircraft_weight_balance_records_path(@aircraft), class: "link" %>
<% elsif owner? %>
<%= link_to "Record the new W&B", new_aircraft_weight_balance_record_path(@aircraft, major_record_id: @record.id), class: "link" %>
<% else %>—<% end %>
</dd>
<dt class="text-slate-500">ICAs</dt>
<dd>
<%= @record.has_ica? ? "Yes" : "No" %>
<% if (ica = @record.ica_inspection_type) %>
<% row = Compliance.inspection_rows(@aircraft).find { _1.type == ica } %>
· Inspection: <%= link_to ica.name, aircraft_inspections_path(@aircraft), class: "link" %> <%= compliance_badge(row.status) if row %>
<% elsif @record.has_ica? && owner? %>
· <%= link_to "Add the ICA's recurring inspection", new_aircraft_inspection_type_path(@aircraft, major_record_id: @record.id), class: "link" %>
<% end %>
</dd>
</dl>
<% [["Description", @record.description], ["ICA notes", @record.ica_notes], ["Notes", @record.notes]].each do |title, text| %>
<% if text.present? %><div class="border-t border-slate-100 px-4 py-3 text-sm"><h3 class="mb-1 font-medium"><%= title %></h3><%= simple_format text %></div><% end %>
+5 -1
View File
@@ -1,5 +1,5 @@
<p>Here's what needs attention on your aircraft.</p>
<% @items.each do |aircraft, issues| %>
<% @items.each do |aircraft, issues, alerts| %>
<h3 style="margin: 16px 0 4px;"><%= link_to aircraft.tail_number, aircraft_url(aircraft) %> <span style="font-weight: normal; color: #64748b;"><%= aircraft.airworthiness.label %></span></h3>
<ul style="margin: 0; padding-left: 20px;">
<% issues.each do |issue| %>
@@ -7,6 +7,10 @@
<%= issue.title %> <span style="color: #64748b;"><%= issue.description %></span></li>
<% end %>
</ul>
<% if alerts.any? %>
<p style="margin: 8px 0 0;"><strong><%= alerts.size %> newly published <%= "AD".pluralize(alerts.size) %> may apply:</strong>
<%= alerts.map { _1.ad_number || _1.fr_document_number }.to_sentence %>. <%= link_to "Review them", aircraft_airworthiness_directives_url(aircraft, anchor: "new-ads") %>.</p>
<% end %>
<% end %>
<p style="color: #64748b; font-size: 12px; margin-top: 20px;">
Based on the records in Simple Aircraft Manager. Turn these emails off on your <%= link_to "profile", edit_profile_url %>.
+4 -1
View File
@@ -1,10 +1,13 @@
Here's what needs attention on your aircraft.
<% @items.each do |aircraft, issues| %>
<% @items.each do |aircraft, issues, alerts| %>
<%= aircraft.tail_number %> (<%= aircraft.airworthiness.label %>): <%= aircraft_url(aircraft) %>
<% issues.each do |issue| %>
- <%= { "RED" => "Overdue", "LIMITED" => "Overdue", "ORANGE" => "Due soon", "INFO" => "Deferred" }[issue.severity] %>: <%= issue.title %>. <%= issue.description %>
<% end %>
<% if alerts.any? %>
- New ADs that may apply: <%= alerts.map { _1.ad_number || _1.fr_document_number }.to_sentence %>. Review: <%= aircraft_airworthiness_directives_url(aircraft, anchor: "new-ads") %>
<% end %>
<% end %>
Based on the records in Simple Aircraft Manager. Turn these emails off on your profile: <%= edit_profile_url %>
@@ -0,0 +1,18 @@
<%= form_with model: [aircraft, record], url: record.new_record? ? aircraft_weight_balance_records_path(aircraft) : aircraft_weight_balance_record_path(aircraft, record),
class: "card card-body space-y-4 max-w-2xl" do |f| %>
<%= f.errors_summary %>
<p class="text-sm text-slate-600">The figures from the weight & balance report: after weighing, or after an alteration or equipment change that changes the empty weight or CG.</p>
<div class="grid gap-4 sm:grid-cols-2">
<%= f.field :date, as: :date %>
<%= f.field :reason, placeholder: "e.g. Weighed at annual; GTX 345 installed" %>
<%= f.field :empty_weight, as: :number, step: 0.1, label: "Empty weight (lb)", required: true %>
<%= f.field :empty_arm, as: :number, step: 0.01, label: "Empty CG / arm (in aft of datum)", required: true %>
<%= f.field :max_gross_weight, as: :number, step: 0.1, label: "Max gross weight (lb)" %>
<%= f.field :major_record_id, as: :select, label: "Alteration (337)",
collection: [ [ "— None —", nil ] ] + aircraft.major_records.recent_first.map { [ "#{_1.date_performed} – #{_1.title.truncate(50)}", _1.id ] } %>
<%= f.field :document_id, as: :select, label: "W&B report document", collection: document_options(aircraft) %>
</div>
<%= f.field :notes, as: :textarea, rows: 2 %>
<div class="flex gap-2"><%= f.submit "Save" %><%= link_to "Cancel", aircraft_weight_balance_records_path(aircraft), class: "btn-secondary" %></div>
<% end %>
<% if record.persisted? %><div class="mt-4"><%= delete_button "Delete record", aircraft_weight_balance_record_path(aircraft, record) %></div><% end %>
@@ -0,0 +1,3 @@
<% content_for :title, "#{@aircraft.tail_number} Weight & Balance" %>
<%= render "shared/aircraft_header", aircraft: @aircraft %>
<%= render "form", aircraft: @aircraft, record: @record %>
@@ -0,0 +1,94 @@
<% content_for :title, "#{@aircraft.tail_number} Weight & Balance" %>
<%= render "shared/aircraft_header", aircraft: @aircraft %>
<% setup = @aircraft.loading_setup %>
<div class="grid gap-5 lg:grid-cols-2">
<section class="card">
<div class="card-header">
<h2 class="card-title">Current weight & balance</h2>
<% if owner? %><%= link_to "+ New W&B", new_aircraft_weight_balance_record_path(@aircraft), class: "btn-primary btn-sm" %><% end %>
</div>
<% if @current %>
<dl class="card-body grid grid-cols-2 gap-x-4 gap-y-2 text-sm">
<dt class="text-slate-500">As of</dt><dd><%= fmt_date(@current.date) %><%= " · #{@current.reason}" if @current.reason.present? %></dd>
<dt class="text-slate-500">Empty weight</dt><dd class="font-medium"><%= number_with_precision(@current.empty_weight, precision: 1, delimiter: ",") %> lb</dd>
<dt class="text-slate-500">Empty CG (arm)</dt><dd class="font-medium"><%= number_with_precision(@current.empty_arm, precision: 2) %> in</dd>
<dt class="text-slate-500">Moment</dt><dd><%= number_with_precision(@current.empty_moment, precision: 0, delimiter: ",") %> lb-in</dd>
<dt class="text-slate-500">Max gross weight</dt><dd><%= @current.max_gross_weight ? "#{number_with_precision(@current.max_gross_weight, precision: 0, delimiter: ',')} lb" : "—" %></dd>
<dt class="text-slate-500">Useful load</dt><dd class="font-medium"><%= @current.useful_load ? "#{number_with_precision(@current.useful_load, precision: 1, delimiter: ',')} lb" : "—" %></dd>
</dl>
<% else %>
<%= empty_state "No weight & balance recorded yet. Add the figures from the current W&B report." %>
<% end %>
</section>
<section class="card">
<div class="card-header">
<h2 class="card-title">Loading calculator</h2>
<% if owner? %><%= link_to "Loading setup", edit_aircraft_loading_setup_path(@aircraft), class: "btn-secondary btn-sm" %><% end %>
</div>
<% if @current && setup.configured? %>
<div class="card-body space-y-3" data-controller="wb-calculator"
data-wb-calculator-empty-weight-value="<%= @current.empty_weight.to_f %>" data-wb-calculator-empty-moment-value="<%= @current.empty_moment.to_f %>"
data-wb-calculator-max-gross-value="<%= @current.max_gross_weight.to_f %>" data-wb-calculator-fuel-density-value="<%= setup.fuel_lb_per_gal.to_f %>"
data-wb-calculator-envelope-value="<%= setup.envelope.map { |w, c| [ w.to_f, c.to_f ] }.to_json %>">
<div class="grid gap-2 sm:grid-cols-2">
<% setup.stations.each do |st| %>
<label class="text-sm">
<span class="label"><%= st.name %> <span class="font-normal text-slate-500">· arm <%= st.arm %> in<%= ", max #{st.max.to_s.sub(/\.0\z/, '')} #{st.fuel ? 'gal' : 'lb'}" if st.max %></span></span>
<span class="flex items-center gap-2">
<input type="number" min="0" step="0.1" class="input" inputmode="decimal" data-wb-calculator-target="station"
data-arm="<%= st.arm.to_f %>" data-fuel="<%= st.fuel %>" data-max="<%= st.max.to_f %>" data-action="input->wb-calculator#update">
<span class="w-6 text-xs text-slate-500"><%= st.fuel ? "gal" : "lb" %></span>
</span>
</label>
<% end %>
<% if setup.stations.any?(&:fuel) %>
<label class="text-sm"><span class="label">Fuel burned in flight</span>
<span class="flex items-center gap-2"><input type="number" min="0" step="0.1" class="input" inputmode="decimal" data-wb-calculator-target="burn" data-action="input->wb-calculator#update"><span class="w-6 text-xs text-slate-500">gal</span></span></label>
<% end %>
</div>
<div class="grid items-start gap-3 sm:grid-cols-[1fr_auto]">
<table class="w-full text-sm table-keep">
<thead><tr class="text-left text-xs uppercase text-slate-500"><th></th><th class="text-right">Weight</th><th class="text-right">CG</th><th class="text-right">Moment</th></tr></thead>
<tbody>
<tr><td>Takeoff</td><td class="text-right tabular-nums" data-wb-calculator-target="takeoffWeight">—</td><td class="text-right tabular-nums" data-wb-calculator-target="takeoffCg">—</td><td class="text-right tabular-nums" data-wb-calculator-target="takeoffMoment">—</td></tr>
<tr><td>Landing</td><td class="text-right tabular-nums" data-wb-calculator-target="landingWeight">—</td><td class="text-right tabular-nums" data-wb-calculator-target="landingCg">—</td><td class="text-right tabular-nums" data-wb-calculator-target="landingMoment">—</td></tr>
</tbody>
</table>
<svg viewBox="0 0 220 160" class="h-40 w-56 rounded bg-slate-50" data-wb-calculator-target="chart" aria-label="CG envelope"></svg>
</div>
<ul class="space-y-1 text-sm" data-wb-calculator-target="messages" role="status"></ul>
<p class="hint">A planning aid from the figures entered here. Check against the POH and the aircraft's current W&B report.</p>
</div>
<% elsif !@current %>
<%= empty_state "Record the current weight & balance first." %>
<% else %>
<%= empty_state(owner? ? "Set up the loading stations and CG envelope from the POH to use the calculator." : "An owner needs to set up the loading stations first.") %>
<% end %>
</section>
</div>
<section class="card mt-5">
<div class="card-header"><h2 class="card-title">History</h2></div>
<% if @records.any? %>
<div class="overflow-x-auto">
<table class="table">
<thead><tr><th>Date</th><th class="text-right">Empty weight</th><th class="text-right">CG</th><th class="text-right">Useful load</th><th>Reason</th><th></th></tr></thead>
<tbody>
<% @records.each do |r| %>
<tr>
<td class="whitespace-nowrap"><%= r.date %></td>
<td class="text-right tabular-nums"><%= number_with_precision(r.empty_weight, precision: 1, delimiter: ",") %> lb</td>
<td class="text-right tabular-nums"><%= number_with_precision(r.empty_arm, precision: 2) %> in</td>
<td class="text-right tabular-nums"><%= r.useful_load ? "#{number_with_precision(r.useful_load, precision: 1, delimiter: ',')} lb" : "—" %></td>
<td class="text-xs"><%= r.reason %>
<% if r.major_record %><div><%= link_to r.major_record.title, aircraft_major_record_path(@aircraft, r.major_record), class: "link" %></div><% end %>
<% if r.document %><div><%= link_to "📄 #{r.document.name}", aircraft_document_path(@aircraft, r.document), class: "link" %></div><% end %></td>
<td class="text-right"><% if owner? %><%= link_to "Edit", edit_aircraft_weight_balance_record_path(@aircraft, r), class: "btn-secondary btn-sm" %><% end %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% else %><%= empty_state "No records yet." %><% end %>
</section>
@@ -0,0 +1,3 @@
<% content_for :title, "#{@aircraft.tail_number} Weight & Balance" %>
<%= render "shared/aircraft_header", aircraft: @aircraft %>
<%= render "form", aircraft: @aircraft, record: @record %>