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

+3
View File
@@ -14,6 +14,9 @@ class AircraftController < ApplicationController
@notes = @aircraft.notes.recent_first.includes(:user).limit(5)
@oil = ConsumptionStats.new(@aircraft, "oil")
@fuel = ConsumptionStats.new(@aircraft, "fuel")
@coming_due = DueList.new(@aircraft).soon
last = @aircraft.flight_logs.recent_first.first
@last_day = last && @aircraft.flight_logs.where(date: last.date).order(:created_at).to_a
end
def new
@@ -68,7 +68,7 @@ class AirworthinessDirectivesController < ApplicationController
def ad_params
p = params.require(:airworthiness_directive).permit(
:name, :short_description, :required_action, :compliance_type, :trigger_condition, :recurring,
:recurring_hours, :recurring_months, :recurring_days, :bulletin_type, :mandatory, :document_id, :document_url
:recurring_hours, :recurring_months, :recurring_days, :recurring_every, :recurring_unit, :bulletin_type, :mandatory, :document_id, :document_url
)
p[:document_id] = scoped_id(@aircraft.documents, p[:document_id])
p
+2 -1
View File
@@ -77,7 +77,8 @@ class ComponentsController < ApplicationController
:component_type_id, :parent_component_id, :manufacturer, :model, :serial_number,
:install_location, :notes, :status, :date_in_service, :hours_in_service,
:hours_since_overhaul, :overhaul_date, :overhaul_kind, :tbo_hours, :tbo_days, :inspection_hours,
:inspection_days, :replacement_hours, :replacement_days, :tbo_critical, :on_condition,
:inspection_days, :replacement_hours, :replacement_days, :replacement_every, :replacement_unit, :tbo_every, :tbo_unit,
:inspection_every, :inspection_unit, :tbo_critical, :on_condition,
:inspection_critical, :replacement_critical, :expires_on
).tap do |p|
# Owners can create a component type inline instead of asking an admin.
@@ -68,7 +68,7 @@ class InspectionTypesController < ApplicationController
def type_params
p = params.require(:inspection_type).permit(:name, :recurring, :effect, :hours_tolerance, :satisfies_id,
:recurring_hours, :recurring_days, :recurring_months)
:recurring_hours, :recurring_days, :recurring_months, :recurring_every, :recurring_unit)
p[:satisfies_id] = scoped_id(@aircraft.applicable_inspection_types, p[:satisfies_id]) if p.key?(:satisfies_id)
p
end
+17
View File
@@ -39,6 +39,23 @@ class AppFormBuilder < ActionView::Helpers::FormBuilder
end
end
# A calendar interval: a number and a days / months / years choice
# (see CalendarInterval).
# <%= f.interval :replacement, label: "Replace every" %>
def interval(name, label:, hint: nil, wrapper: {})
every = :"#{name}_every"
errors = object.errors[every]
@template.content_tag(:div, class: wrapper[:class]) do
label(every, label, class: "label") +
@template.content_tag(:div, class: "flex gap-2") do
number_field(every, class: "input min-w-0 flex-1", min: 1, step: 1, inputmode: "numeric") +
select(:"#{name}_unit", CalendarInterval::UNITS.invert, {}, class: "input w-auto", "aria-label": "#{label} unit")
end +
(hint ? @template.content_tag(:p, hint, class: "hint") : "".html_safe) +
errors.map { |e| @template.content_tag(:p, "#{label} #{e}", class: "field-error") }.join.html_safe
end
end
def errors_summary
return "".html_safe unless object&.errors&.any?
@template.content_tag(:div, class: "rounded-md bg-red-50 p-3 text-sm text-red-700 ring-1 ring-red-200") do
@@ -15,8 +15,10 @@ export default class extends Controller {
let moment = this.emptyMomentValue
let fuelArmMoment = 0
let fuelGallons = 0
let loaded = false
this.stationTargets.forEach((input) => {
const qty = parseFloat(input.value) || 0
if (qty > 0) loaded = true
const arm = parseFloat(input.dataset.arm)
const fuel = input.dataset.fuel === "true"
const max = parseFloat(input.dataset.max) || 0
@@ -39,6 +41,11 @@ export default class extends Controller {
this.show("takeoff", takeoff)
this.show("landing", landing)
if (!loaded) {
this.messagesTarget.replaceChildren(Object.assign(document.createElement("li"), { className: "text-slate-500", textContent: "Enter the loading to check weight and CG." }))
this.draw(takeoff, landing)
return
}
if (this.maxGrossValue && takeoff.weight > this.maxGrossValue) {
messages.push([ "bad", `Takeoff weight is ${(takeoff.weight - this.maxGrossValue).toFixed(1)} lb over the maximum of ${this.maxGrossValue} lb.` ])
}
+5 -2
View File
@@ -6,6 +6,9 @@ class AirworthinessDirective < ApplicationRecord
}.freeze
BULLETIN_LABELS = { "ad" => "AD", "saib" => "SAIB", "sb" => "SB", "alert" => "Alert", "other" => "Bulletin" }.freeze
include CalendarInterval
calendar_interval :recurring, days: :recurring_days, months: :recurring_months, blank: 0
belongs_to :document, optional: true
include SharedRecordHistory # has_and_belongs_to_many :aircraft and :components, with history
has_many :ad_compliances, dependent: :destroy
@@ -45,9 +48,9 @@ class AirworthinessDirective < ApplicationRecord
def conditional? = compliance_type == "conditional"
def bulletin_label = BULLETIN_LABELS[bulletin_type]
# Recurrence rule for next-due math (AD status uses hours and months).
# Recurrence rule for next-due math.
def due_rule
{ hours: recurring_hours.to_f, months: recurring_months, days: 0 } if recurring?
{ hours: recurring_hours.to_f, months: recurring_months, days: recurring_days } if recurring?
end
def latest_compliance_for(aircraft)
+6 -1
View File
@@ -1,10 +1,15 @@
class Component < ApplicationRecord
include Versioned
include CalendarInterval
STATUSES = { "SPARE" => "Spare Part", "IN-USE" => "In Service", "DISPOSED" => "Disposed" }.freeze
# What "since overhaul" counts from, and how logbooks abbreviate it.
OVERHAUL_KINDS = { "major" => "Major overhaul", "factory_overhaul" => "Factory overhaul", "factory_new" => "Factory new or rebuilt (zero time)" }.freeze
OVERHAUL_ABBREVIATIONS = { "major" => "SMOH", "factory_overhaul" => "SFOH", "factory_new" => "SNEW" }.freeze
calendar_interval :replacement, days: :replacement_days, months: :replacement_months
calendar_interval :tbo, days: :tbo_days, months: :tbo_months
calendar_interval :inspection, days: :inspection_days, months: :inspection_months
belongs_to :aircraft, optional: true
belongs_to :parent_component, class_name: "Component", optional: true
belongs_to :component_type
@@ -66,7 +71,7 @@ class Component < ApplicationRecord
def expired?(today = Date.current) = expires_on.present? && today > expires_on
def next_replacement_date
overhaul_date + replacement_days.days if replacement_days && overhaul_date
replacement_after(overhaul_date)
end
# :overdue / :due_soon / :ok / nil (not tracked) for display on the components tab.
+77
View File
@@ -0,0 +1,77 @@
# A calendar interval entered as a number and a unit (days, months or years)
# and stored in a days column and a months column (years as 12 months); one
# of the two is used.
#
# calendar_interval :replacement, days: :replacement_days, months: :replacement_months
#
# gives replacement_every / replacement_unit (for the form), and
# replacement_interval_label ("1 year", "6 months", "90 days").
module CalendarInterval
extend ActiveSupport::Concern
UNITS = { "days" => "days", "months" => "months", "years" => "years" }.freeze
# [count, unit] for display, from the stored columns.
def self.split(days, months)
months = months.to_i
days = days.to_i
if months.positive? then months % 12 == 0 ? [ months / 12, "years" ] : [ months, "months" ]
elsif days.positive? then [ days, "days" ]
end
end
def self.label(days, months)
count, unit = split(days, months)
count && "#{count} #{count == 1 ? unit.singularize : unit}"
end
class_methods do
# blank: what an empty interval is stored as (nil, or 0 for NOT NULL columns).
def calendar_interval(name, days:, months:, blank: nil)
every_ivar = :"@#{name}_every"
unit_ivar = :"@#{name}_unit"
define_method(:"#{name}_every") do
instance_variable_defined?(every_ivar) ? instance_variable_get(every_ivar) : CalendarInterval.split(self[days], self[months])&.first
end
define_method(:"#{name}_unit") do
(instance_variable_get(unit_ivar) if instance_variable_defined?(unit_ivar)) ||
CalendarInterval.split(self[days], self[months])&.last || "months"
end
define_method(:"#{name}_every=") { |v| instance_variable_set(every_ivar, v) }
define_method(:"#{name}_unit=") { |v| instance_variable_set(unit_ivar, v) }
define_method(:"#{name}_interval_label") { CalendarInterval.label(self[days], self[months]) }
define_method(:"#{name}_calendar?") { self[months].to_i.positive? || self[days].to_i.positive? }
# The date one interval after `date`: months to the same day (or the
# month's last day), days added.
define_method(:"#{name}_after") do |date|
if date.nil? then nil
elsif self[months].to_i.positive? then date >> self[months].to_i
elsif self[days].to_i.positive? then date + self[days].to_i
end
end
# Store the entered interval; a bad number leaves the columns alone and
# is reported by the validation below.
before_validation do
next unless instance_variable_defined?(every_ivar)
raw = instance_variable_get(every_ivar).to_s.strip
count = Integer(raw, 10, exception: false)
unit = public_send(:"#{name}_unit")
if raw.empty?
self[days] = blank
self[months] = blank
elsif count&.positive? && UNITS.key?(unit)
self[days] = unit == "days" ? count : blank
self[months] = { "months" => count, "years" => count * 12 }.fetch(unit, blank)
end
end
validate do
next unless instance_variable_defined?(every_ivar)
raw = instance_variable_get(every_ivar).to_s.strip
next if raw.empty? || Integer(raw, 10, exception: false)&.positive?
errors.add(:"#{name}_every", "must be a whole number more than 0")
end
end
end
end
+4 -1
View File
@@ -12,6 +12,8 @@ class InspectionType < ApplicationRecord
# Short form for the airworthiness status ("VFR only").
LIMITATIONS = { "no_ifr" => "VFR only", "no_transponder" => "No transponder" }.freeze
include CalendarInterval
calendar_interval :recurring, days: :recurring_days, months: :recurring_months, blank: 0
include SharedRecordHistory # has_and_belongs_to_many :aircraft and :components, with history
has_many :inspection_records, dependent: :destroy
belongs_to :satisfies, class_name: "InspectionType", optional: true
@@ -54,7 +56,8 @@ class InspectionType < ApplicationRecord
return "One-time" unless recurring?
parts = []
parts << "#{recurring_hours.to_s.sub(/\.0\z/, '')} hrs" if recurring_hours.to_f > 0
parts << "#{recurring_months} months" if recurring_months > 0
parts << recurring_interval_label if recurring_months > 0 && recurring_days.zero?
parts << "#{recurring_months} months" if recurring_months > 0 && recurring_days > 0
parts << "#{recurring_days} days" if recurring_days > 0
parts.any? ? "Every #{parts.join(' / ')}" : "Recurring"
end
+2 -1
View File
@@ -146,7 +146,8 @@ module AircraftArchive
expires_on: c.expires_on&.iso8601, notes: c.notes, status: c.status, date_in_service: c.date_in_service&.iso8601, hours_in_service: dec(c.hours_in_service),
hours_since_overhaul: dec(c.hours_since_overhaul), overhaul_date: c.overhaul_date&.iso8601, tbo_hours: c.tbo_hours,
tbo_days: c.tbo_days, inspection_hours: c.inspection_hours, inspection_days: c.inspection_days,
replacement_hours: c.replacement_hours, replacement_days: c.replacement_days, tbo_critical: c.tbo_critical,
replacement_hours: c.replacement_hours, replacement_days: c.replacement_days,
replacement_months: c.replacement_months, tbo_months: c.tbo_months, inspection_months: c.inspection_months, tbo_critical: c.tbo_critical,
on_condition: c.on_condition, inspection_critical: c.inspection_critical, replacement_critical: c.replacement_critical }
end
+2 -1
View File
@@ -215,7 +215,8 @@ module AircraftArchive
status: Component::STATUSES.key?(data["status"]) ? data["status"] : "SPARE",
date_in_service: date(data["date_in_service"]) || Date.new(1900, 1, 1), hours_in_service: num(data["hours_in_service"]) || 0,
hours_since_overhaul: num(data["hours_since_overhaul"]) || 0, overhaul_date: date(data["overhaul_date"]),
**data.slice(*%w[tbo_hours tbo_days inspection_hours inspection_days replacement_hours replacement_days]).symbolize_keys,
**data.slice(*%w[tbo_hours tbo_days inspection_hours inspection_days replacement_hours replacement_days
tbo_months inspection_months replacement_months]).symbolize_keys,
**data.slice(*%w[tbo_critical on_condition inspection_critical replacement_critical]).transform_values { _1 == true }.symbolize_keys
)
c.save!(validate: false)
+1 -1
View File
@@ -158,7 +158,7 @@ class Airworthiness
if c.replacement_critical? && (due = c.next_replacement_date)
if @today >= due
overdue = true
desc = "Replace every #{c.replacement_days} days. Last serviced #{c.overhaul_date}."
desc = "Replace every #{c.replacement_interval_label}. Last serviced #{c.overhaul_date}."
elsif @today + DAYS_WARNING >= due
approaching = true
desc = "Replace in #{(due - @today).to_i} days."
+2 -2
View File
@@ -51,8 +51,8 @@ module Compliance
end
end
if ad.recurring? && ad.recurring_months.positive?
due = end_of_month_after(compliance.date_complied, ad.recurring_months)
if ad.recurring? && ad.recurring_calendar?
due = next_due(ad.due_rule, date: compliance.date_complied, hours: nil)[:date]
result.next_due_date = due
if today > due
rank = OVERDUE
+25 -9
View File
@@ -3,11 +3,16 @@
# Items due by hours get a projected date from the aircraft's flying over
# the past year. Used by the calendar feed.
class DueList
Item = Data.define(:key, :title, :date, :projected, :due_hours, :kind, :path) do
def overdue?(today = Date.current) = date < today
# past_hours: the hours have already run out (the date is then today).
Item = Data.define(:key, :title, :date, :projected, :due_hours, :kind, :path, :past_hours) do
def overdue?(today = Date.current) = past_hours || date < today
end
# Hours flown per day over the past year (nil when it hasn't flown).
# What counts as coming up soon (Overview).
SOON_DAYS = 30
SOON_HOURS = 10
def self.daily_rate(aircraft, today: Date.current)
hours = aircraft.flight_logs.where(date: (today - 365)..today).sum(:tach_time).to_f
hours.positive? ? hours / 365.0 : nil
@@ -25,6 +30,13 @@ class DueList
(inspections + ads + components + documents).compact.sort_by { [ _1.date, _1.title ] }
end
# Due in the next SOON_DAYS days or SOON_HOURS hours (or overdue).
def soon
horizon = @today + SOON_DAYS
hours_limit = @now_hours + SOON_HOURS
items.select { |i| i.date <= horizon || (i.due_hours && i.due_hours <= hours_limit) }
end
private
# The date it's due: the calendar date, or when the hours run out at the
@@ -35,7 +47,8 @@ class DueList
use = [ date, projected ].compact.min
return unless use
Item.new(key: key, title: title, date: use, projected: use == projected && projected != date, kind: kind, path: path,
due_hours: hours_left ? (@now_hours + hours_left.to_d).round(1) : nil)
due_hours: hours_left ? (@now_hours + hours_left.to_d).round(1) : nil,
past_hours: !hours_left.nil? && hours_left.negative? && use == projected)
end
def hours_left(due_hours) = due_hours ? due_hours.to_d - @now_hours : nil
@@ -55,20 +68,23 @@ class DueList
end
end
# A component's own "Inspect every" counts from its last service; when an
# inspection type covers the component, that inspection (tracked from its
# records, under inspections) governs instead.
def components
@aircraft.components.in_use.includes(:component_type).flat_map do |c|
@aircraft.components.in_use.includes(:component_type, :inspection_types).flat_map do |c|
label = "#{c} #{c.model}".strip
path = @urls.aircraft_component_path(@aircraft, c)
since_service = c.hours_since_overhaul.to_d
[
(item("replace-#{c.id}", "Replace #{label}", "component", path, date: c.next_replacement_date,
hours_left: c.replacement_hours && c.replacement_hours - since_service) if c.replacement_hours || c.replacement_days),
hours_left: c.replacement_hours && c.replacement_hours - since_service) if c.replacement_hours || c.replacement_calendar?),
(item("tbo-#{c.id}", "#{label} reaches TBO", "component", path,
date: c.tbo_days && c.overhaul_date ? c.overhaul_date + c.tbo_days : nil,
hours_left: c.tbo_hours && c.tbo_hours - since_service) if (c.tbo_hours || c.tbo_days) && !c.on_condition?),
date: c.tbo_after(c.overhaul_date),
hours_left: c.tbo_hours && c.tbo_hours - since_service) if (c.tbo_hours || c.tbo_calendar?) && !c.on_condition?),
(item("inspect-#{c.id}", "Inspect #{label}", "component", path,
date: c.inspection_days && c.overhaul_date ? c.overhaul_date + c.inspection_days : nil,
hours_left: c.inspection_hours && c.inspection_hours - since_service) if c.inspection_hours || c.inspection_days),
date: c.inspection_after(c.overhaul_date),
hours_left: c.inspection_hours && c.inspection_hours - since_service) if (c.inspection_hours || c.inspection_calendar?) && c.inspection_types.empty?),
(item("expires-#{c.id}", "#{label} expires", "component", path, date: c.expires_on) if c.expires_on)
]
end
+2 -2
View File
@@ -17,12 +17,12 @@ class MaintenanceReport
# Parts with a mandatory replacement time (life limits).
def life_limited
in_use.select { |c| (c.replacement_critical? && (c.replacement_hours || c.replacement_days)) || c.expires_on }
in_use.select { |c| (c.replacement_critical? && (c.replacement_hours || c.replacement_calendar?)) || c.expires_on }
end
# Items overhauled on a time basis.
def overhaul_items
in_use.select { |c| c.tbo_hours || c.tbo_days }
in_use.select { |c| c.tbo_hours || c.tbo_calendar? }
end
def inspections = @inspections ||= Compliance.inspection_rows(aircraft)
+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 %>