Overview shows coming due and the last flight; intervals in days, months or years

- Overview: "Coming due" (next 30 days or 10 hours) and "Last flight" (the
  most recent day's legs, meters at the end, fuel and oil left).
- Component replace / TBO / inspect intervals, inspection types and ADs take
  a number and a days / months / years choice (CalendarInterval). Components
  gain month columns (years stored as 12 months; months land on the same
  date); inspection types and ADs keep end-of-month. ADs now honour days.
- Due list: hours already run out count as overdue; a component covered by
  an inspection type no longer gets its own "Inspect every" item.
- Loading calculator moved to a partial; no limit warnings until a load is
  entered. Header buttons don't wrap on phones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-11 21:40:14 -05:00
1 parent 215efe6814
commit 31ac991bab
37 files changed
+385 -75

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
<%# What's due in the next few weeks or hours (Overview). %>
<section class="card">
<div class="card-header">
<h2 class="card-title">Coming due</h2>
<span class="text-xs text-slate-500">next <%= DueList::SOON_DAYS %> days or <%= DueList::SOON_HOURS %> hrs</span>
</div>
<% if due.any? %>
<ul class="divide-y divide-slate-100">
<% due.each do |item| %>
<li class="flex items-baseline justify-between gap-3 px-4 py-2 text-sm">
<%= link_to item.title, item.path, class: [ "hover:underline", ("font-medium text-red-700" if item.overdue?) ] %>
<span class="shrink-0 text-right text-xs text-slate-500 tabular-nums">
<% if item.overdue? %>overdue<% else %><%= "~" if item.projected %><%= fmt_date(item.date) %><% end %><%= " · at #{hours(item.due_hours)} hrs" if item.due_hours %>
</span>
</li>
<% end %>
</ul>
<% if due.any?(&:projected) %><p class="hint px-4 pb-3">"~" dates are estimated from the last year's flying.</p><% end %>
<% else %>
<%= empty_state "Nothing coming due soon." %>
<% end %>
</section>
+27
View File
@@ -0,0 +1,27 @@
<%# The most recent day's flying (Overview). %>
<section class="card">
<div class="card-header">
<h2 class="card-title">Last flight</h2>
<%= link_to "Flights →", aircraft_flight_logs_path(aircraft), class: "link text-sm" %>
</div>
<% if last_day %>
<% route = last_day.flat_map { [ _1.departure_location, _1.destination_location ] }.compact_blank.chunk_while { _1 == _2 }.map(&:first) %>
<% last_leg = last_day.last %>
<% fuel_after = last_day.reverse.find(&:fuel_level_after)&.fuel_level_after %>
<% oil_after = last_day.reverse.find(&:oil_level_after)&.oil_level_after %>
<dl class="card-body grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5 text-sm">
<dt class="text-slate-500">Date</dt>
<dd><%= fmt_date(last_leg.date) %><%= " · #{pluralize(last_day.size, 'leg')}" if last_day.size > 1 %></dd>
<% if route.any? %><dt class="text-slate-500">Route</dt><dd><%= route.join(" → ") %></dd><% end %>
<dt class="text-slate-500">Flown</dt><dd><%= hours(last_day.sum { _1.tach_time.to_d }) %> hrs tach</dd>
<% if last_leg.tach_in %><dt class="text-slate-500">Ended at</dt><dd>Tach <%= hours(last_leg.tach_in) %><%= " · Hobbs #{hours(last_leg.hobbs_in)}" if last_leg.hobbs_in %></dd><% end %>
<% if fuel_after %><dt class="text-slate-500">Fuel after</dt><dd><%= number_with_precision(fuel_after, precision: 1, strip_insignificant_zeros: true) %> gal</dd><% end %>
<% if oil_after %><dt class="text-slate-500">Oil after</dt><dd><%= number_with_precision(oil_after, precision: 1, strip_insignificant_zeros: true) %> qt</dd><% end %>
<% if (notes = last_day.filter_map { _1.notes.presence }).any? %>
<dt class="text-slate-500">Notes</dt><dd class="whitespace-pre-line"><%= notes.join("\n") %></dd>
<% end %>
</dl>
<% else %>
<%= empty_state "No flights logged yet." %>
<% end %>
</section>
+4
View File
@@ -46,6 +46,8 @@
<% end %>
</section>
<%= render "aircraft/coming_due", aircraft: @aircraft, due: @coming_due %>
<section class="card">
<div class="card-header"><h2 class="card-title">Consumption</h2>
<%= link_to "Oil & fuel →", aircraft_consumable_records_path(@aircraft), class: "link text-sm" %></div>
@@ -71,6 +73,8 @@
<% end %>
</section>
<%= render "aircraft/last_flight", aircraft: @aircraft, last_day: @last_day %>
<section class="card">
<div class="card-header">
<h2 class="card-title">Details</h2>
@@ -15,7 +15,7 @@
</div>
<div class="grid gap-4 sm:grid-cols-3">
<%= f.field :recurring_hours, as: :number, step: 0.1, label: "Every (hours)" %>
<%= f.field :recurring_months, as: :number, label: "Every (months)" %>
<%= f.interval :recurring, label: "Every", hint: "Months and years are due at the end of the month." %>
<%= f.field :document_id, as: :select, label: "Reference document", collection: document_options(aircraft) %>
</div>
<%= f.field :document_url, label: "Link to AD document", placeholder: "https://…",
@@ -30,7 +30,7 @@
<% if ad.effective_date || ad.product_type.present? %><div class="text-slate-500"><%= [(ad.effective_date && "Effective #{fmt_date(ad.effective_date)}"), ad.product_type.presence].compact.join(" · ") %></div><% end %>
<% if ad.superseded_by.present? %><div class="text-amber-700">Superseded by <%= ad.superseded_by %></div><% end %>
<% if ad.conditional? && ad.trigger_condition.present? %><div class="text-slate-500">Trigger: <%= ad.trigger_condition %></div><% end %></td>
<td class="text-xs"><%= ad.recurring? ? [ad.recurring_hours.to_f > 0 && "#{hours(ad.recurring_hours)} h", ad.recurring_months > 0 && "#{ad.recurring_months} mo"].select(&:itself).join(" / ") : "One-time" %></td>
<td class="text-xs"><%= ad.recurring? ? [ad.recurring_hours.to_f > 0 && "#{hours(ad.recurring_hours)} h", ad.recurring_interval_label].select(&:itself).join(" / ") : "One-time" %></td>
<td class="text-xs"><%= row.latest ? "#{row.latest.date_complied}#{' (permanent)' if row.latest.permanent?}" : "—" %></td>
<td class="text-xs"><%= [row.next_due_date&.strftime("%b %Y"), row.next_due_hours && "#{hours(row.next_due_hours)} #{@aircraft.time_basis} (#{hours(row.next_due_hours - @aircraft.current_hours)} h left)"].compact.join(" / ").presence || "—" %></td>
<td><%= compliance_badge(row.status) %></td>
+4 -3
View File
@@ -28,12 +28,12 @@
<fieldset class="grid gap-4 sm:grid-cols-3">
<legend class="mb-2 text-sm font-semibold text-slate-900">Limits</legend>
<%= f.field :replacement_hours, as: :number, label: "Replace every (hrs)" %>
<%= f.field :replacement_days, as: :number, label: "Replace every (days)" %>
<%= f.interval :replacement, label: "Replace every" %>
<%= f.field :replacement_critical, as: :checkbox, label: "Replacement critical", hint: "Overdue replacement or expiry grounds the aircraft (oil, filters, ELT battery…)." %>
<%= f.field :expires_on, as: :date, label: "Expires on",
hint: "The date marked on the part, e.g. an ELT battery's replacement date (14 CFR 91.207(c): also replace it after 1 hour of cumulative use)." %>
<%= f.field :tbo_hours, as: :number, label: "TBO (hrs)" %>
<%= f.field :tbo_days, as: :number, label: "TBO (days)" %>
<%= f.interval :tbo, label: "TBO (calendar)" %>
<div class="space-y-2">
<%= f.field :tbo_critical, as: :checkbox, label: "Treat TBO as a hard limit",
hint: "Under Part 91, TBO is usually the manufacturer's recommendation, unless an AD or the Airworthiness Limitations make it mandatory." %>
@@ -41,7 +41,8 @@
hint: "Run past TBO based on condition: TBO is shown for reference, never as a limit (this overrides the hard limit)." %>
</div>
<%= f.field :inspection_hours, as: :number, label: "Inspect every (hrs)" %>
<%= f.field :inspection_days, as: :number, label: "Inspect every (days)" %>
<%= f.interval :inspection, label: "Inspect every",
hint: "Counted from the component's last service. If an inspection (Inspections tab) applies to this component, that inspection and its records govern and these are ignored." %>
<%= f.field :inspection_critical, as: :checkbox, label: "Inspection critical" %>
</fieldset>
+2 -2
View File
@@ -31,8 +31,8 @@
<td class="text-right tabular-nums"><%= hours(c.hours_in_service) %></td>
<td class="text-right tabular-nums"><%= hours(c.hours_since_overhaul) %></td>
<td class="text-xs text-slate-600">
<% if c.replacement_critical? && (c.replacement_hours || c.replacement_days) %>
Replace: <%= [c.replacement_hours && "#{c.replacement_hours} h", c.replacement_days && "#{c.replacement_days} d"].compact.join(" / ") %><br>
<% if c.replacement_critical? && (c.replacement_hours || c.replacement_calendar?) %>
Replace: <%= [c.replacement_hours && "#{c.replacement_hours} h", c.replacement_interval_label].compact.join(" / ") %><br>
<% end %>
<% if c.tbo_critical? && c.tbo_hours %>TBO: <%= c.tbo_hours %> h<%= " (on condition)" if c.on_condition? %><br><% end %>
<% if c.expires_on %>Expires: <%= fmt_date(c.expires_on) %><% end %>
+1 -1
View File
@@ -24,7 +24,7 @@
<dt class="text-slate-500">Since OH / service</dt><dd><%= hours(@component.hours_since_overhaul) %></dd>
<dt class="text-slate-500">TBO</dt><dd><%= @component.tbo_hours ? "#{@component.tbo_hours} h (#{hours(@component.hours_to_tbo)} remaining)" : "—" %></dd>
<dt class="text-slate-500">Replacement</dt><dd>
<%= [@component.replacement_hours && "#{@component.replacement_hours} h", @component.replacement_days && "#{@component.replacement_days} d"].compact.join(" / ").presence || "—" %>
<%= [@component.replacement_hours && "#{@component.replacement_hours} h", @component.replacement_interval_label].compact.join(" / ").presence || "—" %>
<% if (d = @component.next_replacement_date) %><div class="text-xs text-slate-500">Next by <%= fmt_date(d) %></div><% end %>
</dd>
<dt class="text-slate-500">Flags</dt>
+2 -2
View File
@@ -10,8 +10,8 @@
<%= f.field :recurring, as: :checkbox, label: "Recurring" %>
<div class="grid gap-4 sm:grid-cols-3">
<%= f.field :recurring_hours, as: :number, step: 0.1, label: "Every (hours)" %>
<%= f.field :recurring_months, as: :number, label: "Every (calendar months)", hint: "Due end of month." %>
<%= f.field :recurring_days, as: :number, label: "Every (days)" %>
<%= f.interval :recurring, label: "Every", wrapper: { class: "sm:col-span-2" },
hint: "Months and years are calendar months: due at the end of the month (an annual done March 10 is due by the end of next March)." %>
</div>
<div class="grid gap-4 sm:grid-cols-2">
<%= f.field :hours_tolerance, as: :number, step: 0.1, min: 0, label: "Overrun allowance (hours)",
+2 -2
View File
@@ -52,7 +52,7 @@
<tbody>
<% @report.life_limited.each do |c| %>
<tr><td class="<%= td %>"><%= c %> <span class="text-slate-500"><%= c.model %></span></td><td class="<%= td %>"><%= c.serial_number.presence || "—" %></td>
<td class="<%= td %>"><%= [ (c.replacement_hours && "#{hours(c.replacement_hours)} hrs"), (c.replacement_days && "#{c.replacement_days} days"), (c.expires_on && "expires #{fmt_date(c.expires_on)}") ].compact.join(" / ") %></td>
<td class="<%= td %>"><%= [ (c.replacement_hours && "#{hours(c.replacement_hours)} hrs"), c.replacement_interval_label, (c.expires_on && "expires #{fmt_date(c.expires_on)}") ].compact.join(" / ") %></td>
<td class="<%= td %> text-right tabular-nums"><%= hours(c.hours_since_overhaul) %> hrs</td>
<td class="<%= td %>"><%= [ (c.hours_to_replacement && "#{hours(c.hours_to_replacement)} hrs"), (c.next_replacement_date && "by #{fmt_date(c.next_replacement_date)}") ].compact.join(", ") %></td>
<td class="<%= td %>"><%= life_badge(c.life_status) %></td></tr>
@@ -70,7 +70,7 @@
<tbody>
<% @report.overhaul_items.each do |c| %>
<tr><td class="<%= td %>"><%= c %> <span class="text-slate-500"><%= c.model %></span></td><td class="<%= td %>"><%= c.serial_number.presence || "—" %></td>
<td class="<%= td %>"><%= [ (c.tbo_hours && "#{hours(c.tbo_hours)} hrs"), (c.tbo_days && "#{c.tbo_days} days") ].compact.join(" / ") %></td>
<td class="<%= td %>"><%= [ (c.tbo_hours && "#{hours(c.tbo_hours)} hrs"), c.tbo_interval_label ].compact.join(" / ") %></td>
<td class="<%= td %> text-right tabular-nums"><%= hours(c.hours_since_overhaul) %> hrs</td>
<td class="<%= td %>"><%= c.hours_to_tbo ? "#{hours(c.hours_to_tbo)} hrs" : "—" %></td>
<td class="<%= td %> text-xs"><%= c.on_condition? ? "On condition (Part 91)" : (c.tbo_critical? ? "Hard limit" : "Recommended") %></td></tr>
+1 -1
View File
@@ -18,7 +18,7 @@
</div>
</div>
</div>
<div class="flex w-full gap-2 sm:w-auto [&>*]:flex-1 [&>*]:justify-center sm:[&>*]:flex-none">
<div class="flex w-full gap-2 sm:w-auto [&>*]:flex-1 [&>*]:justify-center [&>*]:whitespace-nowrap max-sm:[&>*]:px-2 sm:[&>*]:flex-none">
<%= link_to "Log Flight", new_aircraft_flight_log_path(aircraft), class: "btn-primary" %>
<%= link_to "Report Squawk", new_aircraft_squawk_path(aircraft), class: "btn-secondary" %>
</div>
@@ -0,0 +1,34 @@
<%# The loading calculator (W&B tab). %>
<div class="card-body space-y-3" data-controller="wb-calculator"
data-wb-calculator-empty-weight-value="<%= record.empty_weight.to_f %>" data-wb-calculator-empty-moment-value="<%= record.empty_moment.to_f %>"
data-wb-calculator-max-gross-value="<%= record.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>
@@ -27,39 +27,7 @@
<% 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>
<%= render "weight_balance_records/calculator", record: @current, setup: setup %>
<% elsif !@current %>
<%= empty_state "Record the current weight & balance first." %>
<% else %>