mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15: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)
|
||||
if @entry.save
|
||||
log_event("logbook", "Logbook entry #{@entry.supersedes ? 'correction ' : ''}added (#{@entry.date})")
|
||||
record_parts_service
|
||||
redirect_to aircraft_logbook_entry_path(@aircraft, @entry),
|
||||
notice: @entry.supersedes ? "Correction saved. Sign it to supersede the original entry." : "Logbook entry added."
|
||||
else
|
||||
@@ -88,7 +89,19 @@ class LogbookEntriesController < ApplicationController
|
||||
copy
|
||||
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
|
||||
params.fetch(:logbook_entry, {}).permit(parts: {})[:parts]&.to_h || {}
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user