diff --git a/README.md b/README.md index 01c0e77..846a48c 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ To back up or move a single aircraft with all its files, use **Access & Sharing | New ADs | Weekly search of the Federal Register for newly published ADs mentioning the aircraft, engine or propeller models (or your own terms). Review each: track it as an AD or dismiss it. | | AD import | Import ADs from an FAA DRS export (`.xlsx` recommended: its AD numbers link to each AD's DRS page, which the import keeps; `.csv` works without links). ADs are matched by number, so nothing is duplicated. The preview suggests Track, Not applicable or Skip for each AD, and flags superseded or non-current ADs, model mismatches, appliance or STC-only ADs, and repetitive actions. | | Inspections | Shared inspection types with hour, month, and day recurrence, plus history. Each says what overdue means (grounded, no IFR, no transponder, advisory); an annual can also count as the 100-hour, and the 100-hour's 10-hour overrun is credited (91.409(b)). One click adds the standard Part 91 set. | -| Logbook | Maintenance entries with search and a link to a scanned document page. Records the signer's certificate kind and number and an inspection's result, and flags what 43.9 / 43.11 needs that's missing. Entries transcribed by Claude stay "unverified" until someone checks them against the scan. Templates for pilot preventive maintenance (43.3(g), Part 43 Appendix A(c)). Engine and propeller entries link the component and record its total time and time since overhaul (SMOH/SFOH/SNEW) at the entry. Print entries as a PDF on Avery 5163/5164 labels or half-letter/letter pages (boxed) to sign and put in the paper logbook. | +| Logbook | Maintenance entries with search and a link to a scanned document page. Records the signer's certificate kind and number and an inspection's result, and flags what 43.9 / 43.11 needs that's missing. Entries transcribed by Claude stay "unverified" until someone checks them against the scan. Entry templates (built-in pilot preventive maintenance per 43.3(g) and Part 43 Appendix A(c); admins add and edit their own under Admin → Logbook templates). Engine and propeller entries link the component and record its total time and time since overhaul (SMOH/SFOH/SNEW) at the entry, worked out from the entry's airframe total time. Print entries as a PDF on Avery 5163/5164 labels or half-letter/letter pages (boxed) to sign and put in the paper logbook. | | Documents | Collections, multi-file documents with a page viewer, per-document share visibility, bulk upload, and expiration dates (registration, insurance…). | | Major repairs and alterations | Form 337, STC, and ICA tracking; an STC's ICA can become a tracked recurring inspection. | | Weight & balance | History of empty weight and CG (linked to the alteration that changed them) and a loading calculator: takeoff and landing weight and CG against max gross and the CG envelope. | diff --git a/app/controllers/admin/logbook_templates_controller.rb b/app/controllers/admin/logbook_templates_controller.rb new file mode 100644 index 0000000..a90b1d2 --- /dev/null +++ b/app/controllers/admin/logbook_templates_controller.rb @@ -0,0 +1,48 @@ +class Admin::LogbookTemplatesController < ApplicationController + before_action :require_admin! + before_action :set_template, only: %i[edit update destroy] + + def index + LogbookTemplate.ensure_defaults! + @templates = LogbookTemplate.ordered + end + + def new + @template = LogbookTemplate.new(position: (LogbookTemplate.maximum(:position) || 0) + 1) + end + + def create + @template = LogbookTemplate.new(template_params) + if @template.save + redirect_to admin_logbook_templates_path, notice: "Template added." + else + render :new, status: :unprocessable_entity + end + end + + def edit; end + + def update + if @template.update(template_params) + redirect_to admin_logbook_templates_path, notice: "Template updated." + else + render :edit, status: :unprocessable_entity + end + end + + def destroy + @template.destroy! + redirect_to admin_logbook_templates_path, notice: "Template deleted." + end + + def restore + added = LogbookTemplate.restore_defaults! + redirect_to admin_logbook_templates_path, notice: added.positive? ? "Restored #{helpers.pluralize(added, 'built-in template')}." : "All the built-in templates are already here." + end + + private + + def set_template = @template = LogbookTemplate.find(params[:id]) + + def template_params = params.require(:logbook_template).permit(:name, :reference, :text, :entry_type, :log_type, :certificate_type, :position) +end diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index b5654c5..7b5d259 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -2,18 +2,18 @@ class Admin::SettingsController < ApplicationController before_action :require_admin! def edit - @values = Setting::INTEGERS.keys.index_with { Setting.integer(_1) } + @values = { "max_upload_mb" => Setting.max_upload_mb } end def update - submitted = params.fetch(:settings, {}).permit(*Setting::INTEGERS.keys).to_h + submitted = params.fetch(:settings, {}).permit(:max_upload_mb).to_h records = Setting.update_integers(submitted) @errors = records.flat_map { _1.errors.full_messages } if @errors.empty? Rails.logger.info("[settings] #{current_user.email_address} changed #{submitted.inspect}") redirect_to edit_admin_settings_path, notice: "Settings saved." else - @values = Setting::INTEGERS.keys.index_with { Setting.integer(_1) }.merge(submitted) + @values = { "max_upload_mb" => Setting.max_upload_mb }.merge(submitted) render :edit, status: :unprocessable_entity end end diff --git a/app/controllers/logbook_entries_controller.rb b/app/controllers/logbook_entries_controller.rb index e0b7490..a3a9ac3 100644 --- a/app/controllers/logbook_entries_controller.rb +++ b/app/controllers/logbook_entries_controller.rb @@ -26,6 +26,7 @@ class LogbookEntriesController < ApplicationController def show; end def new + LogbookTemplate.ensure_defaults! @entry = @aircraft.logbook_entries.new(date: Date.current, aircraft_hours_at_entry: @aircraft.current_hours) end diff --git a/app/javascript/controllers/component_times_controller.js b/app/javascript/controllers/component_times_controller.js index 1237a9f..7060b06 100644 --- a/app/javascript/controllers/component_times_controller.js +++ b/app/javascript/controllers/component_times_controller.js @@ -1,10 +1,16 @@ import { Controller } from "@hotwired/stimulus" // Logbook entry form: picking an engine or propeller log selects that -// component (if none is chosen yet), and picking a component fills in its -// current total time and time since overhaul. +// component (if none is chosen yet), and the component's total time and time +// since overhaul are filled in for the airframe time entered: its current +// times, shifted by however far the entry's airframe time is from the +// aircraft's current time. Typing in the component times yourself stops the +// automatic updates (until another component is picked). export default class extends Controller { - static targets = [ "logType", "component", "total", "since" ] + static targets = [ "logType", "component", "total", "since", "airframe" ] + static values = { aircraftHours: Number } + + connect() { this.manual = false } logTypeChanged() { if (this.componentTarget.value) return @@ -17,9 +23,25 @@ export default class extends Controller { } componentChanged() { + this.manual = false + this.recompute() + } + + airframeChanged() { + if (!this.manual) this.recompute() + } + + markManual() { this.manual = true } + + recompute() { const option = this.componentTarget.selectedOptions[0] if (!option?.dataset.total) return - this.totalTarget.value = option.dataset.total - this.sinceTarget.value = option.dataset.since + const airframe = this.hasAirframeTarget ? parseFloat(this.airframeTarget.value) : NaN + const delta = Number.isNaN(airframe) ? 0 : airframe - this.aircraftHoursValue + const total = parseFloat(option.dataset.total) + delta + const since = parseFloat(option.dataset.since) + delta + // Negative means the entry is from before the component was new or overhauled: unknown. + this.totalTarget.value = total >= 0 ? total.toFixed(1) : "" + this.sinceTarget.value = since >= 0 ? since.toFixed(1) : "" } } diff --git a/app/javascript/controllers/entry_template_controller.js b/app/javascript/controllers/entry_template_controller.js index 4b6d100..af2663b 100644 --- a/app/javascript/controllers/entry_template_controller.js +++ b/app/javascript/controllers/entry_template_controller.js @@ -1,18 +1,23 @@ import { Controller } from "@hotwired/stimulus" -// Fills a new logbook entry from a preventive maintenance template: the -// wording, the entry type, and "pilot" as the kind of certificate unless one -// is already chosen. +// Fills a new logbook entry from a template: the wording, and when the +// template sets them, the entry type, the logbook (which also picks the +// matching component) and the kind of certificate, unless one is chosen. export default class extends Controller { - static targets = [ "template", "text", "entryType", "certificate" ] + static targets = [ "template", "text", "entryType", "logType", "certificate" ] apply() { const option = this.templateTarget.selectedOptions[0] if (!option?.dataset.text) return if (this.textTarget.value.trim() && !confirm("Replace the entry text with this template?")) return - this.textTarget.value = option.dataset.text - if (this.hasEntryTypeTarget) this.entryTypeTarget.value = "MAINTENANCE" - if (this.hasCertificateTarget && !this.certificateTarget.value) this.certificateTarget.value = "PILOT" // keep a chosen certificate + const { text, entryType, logType, certificate } = option.dataset + this.textTarget.value = text + if (entryType && this.hasEntryTypeTarget) this.entryTypeTarget.value = entryType + if (logType && this.hasLogTypeTarget && this.logTypeTarget.value !== logType) { + this.logTypeTarget.value = logType + this.logTypeTarget.dispatchEvent(new Event("change", { bubbles: true })) + } + if (certificate && this.hasCertificateTarget && !this.certificateTarget.value) this.certificateTarget.value = certificate this.textTarget.focus() } } diff --git a/app/models/logbook_template.rb b/app/models/logbook_template.rb new file mode 100644 index 0000000..5d0031c --- /dev/null +++ b/app/models/logbook_template.rb @@ -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 diff --git a/app/models/preventive_maintenance.rb b/app/models/preventive_maintenance.rb deleted file mode 100644 index 7f5606c..0000000 --- a/app/models/preventive_maintenance.rb +++ /dev/null @@ -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 diff --git a/app/models/setting.rb b/app/models/setting.rb index 532439a..a5bf795 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -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 } diff --git a/app/views/admin/logbook_templates/_form.html.erb b/app/views/admin/logbook_templates/_form.html.erb new file mode 100644 index 0000000..d705697 --- /dev/null +++ b/app/views/admin/logbook_templates/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_with model: [ :admin, template ], class: "card card-body max-w-3xl space-y-4" do |f| %> + <%= f.errors_summary %> +
+ <%= f.field :name, required: true, placeholder: "Oil and filter change" %> + <%= f.field :reference, placeholder: "Part 43 App. A (c)(6)", hint: "Shown next to the name, e.g. the regulation or manual paragraph." %> +
+ <%= f.field :text, as: :textarea, rows: 5, required: true, hint: "The entry text. Use __ for blanks to fill in (quantities, part numbers…)." %> +
+ <%= f.field :entry_type, as: :select, label: "Entry type", collection: LogbookEntry::ENTRY_TYPES.invert %> + <%= f.field :log_type, as: :select, label: "Logbook", include_blank: "— Leave as is —", collection: LogbookEntry::LOG_TYPES.invert %> + <%= f.field :certificate_type, as: :select, label: "Kind of certificate", include_blank: "— Leave as is —", collection: LogbookEntry::CERTIFICATE_TYPES.invert, + hint: "Only filled in when none is chosen yet." %> + <%= f.field :position, as: :number, label: "Order" %> +
+
<%= f.submit "Save Template" %><%= link_to "Cancel", admin_logbook_templates_path, class: "btn-secondary" %>
+<% end %> +<% if template.persisted? %>
<%= delete_button "Delete template", admin_logbook_template_path(template) %>
<% end %> diff --git a/app/views/admin/logbook_templates/edit.html.erb b/app/views/admin/logbook_templates/edit.html.erb new file mode 100644 index 0000000..440711f --- /dev/null +++ b/app/views/admin/logbook_templates/edit.html.erb @@ -0,0 +1,3 @@ +<% content_for :title, "Logbook template" %> +

Logbook template

+<%= render "form", template: @template %> diff --git a/app/views/admin/logbook_templates/index.html.erb b/app/views/admin/logbook_templates/index.html.erb new file mode 100644 index 0000000..20014cc --- /dev/null +++ b/app/views/admin/logbook_templates/index.html.erb @@ -0,0 +1,27 @@ +<% content_for :title, "Logbook templates" %> +
+

Logbook templates

+
+ <%= button_to "Restore built-in templates", restore_admin_logbook_templates_path, class: "btn-secondary", title: "Add back any of the built-in preventive maintenance templates that were deleted" %> + <%= link_to "+ New Template", new_admin_logbook_template_path, class: "btn-primary" %> +
+
+

Wording to start a logbook entry from: the "Template" list on a new entry. Use __ for blanks to fill in.

+
+ <% if @templates.any? %> + + <% else %> + <%= empty_state "No templates." %> + <% end %> +
diff --git a/app/views/admin/logbook_templates/new.html.erb b/app/views/admin/logbook_templates/new.html.erb new file mode 100644 index 0000000..440711f --- /dev/null +++ b/app/views/admin/logbook_templates/new.html.erb @@ -0,0 +1,3 @@ +<% content_for :title, "Logbook template" %> +

Logbook template

+<%= render "form", template: @template %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index b39e704..25b4de8 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -37,7 +37,7 @@ <%= link_to "Profile", edit_profile_path, class: "block px-4 py-2.5 hover:bg-slate-100" %> <% if current_user.admin? %>

Admin

- <% [ [ "Users", admin_users_path ], [ "Component Types", admin_component_types_path ], [ "Airports", admin_airports_path ], [ "Settings", edit_admin_settings_path ], [ "About", admin_about_path ] ].each do |label, path| %> + <% [ [ "Users", admin_users_path ], [ "Component Types", admin_component_types_path ], [ "Airports", admin_airports_path ], [ "Logbook Templates", admin_logbook_templates_path ], [ "Settings", edit_admin_settings_path ], [ "About", admin_about_path ] ].each do |label, path| %> <%= link_to label, path, class: "block px-4 py-2.5 hover:bg-slate-100" %> <% end %> <% end %> @@ -53,7 +53,7 @@ Admin
- <% [ [ "Users", admin_users_path ], [ "Component Types", admin_component_types_path ], [ "Airports", admin_airports_path ], [ "Settings", edit_admin_settings_path ], [ "About", admin_about_path ] ].each do |label, path| %> + <% [ [ "Users", admin_users_path ], [ "Component Types", admin_component_types_path ], [ "Airports", admin_airports_path ], [ "Logbook Templates", admin_logbook_templates_path ], [ "Settings", edit_admin_settings_path ], [ "About", admin_about_path ] ].each do |label, path| %> <%= link_to label, path, class: [ "block px-4 py-2 text-sm hover:bg-slate-100", ("font-semibold text-sky-700" if current_page?(path)) ] %> <% end %>
diff --git a/app/views/logbook_entries/_component_fields.html.erb b/app/views/logbook_entries/_component_fields.html.erb index aa9f6c6..d0aeb90 100644 --- a/app/views/logbook_entries/_component_fields.html.erb +++ b/app/views/logbook_entries/_component_fields.html.erb @@ -10,7 +10,9 @@ {}, class: "input", data: { component_times_target: "component", action: "component-times#componentChanged" } %>

For engine and propeller logs: printed with its serial number and times.

- <%= f.field :component_hours_at_entry, as: :number, step: 0.1, label: "Component total time", data: { component_times_target: "total" } %> - <%= f.field :component_since_overhaul_at_entry, as: :number, step: 0.1, label: "Since overhaul", data: { component_times_target: "since" }, - hint: "Filled in from the component; correct them for an older entry." %> + <%= f.field :component_hours_at_entry, as: :number, step: 0.1, label: "Component total time", + data: { component_times_target: "total", action: "input->component-times#markManual" } %> + <%= f.field :component_since_overhaul_at_entry, as: :number, step: 0.1, label: "Since overhaul", + data: { component_times_target: "since", action: "input->component-times#markManual" }, + hint: "Worked out from the component's current times and the airframe total time above; edit them if they differ." %> diff --git a/app/views/logbook_entries/_form.html.erb b/app/views/logbook_entries/_form.html.erb index aaac59a..277c1e7 100644 --- a/app/views/logbook_entries/_form.html.erb +++ b/app/views/logbook_entries/_form.html.erb @@ -1,23 +1,26 @@ -<%= form_with model: [aircraft, entry], class: "card card-body space-y-4 max-w-3xl", data: { controller: "entry-template signer component-times" } do |f| %> +<%= form_with model: [aircraft, entry], class: "card card-body space-y-4 max-w-3xl", data: { controller: "entry-template signer component-times", component_times_aircraft_hours_value: aircraft.current_hours.to_f } do |f| %> <%= f.errors_summary %> - <% if entry.new_record? %> + <% templates = entry.new_record? ? LogbookTemplate.ordered.to_a : [] %> + <% if templates.any? %>
- <%= label_tag :template, "Preventive maintenance template", class: "label" %> + <%= label_tag :template, "Template", class: "label" %> -

For a pilot doing preventive maintenance on an aircraft they own or operate (14 CFR 43.3(g)). Fill in the blanks (__) and add your name and pilot certificate number. The item list is paraphrased from Part 43 Appendix A(c); the rule sets each item's limits.

+

Fill in the blanks (__). The built-in ones are for a pilot doing preventive maintenance on an aircraft they own or operate (14 CFR 43.3(g)); their wording is paraphrased from Part 43 Appendix A(c), which sets each item's limits.<% if current_user.admin? %> <%= link_to "Edit templates", admin_logbook_templates_path, class: "link" %><% end %>

<% end %>
<%= f.field :date, as: :date %> <%= f.field :log_type, as: :select, label: "Logbook", collection: LogbookEntry::LOG_TYPES.invert, - data: { component_times_target: "logType", action: "component-times#logTypeChanged" } %> + data: { component_times_target: "logType", entry_template_target: "logType", action: "component-times#logTypeChanged" } %> <%= f.field :entry_type, as: :select, label: "Entry type", collection: LogbookEntry::ENTRY_TYPES.invert, data: { entry_template_target: "entryType" } %> - <%= f.field :aircraft_hours_at_entry, as: :number, step: 0.1, label: "Airframe total time" %> + <%= f.field :aircraft_hours_at_entry, as: :number, step: 0.1, label: "Airframe total time", + data: { component_times_target: "airframe", action: "input->component-times#airframeChanged" } %>
<%= render "logbook_entries/component_fields", f: f, aircraft: aircraft %> <%= f.field :text, as: :textarea, label: "Entry text", rows: 8, data: { entry_template_target: "text" } %> diff --git a/app/views/squawks/resolution.html.erb b/app/views/squawks/resolution.html.erb index f026e7b..cc3ebaf 100644 --- a/app/views/squawks/resolution.html.erb +++ b/app/views/squawks/resolution.html.erb @@ -19,7 +19,8 @@ -
+

For a new entry. 14 CFR 43.9: what was done, the date, and the name, certificate number and kind of certificate of whoever approved the return to service.

<%= render "shared/sign_as" %> <%= fields_for :logbook_entry, @entry do |f| %> @@ -27,7 +28,8 @@ <%= f.field :date, as: :date %> <%= f.field :log_type, as: :select, label: "Logbook", collection: LogbookEntry::LOG_TYPES.invert, data: { component_times_target: "logType", action: "component-times#logTypeChanged" } %> - <%= f.field :aircraft_hours_at_entry, as: :number, step: 0.1, label: "Airframe total time" %> + <%= f.field :aircraft_hours_at_entry, as: :number, step: 0.1, label: "Airframe total time", + data: { component_times_target: "airframe", action: "input->component-times#airframeChanged" } %>
<%= render "logbook_entries/component_fields", f: f, aircraft: @aircraft %> <%= f.field :text, as: :textarea, label: "Work performed", rows: 3 %> diff --git a/config/logbook_templates.yml b/config/logbook_templates.yml new file mode 100644 index 0000000..81c288a --- /dev/null +++ b/config/logbook_templates.yml @@ -0,0 +1,95 @@ +# Built-in logbook templates: common preventive maintenance a pilot may do on +# an aircraft they own or operate (14 CFR 43.3(g)), keyed to Part 43 Appendix A +# paragraph (c). Descriptions are paraphrased; the rule sets each item's limits. +# Admins can edit these and add their own (Admin -> Logbook templates). +- name: "Oil and filter change" + log_type: ENG + reference: "Part 43 App. A (c)(6), (c)(23)" + text: "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. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(6) and (c)(23)." + certificate_type: PILOT +- name: "Tire removal, installation or repair" + reference: "Part 43 App. A (c)(1)" + text: "Removed and replaced the __ tire and tube. Inflated to __ psi. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(1)." + certificate_type: PILOT +- name: "Servicing landing gear shock struts" + reference: "Part 43 App. A (c)(3)" + text: "Serviced the __ shock strut with __. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(3)." + certificate_type: PILOT +- name: "Servicing wheel bearings" + reference: "Part 43 App. A (c)(4)" + text: "Cleaned, inspected and repacked the __ wheel bearings with __ grease. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(4)." + certificate_type: PILOT +- name: "Replacing safety wire or cotter keys" + reference: "Part 43 App. A (c)(5)" + text: "Replaced defective safety wire / cotter key at __. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(5)." + certificate_type: PILOT +- name: "Lubrication" + reference: "Part 43 App. A (c)(6)" + text: "Lubricated __ per the maintenance manual. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(6)." + certificate_type: PILOT +- name: "Replenishing hydraulic fluid" + reference: "Part 43 App. A (c)(8)" + text: "Replenished the hydraulic reservoir with __. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(8)." + certificate_type: PILOT +- name: "Repairing upholstery" + reference: "Part 43 App. A (c)(11)" + text: "Repaired the upholstery of __. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(11)." + certificate_type: PILOT +- name: "Small repairs to fairings or cowlings" + reference: "Part 43 App. A (c)(12)" + text: "Made a small repair to the __ (non-structural, contour unchanged). Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(12)." + certificate_type: PILOT +- name: "Replacing safety belts" + reference: "Part 43 App. A (c)(14)" + text: "Replaced the __ safety belt with P/N __. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(14)." + certificate_type: PILOT +- name: "Repairing landing light circuits" + reference: "Part 43 App. A (c)(16)" + text: "Troubleshot and repaired a broken circuit in the landing light wiring. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(16)." + certificate_type: PILOT +- name: "Replacing light bulbs, reflectors or lenses" + reference: "Part 43 App. A (c)(17)" + text: "Replaced the __ position/landing light bulb with P/N __. Checked operation. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(17)." + certificate_type: PILOT +- name: "Replacing a cowling" + reference: "Part 43 App. A (c)(19)" + text: "Removed and reinstalled the __ cowling. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(19)." + certificate_type: PILOT +- name: "Cleaning or replacing spark plugs" + log_type: ENG + reference: "Part 43 App. A (c)(20)" + text: "Removed, cleaned, gapped and rotated the spark plugs. Reinstalled and torqued to __. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(20)." + certificate_type: PILOT +- name: "Replacing hose connections (not hydraulic)" + reference: "Part 43 App. A (c)(21)" + text: "Replaced the __ hose with P/N __. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(21)." + certificate_type: PILOT +- name: "Replacing prefabricated fuel lines" + reference: "Part 43 App. A (c)(22)" + text: "Replaced the prefabricated fuel line __ with P/N __. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(22)." + certificate_type: PILOT +- name: "Cleaning or replacing fuel/oil strainers or filters" + reference: "Part 43 App. A (c)(23)" + text: "Cleaned / replaced the __ strainer / filter element. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(23)." + certificate_type: PILOT +- name: "Replacing or servicing the battery" + reference: "Part 43 App. A (c)(24)" + text: "Replaced the battery with P/N __ / serviced the battery. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(24)." + certificate_type: PILOT +- name: "Replacing non-structural fasteners" + reference: "Part 43 App. A (c)(26)" + text: "Replaced non-structural standard fasteners at __. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(26)." + certificate_type: PILOT +- name: "Checking magnetic chip detectors" + log_type: ENG + reference: "Part 43 App. A (c)(29)" + text: "Removed, checked and reinstalled the magnetic chip detector: no particles found. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(29)." + certificate_type: PILOT +- name: "Updating the navigation database" + reference: "Part 43 App. A (c)(31)" + text: "Updated the __ navigation database to cycle __. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(31)." + certificate_type: PILOT +- name: "Swapping a tray-mounted nav/com unit" + reference: "Part 43 App. A (c)(32)" + text: "Removed and reinstalled the tray-mounted __ unit. Checked operation. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(32)." + certificate_type: PILOT diff --git a/config/routes.rb b/config/routes.rb index af14565..4480811 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -112,6 +112,9 @@ Rails.application.routes.draw do namespace :admin do get "about", to: "about#show" resource :settings, only: %i[edit update] + resources :logbook_templates, except: :show do + collection { post :restore } + end post "about/test_email", to: "about#test_email", as: :test_email post "about/test_reminder", to: "about#test_reminder", as: :test_reminder resources :users, except: :show diff --git a/db/migrate/20261107250000_create_logbook_templates.rb b/db/migrate/20261107250000_create_logbook_templates.rb new file mode 100644 index 0000000..0632479 --- /dev/null +++ b/db/migrate/20261107250000_create_logbook_templates.rb @@ -0,0 +1,16 @@ +# Logbook entry templates admins can add and edit (the built-in preventive +# maintenance set is added on first use; see LogbookTemplate.ensure_defaults!). +class CreateLogbookTemplates < ActiveRecord::Migration[8.1] + def change + create_table :logbook_templates do |t| + t.string :name, null: false + t.string :reference + t.text :text, null: false + t.string :entry_type, null: false, default: "MAINTENANCE" + t.string :log_type + t.string :certificate_type + t.integer :position, null: false, default: 0 + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3894ad5..e2fcfc8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2026_11_07_240000) do +ActiveRecord::Schema[8.1].define(version: 2026_11_07_250000) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -480,6 +480,18 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_07_240000) do t.index ["user_id"], name: "index_logbook_imports_on_user_id" end + create_table "logbook_templates", force: :cascade do |t| + t.string "name", null: false + t.string "reference" + t.text "text", null: false + t.string "entry_type", default: "MAINTENANCE", null: false + t.string "log_type" + t.string "certificate_type" + t.integer "position", default: 0, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "major_records", force: :cascade do |t| t.integer "aircraft_id", null: false t.integer "component_id" diff --git a/test/integration/group_four_test.rb b/test/integration/group_four_test.rb index b4a50e0..d6dd948 100644 --- a/test/integration/group_four_test.rb +++ b/test/integration/group_four_test.rb @@ -34,14 +34,46 @@ class GroupFourTest < ActionDispatch::IntegrationTest refute first.reload.verified? end - test "preventive maintenance templates fill in the entry with the Part 43 reference" do + test "built-in templates are added once, show their reference, and fill in the entry" do sign_in @owner get new_aircraft_logbook_entry_path(@a) - assert_select "select[data-entry-template-target=template] option", PreventiveMaintenance::ITEMS.size + 1 - assert_select "option[value=spark_plugs][data-text*='Part 43 Appendix A paragraph (c)(20)']" - assert_select "option[value=oil_change][data-text*='14 CFR 43.3(g)']" + count = LogbookTemplate.defaults.size + assert_equal count, LogbookTemplate.count + assert_select "select[data-entry-template-target=template] option", count + 1 + assert_select "option[data-log-type=ENG][data-certificate=PILOT][data-entry-type=MAINTENANCE]", text: "Oil and filter change — Part 43 App. A (c)(6), (c)(23)" + assert_select "option[data-text*='Part 43 Appendix A paragraph (c)(20)']", text: /Cleaning or replacing spark plugs/ get edit_aircraft_logbook_entry_path(@a, @a.logbook_entries.create!(date: Date.current, text: "x")) assert_select "select[data-entry-template-target=template]", 0 + + LogbookTemplate.delete_all # deleting them sticks + get new_aircraft_logbook_entry_path(@a) + assert_equal 0, LogbookTemplate.count + assert_select "select[data-entry-template-target=template]", 0 + end + + test "admins add, edit and restore templates" do + sign_in @owner + get admin_logbook_templates_path + assert_redirected_to root_path + + admin = create_user("admin@example.com", admin: true) + sign_in admin + get admin_logbook_templates_path + assert_select "a", text: "+ New Template" + oil = LogbookTemplate.find_by!(name: "Oil and filter change") + post admin_logbook_templates_path, params: { logbook_template: { name: "Annual sign-off", reference: "14 CFR 43.11", entry_type: "INSPECTION", + log_type: "AC", certificate_type: "IA", text: "Annual inspection completed IAW Part 43 Appendix D." } } + assert_redirected_to admin_logbook_templates_path + assert_equal [ "INSPECTION", "AC", "IA" ], LogbookTemplate.find_by!(name: "Annual sign-off").then { [ _1.entry_type, _1.log_type, _1.certificate_type ] } + post admin_logbook_templates_path, params: { logbook_template: { name: "", text: "", entry_type: "NOPE" } } + assert_response :unprocessable_entity + + patch admin_logbook_template_path(oil), params: { logbook_template: { text: "Changed oil: __ qt of __." } } + assert_equal "Changed oil: __ qt of __.", oil.reload.text + delete admin_logbook_template_path(oil) + post restore_admin_logbook_templates_path + assert_equal "Restored 1 built-in template.", flash[:notice] + assert LogbookTemplate.exists?(name: "Oil and filter change") end test "an STC's ICA becomes a tracked inspection linked from its major record" do