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:
rickyandClaude Opus 5.5 committed 2026-11-07 11:40:23 -05:00
1 parent a51f78ebf3
commit 72e1d7760f
22 files changed
+366 -74

No files matched your search

@@ -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 %>
+2 -2
View File
@@ -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? %>
<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" %>
<% end %>
<% end %>
@@ -53,7 +53,7 @@
Admin <span aria-hidden="true" class="text-xs">▾</span>
</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">
<% [ [ "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 %>
</div>
@@ -10,7 +10,9 @@
{}, 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>
</div>
<%= 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." %>
</div>
+11 -8
View File
@@ -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? %>
<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">
<option value="">— Write it yourself —</option>
<% PreventiveMaintenance::ITEMS.each do |item| %>
<option value="<%= item.key %>" data-text="<%= PreventiveMaintenance.text_for(item) %>"><%= item.label %> (<%= item.paragraphs.join(", ") %>)</option>
<% templates.each do |t| %>
<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 %>
</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>
<% end %>
<div class="grid gap-4 sm:grid-cols-4">
<%= 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" } %>
</div>
<%= render "logbook_entries/component_fields", f: f, aircraft: aircraft %>
<%= f.field :text, as: :textarea, label: "Entry text", rows: 8, data: { entry_template_target: "text" } %>
+4 -2
View File
@@ -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>
</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>
<%= 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" } %>
</div>
<%= render "logbook_entries/component_fields", f: f, aircraft: @aircraft %>
<%= f.field :text, as: :textarea, label: "Work performed", rows: 3 %>