mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Editable logbook templates; component times follow the airframe time
- Templates move to the database (Admin -> Logbook templates: add, edit, delete, restore the built-in ones). The built-in preventive maintenance set is added once on first use; deletions stick. A template can set the entry type, logbook (picking the matching component) and certificate - Template list shows "Name — Part 43 App. A (c)(6), (c)(23)" instead of the doubled parentheses - Component total time and time since overhaul are worked out from the entry's airframe total time (current times shifted by the difference); blank when the entry predates the overhaul; typing them stops the automatic updates Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a51f78ebf3
commit
72e1d7760f
22 files changed
+366
-74
No files matched your search
@@ -0,0 +1,37 @@
|
||||
# Wording to start a logbook entry from (Admin → Logbook templates). Picking
|
||||
# one on the entry form fills the text and, when set, the entry type, the
|
||||
# logbook and the kind of certificate.
|
||||
class LogbookTemplate < ApplicationRecord
|
||||
DEFAULTS_FILE = Rails.root.join("config/logbook_templates.yml")
|
||||
|
||||
validates :name, :text, presence: true
|
||||
validates :entry_type, inclusion: { in: LogbookEntry::ENTRY_TYPES.keys }
|
||||
validates :log_type, inclusion: { in: LogbookEntry::LOG_TYPES.keys }, allow_blank: true
|
||||
validates :certificate_type, inclusion: { in: LogbookEntry::CERTIFICATE_TYPES.keys }, allow_blank: true
|
||||
normalizes :log_type, :certificate_type, :reference, with: ->(v) { v.strip.presence }
|
||||
|
||||
scope :ordered, -> { order(:position, :name) }
|
||||
|
||||
def label = reference.present? ? "#{name} — #{reference}" : name
|
||||
|
||||
def self.defaults = YAML.safe_load_file(DEFAULTS_FILE)
|
||||
|
||||
# Adds the built-in templates that aren't here (matched by name). Returns
|
||||
# how many were added.
|
||||
def self.restore_defaults!
|
||||
existing = pluck(:name).to_set
|
||||
next_position = (maximum(:position) || 0) + 1
|
||||
added = defaults.reject { existing.include?(_1["name"]) }
|
||||
added.each_with_index { |d, i| create!(d.slice("name", "reference", "text", "log_type", "certificate_type").merge("position" => next_position + i)) }
|
||||
added.size
|
||||
end
|
||||
|
||||
# The built-in set, once: after that, admins' deletions stick.
|
||||
def self.ensure_defaults!
|
||||
return if Setting.integer("logbook_templates_seeded") == 1
|
||||
transaction do
|
||||
restore_defaults!
|
||||
Setting.update_integers("logbook_templates_seeded" => "1")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,37 +0,0 @@
|
||||
# Logbook wording for common preventive maintenance a pilot-owner may do
|
||||
# (14 CFR 43.3(g)), keyed to Part 43 Appendix A paragraph (c). The item
|
||||
# descriptions are paraphrased; the rule sets each item's limits.
|
||||
module PreventiveMaintenance
|
||||
Item = Data.define(:key, :paragraphs, :label, :work)
|
||||
|
||||
ITEMS = [
|
||||
Item.new("oil_change", %w[(c)(6) (c)(23)], "Oil and filter change", "Drained engine oil and replaced the oil filter. Cut open and inspected the filter: no metal found. Refilled with __ qt of __. Ran engine and checked for leaks."),
|
||||
Item.new("tire", %w[(c)(1)], "Tire removal, installation or repair", "Removed and replaced the __ tire and tube. Inflated to __ psi."),
|
||||
Item.new("strut", %w[(c)(3)], "Servicing landing gear shock struts", "Serviced the __ shock strut with __."),
|
||||
Item.new("bearings", %w[(c)(4)], "Servicing wheel bearings", "Cleaned, inspected and repacked the __ wheel bearings with __ grease."),
|
||||
Item.new("safety_wire", %w[(c)(5)], "Replacing safety wire or cotter keys", "Replaced defective safety wire / cotter key at __."),
|
||||
Item.new("lubrication", %w[(c)(6)], "Lubrication", "Lubricated __ per the maintenance manual."),
|
||||
Item.new("hydraulic", %w[(c)(8)], "Replenishing hydraulic fluid", "Replenished the hydraulic reservoir with __."),
|
||||
Item.new("upholstery", %w[(c)(11)], "Repairing upholstery", "Repaired the upholstery of __."),
|
||||
Item.new("fairings", %w[(c)(12)], "Small repairs to fairings or cowlings", "Made a small repair to the __ (non-structural, contour unchanged)."),
|
||||
Item.new("seat_belts", %w[(c)(14)], "Replacing safety belts", "Replaced the __ safety belt with P/N __."),
|
||||
Item.new("landing_light_wiring", %w[(c)(16)], "Repairing landing light circuits", "Troubleshot and repaired a broken circuit in the landing light wiring."),
|
||||
Item.new("lights", %w[(c)(17)], "Replacing light bulbs, reflectors or lenses", "Replaced the __ position/landing light bulb with P/N __. Checked operation."),
|
||||
Item.new("cowling", %w[(c)(19)], "Replacing a cowling", "Removed and reinstalled the __ cowling."),
|
||||
Item.new("spark_plugs", %w[(c)(20)], "Cleaning or replacing spark plugs", "Removed, cleaned, gapped and rotated the spark plugs. Reinstalled and torqued to __."),
|
||||
Item.new("hoses", %w[(c)(21)], "Replacing hose connections (not hydraulic)", "Replaced the __ hose with P/N __."),
|
||||
Item.new("fuel_lines", %w[(c)(22)], "Replacing prefabricated fuel lines", "Replaced the prefabricated fuel line __ with P/N __."),
|
||||
Item.new("filters", %w[(c)(23)], "Cleaning or replacing fuel/oil strainers or filters", "Cleaned / replaced the __ strainer / filter element."),
|
||||
Item.new("battery", %w[(c)(24)], "Replacing or servicing the battery", "Replaced the battery with P/N __ / serviced the battery."),
|
||||
Item.new("fasteners", %w[(c)(26)], "Replacing non-structural fasteners", "Replaced non-structural standard fasteners at __."),
|
||||
Item.new("chip_detector", %w[(c)(29)], "Checking magnetic chip detectors", "Removed, checked and reinstalled the magnetic chip detector: no particles found."),
|
||||
Item.new("nav_database", %w[(c)(31)], "Updating the navigation database", "Updated the __ navigation database to cycle __."),
|
||||
Item.new("nav_com", %w[(c)(32)], "Swapping a tray-mounted nav/com unit", "Removed and reinstalled the tray-mounted __ unit. Checked operation.")
|
||||
].freeze
|
||||
|
||||
module_function
|
||||
|
||||
def text_for(item)
|
||||
"#{item.work} Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph #{item.paragraphs.to_sentence}."
|
||||
end
|
||||
end
|
||||
@@ -6,7 +6,8 @@
|
||||
# Setting.max_upload_bytes # => 52428800
|
||||
class Setting < ApplicationRecord
|
||||
INTEGERS = {
|
||||
"max_upload_mb" => { default: 50, in: 1..1024, label: "Maximum upload size (MB)" }
|
||||
"max_upload_mb" => { default: 50, in: 1..1024, label: "Maximum upload size (MB)" },
|
||||
"logbook_templates_seeded" => { default: 0, in: 0..1, label: "Built-in logbook templates added" } # internal flag
|
||||
}.freeze
|
||||
|
||||
validates :key, presence: true, uniqueness: true, inclusion: { in: INTEGERS.keys }
|
||||
|
||||
Reference in new issue
Block a user