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
@@ -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. |
|
| 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. |
|
| 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. |
|
| 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…). |
|
| 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. |
|
| 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. |
|
| 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. |
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -2,18 +2,18 @@ class Admin::SettingsController < ApplicationController
|
|||||||
before_action :require_admin!
|
before_action :require_admin!
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@values = Setting::INTEGERS.keys.index_with { Setting.integer(_1) }
|
@values = { "max_upload_mb" => Setting.max_upload_mb }
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
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)
|
records = Setting.update_integers(submitted)
|
||||||
@errors = records.flat_map { _1.errors.full_messages }
|
@errors = records.flat_map { _1.errors.full_messages }
|
||||||
if @errors.empty?
|
if @errors.empty?
|
||||||
Rails.logger.info("[settings] #{current_user.email_address} changed #{submitted.inspect}")
|
Rails.logger.info("[settings] #{current_user.email_address} changed #{submitted.inspect}")
|
||||||
redirect_to edit_admin_settings_path, notice: "Settings saved."
|
redirect_to edit_admin_settings_path, notice: "Settings saved."
|
||||||
else
|
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
|
render :edit, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class LogbookEntriesController < ApplicationController
|
|||||||
def show; end
|
def show; end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
LogbookTemplate.ensure_defaults!
|
||||||
@entry = @aircraft.logbook_entries.new(date: Date.current, aircraft_hours_at_entry: @aircraft.current_hours)
|
@entry = @aircraft.logbook_entries.new(date: Date.current, aircraft_hours_at_entry: @aircraft.current_hours)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import { Controller } from "@hotwired/stimulus"
|
import { Controller } from "@hotwired/stimulus"
|
||||||
|
|
||||||
// Logbook entry form: picking an engine or propeller log selects that
|
// Logbook entry form: picking an engine or propeller log selects that
|
||||||
// component (if none is chosen yet), and picking a component fills in its
|
// component (if none is chosen yet), and the component's total time and time
|
||||||
// current total time and time since overhaul.
|
// 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 {
|
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() {
|
logTypeChanged() {
|
||||||
if (this.componentTarget.value) return
|
if (this.componentTarget.value) return
|
||||||
@@ -17,9 +23,25 @@ export default class extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentChanged() {
|
componentChanged() {
|
||||||
|
this.manual = false
|
||||||
|
this.recompute()
|
||||||
|
}
|
||||||
|
|
||||||
|
airframeChanged() {
|
||||||
|
if (!this.manual) this.recompute()
|
||||||
|
}
|
||||||
|
|
||||||
|
markManual() { this.manual = true }
|
||||||
|
|
||||||
|
recompute() {
|
||||||
const option = this.componentTarget.selectedOptions[0]
|
const option = this.componentTarget.selectedOptions[0]
|
||||||
if (!option?.dataset.total) return
|
if (!option?.dataset.total) return
|
||||||
this.totalTarget.value = option.dataset.total
|
const airframe = this.hasAirframeTarget ? parseFloat(this.airframeTarget.value) : NaN
|
||||||
this.sinceTarget.value = option.dataset.since
|
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) : ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,23 @@
|
|||||||
import { Controller } from "@hotwired/stimulus"
|
import { Controller } from "@hotwired/stimulus"
|
||||||
|
|
||||||
// Fills a new logbook entry from a preventive maintenance template: the
|
// Fills a new logbook entry from a template: the wording, and when the
|
||||||
// wording, the entry type, and "pilot" as the kind of certificate unless one
|
// template sets them, the entry type, the logbook (which also picks the
|
||||||
// is already chosen.
|
// matching component) and the kind of certificate, unless one is chosen.
|
||||||
export default class extends Controller {
|
export default class extends Controller {
|
||||||
static targets = [ "template", "text", "entryType", "certificate" ]
|
static targets = [ "template", "text", "entryType", "logType", "certificate" ]
|
||||||
|
|
||||||
apply() {
|
apply() {
|
||||||
const option = this.templateTarget.selectedOptions[0]
|
const option = this.templateTarget.selectedOptions[0]
|
||||||
if (!option?.dataset.text) return
|
if (!option?.dataset.text) return
|
||||||
if (this.textTarget.value.trim() && !confirm("Replace the entry text with this template?")) return
|
if (this.textTarget.value.trim() && !confirm("Replace the entry text with this template?")) return
|
||||||
this.textTarget.value = option.dataset.text
|
const { text, entryType, logType, certificate } = option.dataset
|
||||||
if (this.hasEntryTypeTarget) this.entryTypeTarget.value = "MAINTENANCE"
|
this.textTarget.value = text
|
||||||
if (this.hasCertificateTarget && !this.certificateTarget.value) this.certificateTarget.value = "PILOT" // keep a chosen certificate
|
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()
|
this.textTarget.focus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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
|
# Setting.max_upload_bytes # => 52428800
|
||||||
class Setting < ApplicationRecord
|
class Setting < ApplicationRecord
|
||||||
INTEGERS = {
|
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
|
}.freeze
|
||||||
|
|
||||||
validates :key, presence: true, uniqueness: true, inclusion: { in: INTEGERS.keys }
|
validates :key, presence: true, uniqueness: true, inclusion: { in: INTEGERS.keys }
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<%= form_with model: [ :admin, template ], class: "card card-body max-w-3xl space-y-4" do |f| %>
|
||||||
|
<%= f.errors_summary %>
|
||||||
|
<div class="grid gap-4 sm:grid-cols-2">
|
||||||
|
<%= 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." %>
|
||||||
|
</div>
|
||||||
|
<%= f.field :text, as: :textarea, rows: 5, required: true, hint: "The entry text. Use __ for blanks to fill in (quantities, part numbers…)." %>
|
||||||
|
<div class="grid gap-4 sm:grid-cols-4">
|
||||||
|
<%= 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" %>
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-2"><%= f.submit "Save Template" %><%= link_to "Cancel", admin_logbook_templates_path, class: "btn-secondary" %></div>
|
||||||
|
<% end %>
|
||||||
|
<% if template.persisted? %><div class="mt-4"><%= delete_button "Delete template", admin_logbook_template_path(template) %></div><% end %>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<% content_for :title, "Logbook template" %>
|
||||||
|
<h1 class="mb-4 text-2xl font-bold">Logbook template</h1>
|
||||||
|
<%= render "form", template: @template %>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<% content_for :title, "Logbook templates" %>
|
||||||
|
<div class="mb-4 flex flex-wrap items-center justify-between gap-2">
|
||||||
|
<h1 class="text-2xl font-bold">Logbook templates</h1>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<%= 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" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="mb-4 text-sm text-slate-600">Wording to start a logbook entry from: the "Template" list on a new entry. Use __ for blanks to fill in.</p>
|
||||||
|
<section class="card">
|
||||||
|
<% if @templates.any? %>
|
||||||
|
<ul class="divide-y divide-slate-100">
|
||||||
|
<% @templates.each do |t| %>
|
||||||
|
<li class="flex flex-wrap items-start justify-between gap-3 px-4 py-3">
|
||||||
|
<div class="min-w-0 flex-1 text-sm">
|
||||||
|
<div class="font-medium"><%= t.name %><% if t.reference.present? %> <span class="font-normal text-slate-500">— <%= t.reference %></span><% end %></div>
|
||||||
|
<div class="text-xs text-slate-500"><%= [ LogbookEntry::ENTRY_TYPES[t.entry_type], (t.log_type && "#{LogbookEntry::LOG_TYPES[t.log_type]} log"), (t.certificate_type && LogbookEntry::CERTIFICATE_TYPES[t.certificate_type]) ].compact.join(" · ") %></div>
|
||||||
|
<p class="mt-1 text-xs text-slate-600"><%= t.text.truncate(220) %></p>
|
||||||
|
</div>
|
||||||
|
<%= link_to "Edit", edit_admin_logbook_template_path(t), class: "btn-secondary btn-sm" %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
<% else %>
|
||||||
|
<%= empty_state "No templates." %>
|
||||||
|
<% end %>
|
||||||
|
</section>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<% content_for :title, "Logbook template" %>
|
||||||
|
<h1 class="mb-4 text-2xl font-bold">Logbook template</h1>
|
||||||
|
<%= render "form", template: @template %>
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
<%= link_to "Profile", edit_profile_path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
|
<%= link_to "Profile", edit_profile_path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
|
||||||
<% if current_user.admin? %>
|
<% if current_user.admin? %>
|
||||||
<p class="border-t border-slate-100 px-4 pt-2 pb-1 text-xs font-semibold text-slate-500">Admin</p>
|
<p class="border-t border-slate-100 px-4 pt-2 pb-1 text-xs font-semibold text-slate-500">Admin</p>
|
||||||
<% [ [ "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" %>
|
<%= link_to label, path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
Admin <span aria-hidden="true" class="text-xs">▾</span>
|
Admin <span aria-hidden="true" class="text-xs">▾</span>
|
||||||
</summary>
|
</summary>
|
||||||
<div class="absolute right-0 z-30 mt-2 w-48 rounded-md bg-surface py-1 text-slate-700 shadow-lg ring-1 ring-slate-200">
|
<div class="absolute right-0 z-30 mt-2 w-48 rounded-md bg-surface py-1 text-slate-700 shadow-lg ring-1 ring-slate-200">
|
||||||
<% [ [ "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)) ] %>
|
<%= 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 %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -10,7 +10,9 @@
|
|||||||
{}, class: "input", data: { component_times_target: "component", action: "component-times#componentChanged" } %>
|
{}, class: "input", data: { component_times_target: "component", action: "component-times#componentChanged" } %>
|
||||||
<p class="hint">For engine and propeller logs: printed with its serial number and times.</p>
|
<p class="hint">For engine and propeller logs: printed with its serial number and times.</p>
|
||||||
</div>
|
</div>
|
||||||
<%= f.field :component_hours_at_entry, as: :number, step: 0.1, label: "Component total time", data: { component_times_target: "total" } %>
|
<%= f.field :component_hours_at_entry, as: :number, step: 0.1, label: "Component total time",
|
||||||
<%= f.field :component_since_overhaul_at_entry, as: :number, step: 0.1, label: "Since overhaul", data: { component_times_target: "since" },
|
data: { component_times_target: "total", action: "input->component-times#markManual" } %>
|
||||||
hint: "Filled in from the component; correct them for an older entry." %>
|
<%= 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." %>
|
||||||
</div>
|
</div>
|
||||||
@@ -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 %>
|
<%= f.errors_summary %>
|
||||||
<% if entry.new_record? %>
|
<% templates = entry.new_record? ? LogbookTemplate.ordered.to_a : [] %>
|
||||||
|
<% if templates.any? %>
|
||||||
<div>
|
<div>
|
||||||
<%= label_tag :template, "Preventive maintenance template", class: "label" %>
|
<%= label_tag :template, "Template", class: "label" %>
|
||||||
<select id="template" class="input" data-entry-template-target="template" data-action="entry-template#apply">
|
<select id="template" class="input" data-entry-template-target="template" data-action="entry-template#apply">
|
||||||
<option value="">— Write it yourself —</option>
|
<option value="">— Write it yourself —</option>
|
||||||
<% PreventiveMaintenance::ITEMS.each do |item| %>
|
<% templates.each do |t| %>
|
||||||
<option value="<%= item.key %>" data-text="<%= PreventiveMaintenance.text_for(item) %>"><%= item.label %> (<%= item.paragraphs.join(", ") %>)</option>
|
<option value="<%= t.id %>" data-text="<%= t.text %>" data-entry-type="<%= t.entry_type %>" data-log-type="<%= t.log_type %>"
|
||||||
|
data-certificate="<%= t.certificate_type %>"><%= t.label %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
<p class="hint">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.</p>
|
<p class="hint">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 %></p>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<div class="grid gap-4 sm:grid-cols-4">
|
<div class="grid gap-4 sm:grid-cols-4">
|
||||||
<%= f.field :date, as: :date %>
|
<%= f.field :date, as: :date %>
|
||||||
<%= f.field :log_type, as: :select, label: "Logbook", collection: LogbookEntry::LOG_TYPES.invert,
|
<%= 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 :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" } %>
|
||||||
</div>
|
</div>
|
||||||
<%= render "logbook_entries/component_fields", f: f, aircraft: aircraft %>
|
<%= render "logbook_entries/component_fields", f: f, aircraft: aircraft %>
|
||||||
<%= f.field :text, as: :textarea, label: "Entry text", rows: 8, data: { entry_template_target: "text" } %>
|
<%= f.field :text, as: :textarea, label: "Entry text", rows: 8, data: { entry_template_target: "text" } %>
|
||||||
|
|||||||
@@ -19,7 +19,8 @@
|
|||||||
<label class="flex items-center gap-2"><%= radio_button_tag :logbook, "none", choice == "none" %> No logbook entry (e.g. it wasn't a defect)</label>
|
<label class="flex items-center gap-2"><%= radio_button_tag :logbook, "none", choice == "none" %> No logbook entry (e.g. it wasn't a defect)</label>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<div class="space-y-4 rounded-md border border-slate-200 p-3" data-controller="signer component-times">
|
<div class="space-y-4 rounded-md border border-slate-200 p-3" data-controller="signer component-times"
|
||||||
|
data-component-times-aircraft-hours-value="<%= @aircraft.current_hours.to_f %>">
|
||||||
<p class="text-xs text-slate-500">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.</p>
|
<p class="text-xs text-slate-500">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.</p>
|
||||||
<%= render "shared/sign_as" %>
|
<%= render "shared/sign_as" %>
|
||||||
<%= fields_for :logbook_entry, @entry do |f| %>
|
<%= fields_for :logbook_entry, @entry do |f| %>
|
||||||
@@ -27,7 +28,8 @@
|
|||||||
<%= f.field :date, as: :date %>
|
<%= f.field :date, as: :date %>
|
||||||
<%= f.field :log_type, as: :select, label: "Logbook", collection: LogbookEntry::LOG_TYPES.invert,
|
<%= 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", 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" } %>
|
||||||
</div>
|
</div>
|
||||||
<%= render "logbook_entries/component_fields", f: f, aircraft: @aircraft %>
|
<%= render "logbook_entries/component_fields", f: f, aircraft: @aircraft %>
|
||||||
<%= f.field :text, as: :textarea, label: "Work performed", rows: 3 %>
|
<%= f.field :text, as: :textarea, label: "Work performed", rows: 3 %>
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -112,6 +112,9 @@ Rails.application.routes.draw do
|
|||||||
namespace :admin do
|
namespace :admin do
|
||||||
get "about", to: "about#show"
|
get "about", to: "about#show"
|
||||||
resource :settings, only: %i[edit update]
|
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_email", to: "about#test_email", as: :test_email
|
||||||
post "about/test_reminder", to: "about#test_reminder", as: :test_reminder
|
post "about/test_reminder", to: "about#test_reminder", as: :test_reminder
|
||||||
resources :users, except: :show
|
resources :users, except: :show
|
||||||
|
|||||||
@@ -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
|
||||||
Generated
+13
-1
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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|
|
create_table "active_storage_attachments", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.string "record_type", 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"
|
t.index ["user_id"], name: "index_logbook_imports_on_user_id"
|
||||||
end
|
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|
|
create_table "major_records", force: :cascade do |t|
|
||||||
t.integer "aircraft_id", null: false
|
t.integer "aircraft_id", null: false
|
||||||
t.integer "component_id"
|
t.integer "component_id"
|
||||||
|
|||||||
@@ -34,14 +34,46 @@ class GroupFourTest < ActionDispatch::IntegrationTest
|
|||||||
refute first.reload.verified?
|
refute first.reload.verified?
|
||||||
end
|
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
|
sign_in @owner
|
||||||
get new_aircraft_logbook_entry_path(@a)
|
get new_aircraft_logbook_entry_path(@a)
|
||||||
assert_select "select[data-entry-template-target=template] option", PreventiveMaintenance::ITEMS.size + 1
|
count = LogbookTemplate.defaults.size
|
||||||
assert_select "option[value=spark_plugs][data-text*='Part 43 Appendix A paragraph (c)(20)']"
|
assert_equal count, LogbookTemplate.count
|
||||||
assert_select "option[value=oil_change][data-text*='14 CFR 43.3(g)']"
|
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"))
|
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
|
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
|
end
|
||||||
|
|
||||||
test "an STC's ICA becomes a tracked inspection linked from its major record" do
|
test "an STC's ICA becomes a tracked inspection linked from its major record" do
|
||||||
|
|||||||
Reference in new issue
Block a user