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

@@ -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) : ""
}
}
@@ -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()
}
}