mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Logbook: a new entry can mark its sub-components serviced or replaced on the Components tab, dated to the entry
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8bea2abf75
commit
87e30946fe
5 files changed
+53
-4
No files matched your search
@@ -37,6 +37,7 @@ class LogbookEntriesController < ApplicationController
|
|||||||
@entry.assign_parts(parts_params, @aircraft)
|
@entry.assign_parts(parts_params, @aircraft)
|
||||||
if @entry.save
|
if @entry.save
|
||||||
log_event("logbook", "Logbook entry #{@entry.supersedes ? 'correction ' : ''}added (#{@entry.date})")
|
log_event("logbook", "Logbook entry #{@entry.supersedes ? 'correction ' : ''}added (#{@entry.date})")
|
||||||
|
record_parts_service
|
||||||
redirect_to aircraft_logbook_entry_path(@aircraft, @entry),
|
redirect_to aircraft_logbook_entry_path(@aircraft, @entry),
|
||||||
notice: @entry.supersedes ? "Correction saved. Sign it to supersede the original entry." : "Logbook entry added."
|
notice: @entry.supersedes ? "Correction saved. Sign it to supersede the original entry." : "Logbook entry added."
|
||||||
else
|
else
|
||||||
@@ -88,7 +89,19 @@ class LogbookEntriesController < ApplicationController
|
|||||||
copy
|
copy
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sub-components ticked on the form: { component_id => { include, hours, since } }.
|
# Sub-components marked "Serviced" or "Replaced" on a new entry: recorded on
|
||||||
|
# the Components tab too, dated to the entry.
|
||||||
|
def record_parts_service
|
||||||
|
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")
|
||||||
|
log_event("component", "#{p['service'] == 'replaced' ? 'Replaced' : 'Serviced'}: #{component} (logbook entry #{@entry.date})")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Sub-components ticked on the form: { component_id => { include, hours, since, service } }.
|
||||||
def parts_params
|
def parts_params
|
||||||
params.fetch(:logbook_entry, {}).permit(parts: {})[:parts]&.to_h || {}
|
params.fetch(:logbook_entry, {}).permit(parts: {})[:parts]&.to_h || {}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -90,6 +90,16 @@ class Component < ApplicationRecord
|
|||||||
|
|
||||||
# Service reset: always zeroes time since overhaul; optionally the whole
|
# Service reset: always zeroes time since overhaul; optionally the whole
|
||||||
# in-service clock when the part was physically replaced.
|
# in-service clock when the part was physically replaced.
|
||||||
|
# Serviced (or replaced) as recorded in a logbook entry: dated to the entry,
|
||||||
|
# with the hours it has run since then (its total time now less its total
|
||||||
|
# time at the entry) as the new time since service.
|
||||||
|
def service_from_entry!(date:, hours_at_entry:, replaced: false)
|
||||||
|
since = hours_at_entry ? [ hours_in_service.to_d - hours_at_entry.to_d, 0 ].max : 0
|
||||||
|
attrs = { hours_since_overhaul: since, overhaul_date: date }
|
||||||
|
attrs.merge!(hours_in_service: since, date_in_service: date) if replaced
|
||||||
|
update!(attrs)
|
||||||
|
end
|
||||||
|
|
||||||
def reset_service!(reset_in_service: false)
|
def reset_service!(reset_in_service: false)
|
||||||
attrs = { hours_since_overhaul: 0, overhaul_date: Date.current }
|
attrs = { hours_since_overhaul: 0, overhaul_date: Date.current }
|
||||||
attrs.merge!(hours_in_service: 0, date_in_service: Date.current) if reset_in_service
|
attrs.merge!(hours_in_service: 0, date_in_service: Date.current) if reset_in_service
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
<% part = parts[c.id] %>
|
<% part = parts[c.id] %>
|
||||||
<% ancestors = c.ancestor_ids %>
|
<% ancestors = c.ancestor_ids %>
|
||||||
<% field = "#{f.object_name}[parts][#{c.id}]" %>
|
<% field = "#{f.object_name}[parts][#{c.id}]" %>
|
||||||
<div class="grid items-end gap-2 sm:grid-cols-[1fr_9rem_9rem]" data-component-times-target="part" data-ancestors="<%= ancestors.join(' ') %>"
|
<div class="grid items-end gap-2 <%= f.object.new_record? ? 'sm:grid-cols-[1fr_9rem_9rem_10rem]' : 'sm:grid-cols-[1fr_9rem_9rem]' %>" data-component-times-target="part" data-ancestors="<%= ancestors.join(' ') %>"
|
||||||
data-total="<%= c.hours_in_service.to_f %>" data-since="<%= c.hours_since_overhaul.to_f %>"
|
data-total="<%= c.hours_in_service.to_f %>" data-since="<%= c.hours_since_overhaul.to_f %>"
|
||||||
<%= "hidden" unless selected && ancestors.include?(selected.id) %>>
|
<%= "hidden" unless selected && ancestors.include?(selected.id) %>>
|
||||||
<label class="flex items-center gap-2 text-sm">
|
<label class="flex items-center gap-2 text-sm">
|
||||||
@@ -41,8 +41,13 @@
|
|||||||
<div><label class="text-xs text-slate-500" for="part_<%= c.id %>_since"><%= c.since_overhaul_abbreviation.capitalize %></label>
|
<div><label class="text-xs text-slate-500" for="part_<%= c.id %>_since"><%= c.since_overhaul_abbreviation.capitalize %></label>
|
||||||
<%= number_field_tag "#{field}[since]", part&.since_overhaul_at_entry, id: "part_#{c.id}_since", step: 0.1, class: "input",
|
<%= number_field_tag "#{field}[since]", part&.since_overhaul_at_entry, id: "part_#{c.id}_since", step: 0.1, class: "input",
|
||||||
data: { role: "since", action: "input->component-times#partEdited" } %></div>
|
data: { role: "since", action: "input->component-times#partEdited" } %></div>
|
||||||
|
<% if f.object.new_record? %>
|
||||||
|
<div><label class="text-xs text-slate-500" for="part_<%= c.id %>_service">On the Components tab</label>
|
||||||
|
<%= select_tag "#{field}[service]", options_for_select([ [ "Not changed", "" ], [ "Serviced", "serviced" ], [ "Replaced", "replaced" ] ], params.dig(:logbook_entry, :parts, c.id.to_s, :service)),
|
||||||
|
id: "part_#{c.id}_service", class: "input" %></div>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<p class="hint">Their times are worked out the same way as the component's. Sub-components are set up on the Components tab (a part's "Parent component").</p>
|
<p class="hint">Their times are worked out the same way as the component's. Sub-components are set up on the Components tab (a part's "Parent component").<%= " “Serviced” or “Replaced” also records it on the Components tab (e.g. an oil and filter change), dated to this entry." if f.object.new_record? %></p>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -8,7 +8,7 @@ The **Logbook** tab holds the maintenance record entries. Owners write and edit
|
|||||||
|
|
||||||
1. Choose a **Template** to start the wording if one fits, and fill in its blanks (`__`). The built-in ones are for a pilot doing preventive maintenance on an aircraft they own or operate (14 CFR 43.3(g)); admins can add their own.
|
1. Choose a **Template** to start the wording if one fits, and fill in its blanks (`__`). The built-in ones are for a pilot doing preventive maintenance on an aircraft they own or operate (14 CFR 43.3(g)); admins can add their own.
|
||||||
2. Fill in the date, the **logbook** (aircraft, engine, propeller or other), the **entry type** (usually maintenance or inspection) and the **airframe total time**.
|
2. Fill in the date, the **logbook** (aircraft, engine, propeller or other), the **entry type** (usually maintenance or inspection) and the **airframe total time**.
|
||||||
3. For an engine or propeller entry, pick the component: its total time and time since overhaul at the entry fill in from the airframe time. Tick any **sub-components** included in the work (an oil filter on the engine) to record their times as well.
|
3. For an engine or propeller entry, pick the component: its total time and time since overhaul at the entry fill in from the airframe time. Tick any **sub-components** included in the work (an oil filter on the engine) to record their times as well. On a new entry, set a sub-component to **Serviced** or **Replaced** to record that on the Components tab at the same time (an oil and filter change resets their time since service), dated to the entry.
|
||||||
4. Write the **entry text**: what was done, with reference to the data used.
|
4. Write the **entry text**: what was done, with reference to the data used.
|
||||||
5. The sign-off fields (who, certificate kind and number, location) are filled in when the entry is signed electronically. Fill them in yourself for an entry copied from a paper logbook.
|
5. The sign-off fields (who, certificate kind and number, location) are filled in when the entry is signed electronically. Fill them in yourself for an entry copied from a paper logbook.
|
||||||
6. For an inspection, record the **inspection result** (approved for return to service, or a list of discrepancies given to the owner).
|
6. For an inspection, record the **inspection result** (approved for return to service, or a list of discrepancies given to the owner).
|
||||||
|
|||||||
@@ -47,6 +47,27 @@ class LogbookEntryPartsTest < ActionDispatch::IntegrationTest
|
|||||||
assert_empty entry.parts.reload
|
assert_empty entry.parts.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "a new entry can record a sub-component as serviced or replaced on the Components tab" do
|
||||||
|
oil = create_component(@a, component_type: component_type("Oil"), manufacturer: "Phillips", model: "20W50",
|
||||||
|
parent_component: @engine, hours_in_service: 45.0, hours_since_overhaul: 45.0)
|
||||||
|
get new_aircraft_logbook_entry_path(@a)
|
||||||
|
assert_select "select[name='logbook_entry[parts][#{oil.id}][service]'] option", 3
|
||||||
|
post aircraft_logbook_entries_path(@a), params: { logbook_entry: entry_params(parts: {
|
||||||
|
@filter.id => { include: "1", hours: "110.5", since: "10.5", service: "serviced" },
|
||||||
|
oil.id => { include: "1", hours: "35.0", since: "35.0", service: "replaced" } }) }
|
||||||
|
assert_redirected_to aircraft_logbook_entry_path(@a, @a.logbook_entries.last)
|
||||||
|
@filter.reload
|
||||||
|
oil.reload
|
||||||
|
# dated to the entry; the 10 hours flown since the entry carry over
|
||||||
|
assert_equal [ Date.new(2026, 8, 20), 10.0, 120.5 ], [ @filter.overhaul_date, @filter.hours_since_overhaul.to_f, @filter.hours_in_service.to_f ]
|
||||||
|
assert_equal [ 10.0, 10.0, Date.new(2026, 8, 20) ], [ oil.hours_since_overhaul.to_f, oil.hours_in_service.to_f, oil.date_in_service ]
|
||||||
|
assert @a.events.exists?(event_name: "Replaced: #{oil} (logbook entry 2026-08-20)")
|
||||||
|
|
||||||
|
entry = @a.logbook_entries.last # editing doesn't offer it again (it would apply twice)
|
||||||
|
get edit_aircraft_logbook_entry_path(@a, entry)
|
||||||
|
assert_select "select[name='logbook_entry[parts][#{oil.id}][service]']", 0
|
||||||
|
end
|
||||||
|
|
||||||
test "printouts add a line per sub-component; archives carry them" do
|
test "printouts add a line per sub-component; archives carry them" do
|
||||||
entry = @a.logbook_entries.create!(entry_params.merge(component: @engine))
|
entry = @a.logbook_entries.create!(entry_params.merge(component: @engine))
|
||||||
entry.parts.create!(component: @filter, hours_at_entry: 110.5, since_overhaul_at_entry: 10.5)
|
entry.parts.create!(component: @filter, hours_at_entry: 110.5, since_overhaul_at_entry: 10.5)
|
||||||
|
|||||||
Reference in new issue
Block a user