mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Confirm Update Hours and say what changed
- Updating the meters without a flight asks first, showing each reading's change, that every in-service component moves and no flight is logged, and a warning when a reading goes down; unchanged readings aren't sent - The flash lists each changed reading (old -> new, difference) and how far the components moved; a lowered reading is labelled a correction Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f534541467
commit
cce1ce51b5
5 files changed
+75
-8
No files matched your search
@@ -52,10 +52,9 @@ class AircraftController < ApplicationController
|
||||
|
||||
# Pilots and above: set absolute tach/hobbs readings.
|
||||
def update_hours
|
||||
delta = HoursService.new(@aircraft).update_hours!(
|
||||
tach_time: params.require(:tach_time), hobbs_time: params[:hobbs_time]
|
||||
)
|
||||
redirect_to @aircraft, notice: t("flash.aircraft.hours_updated", delta: "#{'+' if delta >= 0}#{delta}")
|
||||
before = { tach: @aircraft.tach_time.to_d, hobbs: @aircraft.hobbs_time.to_d }
|
||||
HoursService.new(@aircraft).update_hours!(tach_time: params.require(:tach_time), hobbs_time: params[:hobbs_time])
|
||||
redirect_to @aircraft, notice: hours_notice(before)
|
||||
rescue AircraftGroundedError => e
|
||||
redirect_to @aircraft, alert: e.message
|
||||
rescue ArgumentError
|
||||
@@ -64,6 +63,19 @@ class AircraftController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
# "Tach 4,211.6 → 4,213.0 (+1.4). In-service components moved +1.4 hrs; no flight was logged."
|
||||
def hours_notice(before)
|
||||
after = { tach: @aircraft.tach_time.to_d, hobbs: @aircraft.hobbs_time.to_d }
|
||||
signed = ->(d) { "#{d.negative? ? '−' : '+'}#{helpers.hours(d.abs)}" }
|
||||
changes = %i[tach hobbs].filter_map do |meter|
|
||||
d = after[meter] - before[meter]
|
||||
t("flash.aircraft.meter_changed", meter: Aircraft::TIME_BASES[meter.to_s], from: helpers.hours(before[meter]), to: helpers.hours(after[meter]), delta: signed.(d)) unless d.zero?
|
||||
end
|
||||
moved = @aircraft.hobbs? ? after[:hobbs] - before[:hobbs] : after[:tach] - before[:tach]
|
||||
return t("flash.aircraft.hours_unchanged") if changes.empty?
|
||||
t(moved.negative? ? "flash.aircraft.hours_corrected" : "flash.aircraft.hours_updated", changes: changes.join(" · "), delta: signed.(moved))
|
||||
end
|
||||
|
||||
def aircraft_param = params[:id]
|
||||
|
||||
def aircraft_params
|
||||
|
||||
Reference in new issue
Block a user