mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
Sub-components on logbook entries (e.g. the oil filter on the engine)
- Once a component is chosen, its sub-components are offered on the entry form (and the squawk Resolve page); ticked ones are saved with their total time and time since service, worked out from the airframe total time like the component's (editable; blank before it was installed) - Entry page and printed PDFs list each sub-component with its serial number and times; parts without an overhaul type read "Since service" - Archives carry them: the original format's list of components per entry (first = the entry's component, the rest = sub-components) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
72e1d7760f
commit
7caa213e7a
16 files changed
+249
-22
No files matched your search
@@ -5,9 +5,11 @@ import { Controller } from "@hotwired/stimulus"
|
||||
// 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).
|
||||
// automatic updates (until another component is picked). The chosen
|
||||
// component's sub-components (oil filter…) can be ticked to include them,
|
||||
// with their times worked out the same way.
|
||||
export default class extends Controller {
|
||||
static targets = [ "logType", "component", "total", "since", "airframe" ]
|
||||
static targets = [ "logType", "component", "total", "since", "airframe", "partsBox", "part" ]
|
||||
static values = { aircraftHours: Number }
|
||||
|
||||
connect() { this.manual = false }
|
||||
@@ -24,11 +26,49 @@ export default class extends Controller {
|
||||
|
||||
componentChanged() {
|
||||
this.manual = false
|
||||
this.showParts()
|
||||
this.recompute()
|
||||
}
|
||||
|
||||
// Only the chosen component's sub-components are offered.
|
||||
showParts() {
|
||||
const id = this.componentTarget.value
|
||||
let any = false
|
||||
this.partTargets.forEach((row) => {
|
||||
const mine = id && row.dataset.ancestors.split(" ").includes(id)
|
||||
row.hidden = !mine
|
||||
if (!mine) row.querySelector("input[type=checkbox]").checked = false
|
||||
any ||= mine
|
||||
})
|
||||
if (this.hasPartsBoxTarget) this.partsBoxTarget.hidden = !any
|
||||
}
|
||||
|
||||
partToggled(event) {
|
||||
const row = event.target.closest("[data-component-times-target=part]")
|
||||
if (event.target.checked) { delete row.dataset.manual; this.fillPart(row) }
|
||||
}
|
||||
|
||||
partEdited(event) {
|
||||
const row = event.target.closest("[data-component-times-target=part]")
|
||||
row.dataset.manual = "true"
|
||||
row.querySelector("input[type=checkbox]").checked = true
|
||||
}
|
||||
|
||||
airframeChanged() {
|
||||
if (!this.manual) this.recompute()
|
||||
this.partTargets.forEach((row) => { if (!row.hidden && !row.dataset.manual) this.fillPart(row) })
|
||||
}
|
||||
|
||||
get delta() {
|
||||
const airframe = this.hasAirframeTarget ? parseFloat(this.airframeTarget.value) : NaN
|
||||
return Number.isNaN(airframe) ? 0 : airframe - this.aircraftHoursValue
|
||||
}
|
||||
|
||||
fillPart(row) {
|
||||
const total = parseFloat(row.dataset.total) + this.delta
|
||||
const since = parseFloat(row.dataset.since) + this.delta
|
||||
row.querySelector("[data-role=hours]").value = total >= 0 ? total.toFixed(1) : ""
|
||||
row.querySelector("[data-role=since]").value = since >= 0 ? since.toFixed(1) : ""
|
||||
}
|
||||
|
||||
markManual() { this.manual = true }
|
||||
@@ -36,10 +76,8 @@ export default class extends Controller {
|
||||
recompute() {
|
||||
const option = this.componentTarget.selectedOptions[0]
|
||||
if (!option?.dataset.total) return
|
||||
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
|
||||
const total = parseFloat(option.dataset.total) + this.delta
|
||||
const since = parseFloat(option.dataset.since) + this.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) : ""
|
||||
|
||||
Reference in new issue
Block a user