Files
simple-aircraft-manager-rails/app/javascript/controllers/next_due_controller.js
T
rickyandClaude Opus 5.5 b75fd7cf62 Import ADs from FAA DRS exports; N/A determinations and DRS links
AD import (owners, ADs tab → Import from FAA DRS):
- Upload a DRS export (.xlsx recommended, .csv works), preview, confirm.
- Per AD: track, not applicable, or skip, with suggestions and flags for
  superseded/non-current ADs, model mismatches, appliance and STC-only
  ADs, repetitive actions, and older ADs this one supersedes.
- ADs are matched by number; re-importing updates existing ADs from the
  FAA data (preview lists what will change) without touching compliance
  records, recurrence or applicability. Superseded tracked ADs are
  updated and flagged rather than skipped.
- DRS's Excel export hyperlinks each AD number to its DRS page; those
  links are kept (http(s) only). DRS ids aren't derivable from the AD
  number, so no links are guessed.

Also:
- Per-aircraft "not applicable" AD determinations (N/A badge, quick
  action, excluded from airworthiness).
- AD numbers link to their DRS document in the AD list, compliance
  history (now with description, logbook/inspection links) and share page.
- Saved DRS search link per aircraft with an "Open in DRS" button.
- Upload storage extracted to a StoredUpload concern shared with the
  flight import.
- document_url / drs_search_url added in their own guarded migration
  (they were briefly in an already-applied migration).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 18:35:38 -05:00

66 lines
2.3 KiB
JavaScript

import { Controller } from "@hotwired/stimulus"
import { nextDue, describeDue } from "next_due"
// Live next-due preview (and prefill of an AD's next-due tach reading) from
// the selected AD/inspection type's recurrence rule.
//
// data-controller="next-due" data-next-due-rules-value='{"12": {"hours": 100, "months": 12, "days": 0}}'
// targets: rule (select), date, hours, dueHours (optional), permanent (optional), preview
export default class extends Controller {
static targets = ["rule", "date", "hours", "dueHours", "permanent", "preview"]
static values = { rules: Object }
connect() {
// Don't overwrite a reading that's already filled in (e.g. editing a record).
this.manual = this.hasDueHoursTarget && parseFloat(this.dueHoursTarget.value) > 0
this.recalc()
}
// The user typed their own next-due reading: stop overwriting it.
markManual() {
this.manual = this.dueHoursTarget.value.trim() !== "" && parseFloat(this.dueHoursTarget.value) > 0
this.renderPreview()
}
// Inputs that the rule depends on changed: recompute, unless overridden.
changed() {
this.manual = false
this.recalc()
}
recalc() {
const due = this.computeDue()
if (this.hasDueHoursTarget && !this.manual && !this.isPermanent) {
this.dueHoursTarget.value = due.hours != null ? due.hours.toFixed(1) : "0"
}
this.renderPreview(due)
}
renderPreview(due = this.computeDue()) {
if (!this.hasPreviewTarget) return
const rule = this.currentRule
let text
if (this.isPermanent) text = "Permanent compliance or not applicable: never due again."
else if (!this.ruleTarget.value) text = ""
else if (!rule) text = "One-time: no recurring due date."
else {
if (this.hasDueHoursTarget && this.manual) due = { ...due, hours: parseFloat(this.dueHoursTarget.value) }
text = describeDue(due) ? `Next due: ${describeDue(due)}` : "Enter the date and hours to calculate the next due."
}
this.previewTarget.textContent = text
this.previewTarget.hidden = text === ""
}
computeDue() {
return nextDue(this.currentRule, this.dateTarget.value, this.hoursTarget.value)
}
get currentRule() {
return this.rulesValue[this.ruleTarget.value] || null
}
get isPermanent() {
return this.permanentTargets.some((el) => el.checked)
}
}