mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
2026.11.1: offline flight logging fixed, inspections from logbook entries, life limits from installation, component inspections moved to inspection types
- Service worker keeps the Log Flight form when opened via Turbo, serves the offline page's script and icon, and treats 502/503/504 as offline; the offline page only links forms actually kept - Serviced sub-components restart from the airframe time flown since the entry - New logbook entries can complete inspections (recorded and linked to the entry) - Components: replacement limit can count from installation (life limit) - Component-level "Inspect every" / "Inspection critical" removed; a migration converts any unlinked settings into inspection types with a first record; component page lists its inspections Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7552e4a8a3
commit
352a38c7fb
28 files changed
+289
-69
No files matched your search
@@ -23,6 +23,8 @@ class ComponentsController < ApplicationController
|
||||
|
||||
def show
|
||||
@squawks = @component.squawks.by_priority.with_attached_attachments
|
||||
ids = @component.inspection_type_ids
|
||||
@inspection_rows = Compliance.inspection_rows(@aircraft).select { ids.include?(_1.type.id) }
|
||||
end
|
||||
|
||||
def new
|
||||
@@ -76,10 +78,8 @@ class ComponentsController < ApplicationController
|
||||
params.require(:component).permit(
|
||||
: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, :replacement_every, :replacement_unit, :tbo_every, :tbo_unit,
|
||||
:inspection_every, :inspection_unit, :tbo_critical, :on_condition,
|
||||
:inspection_critical, :replacement_critical, :expires_on
|
||||
:hours_since_overhaul, :overhaul_date, :overhaul_kind, :tbo_hours, :tbo_days, :replacement_hours, :replacement_days, :replacement_every, :replacement_unit, :tbo_every, :tbo_unit,
|
||||
:tbo_critical, :on_condition, :replacement_critical, :replacement_from_install, :expires_on
|
||||
).tap do |p|
|
||||
# Owners can create a component type inline instead of asking an admin.
|
||||
if (name = params[:new_component_type].to_s.strip).present?
|
||||
|
||||
@@ -11,6 +11,11 @@ class InspectionTypesController < ApplicationController
|
||||
@inspection_type.name = "ICA: #{@major_record.title}".first(120)
|
||||
@applies_to_airframe = @major_record.component.nil?
|
||||
@inspection_type.components = [ @major_record.component ] if @major_record.component
|
||||
elsif (component = @aircraft.components.find_by(id: params[:component_id]))
|
||||
# From a component's page: applies to that part, e.g. "Magneto 500-hour inspection".
|
||||
@inspection_type.name = "#{component} inspection"
|
||||
@inspection_type.components = [ component ]
|
||||
@applies_to_airframe = false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ class LogbookEntriesController < ApplicationController
|
||||
if @entry.save
|
||||
log_event("logbook", "Logbook entry #{@entry.supersedes ? 'correction ' : ''}added (#{@entry.date})")
|
||||
record_parts_service
|
||||
record_inspections
|
||||
redirect_to aircraft_logbook_entry_path(@aircraft, @entry),
|
||||
notice: @entry.supersedes ? "Correction saved. Sign it to supersede the original entry." : "Logbook entry added."
|
||||
else
|
||||
@@ -92,15 +93,27 @@ class LogbookEntriesController < ApplicationController
|
||||
# Sub-components marked "Serviced" or "Replaced" on a new entry: recorded on
|
||||
# the Components tab too, dated to the entry.
|
||||
def record_parts_service
|
||||
flown = (@aircraft.current_hours - @entry.aircraft_hours_at_entry if @entry.aircraft_hours_at_entry)
|
||||
parts_params.each do |id, p|
|
||||
next unless p["include"] == "1" && %w[serviced replaced].include?(p["service"])
|
||||
part = @entry.parts.find { _1.component_id == id.to_i } or next
|
||||
component = part.component
|
||||
component.service_from_entry!(date: @entry.date, hours_at_entry: part.hours_at_entry, replaced: p["service"] == "replaced")
|
||||
component.service_from_entry!(date: @entry.date, hours_at_entry: part.hours_at_entry, flown_since: flown, replaced: p["service"] == "replaced")
|
||||
log_event("component", "#{p['service'] == 'replaced' ? 'Replaced' : 'Serviced'}: #{component} (logbook entry #{@entry.date})")
|
||||
end
|
||||
end
|
||||
|
||||
# Inspections ticked on a new entry (e.g. Oil Change): done at the entry's
|
||||
# date and airframe time, linked to it.
|
||||
def record_inspections
|
||||
ids = Array(params.dig(:logbook_entry, :inspection_type_ids)).compact_blank
|
||||
@aircraft.applicable_inspection_types.where(id: ids).find_each do |type|
|
||||
@aircraft.inspection_records.create!(inspection_type: type, logbook_entry: @entry, date: @entry.date,
|
||||
aircraft_hours: @entry.aircraft_hours_at_entry)
|
||||
log_event("inspection", "Inspection completed: #{type.name} (logbook entry #{@entry.date})")
|
||||
end
|
||||
end
|
||||
|
||||
# Sub-components ticked on the form: { component_id => { include, hours, since, service } }.
|
||||
def parts_params
|
||||
params.fetch(:logbook_entry, {}).permit(parts: {})[:parts]&.to_h || {}
|
||||
|
||||
Reference in new issue
Block a user