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>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-05 18:35:38 -05:00
1 parent f94ccee99b
commit b75fd7cf62
31 files changed
+817 -57

No files matched your search

+5 -2
View File
@@ -15,12 +15,15 @@ class AdCompliance < ApplicationRecord
# Prefill next_due_at_time from the AD's hour recurrence (hours at compliance
# + interval). Only fills a blank/zero value, so a typed-in reading wins.
def fill_next_due
return if permanent? || airworthiness_directive.nil?
return if closed? || airworthiness_directive.nil?
base = aircraft_hours_at_compliance || aircraft&.tach_time
due = Compliance.next_due(airworthiness_directive.due_rule, date: date_complied, hours: base)
self.next_due_at_time = due[:hours] if due[:hours]
end
# Permanent compliance or a not-applicable determination: never due again.
def closed? = permanent? || not_applicable?
def self.for_aircraft(aircraft)
where(aircraft_id: aircraft.id).or(where(component_id: aircraft.components.select(:id)))
end
@@ -31,7 +34,7 @@ class AdCompliance < ApplicationRecord
# easy mistake of entering "100" for "every 100 hours".
def next_due_is_a_future_reading
due = next_due_at_time.to_d
return if permanent? || due <= 0
return if closed? || due <= 0
base = aircraft_hours_at_compliance || aircraft&.tach_time
return unless base && due <= base
errors.add(:next_due_at_time, "must be a tach reading after the compliance hours (#{base}). " \
+2
View File
@@ -28,6 +28,8 @@ class Aircraft < ApplicationRecord
validates :tail_number, presence: true
validates :status, inclusion: { in: STATUSES.keys }
validates :drs_search_url, format: { with: %r{\Ahttps://drs\.faa\.gov/\S*\z}, message: "must be a https://drs.faa.gov/ link" }, allow_blank: true
normalizes :drs_search_url, with: ->(url) { url.strip.sub(/#.*\z/, "").presence }
validate :picture_is_image
scope :ordered, -> { order(:tail_number) }
+19
View File
@@ -14,9 +14,20 @@ class AirworthinessDirective < ApplicationRecord
validates :name, :short_description, presence: true
validates :compliance_type, inclusion: { in: COMPLIANCE_TYPES.keys }
validates :bulletin_type, inclusion: { in: BULLETIN_TYPES.keys }
validates :document_url, format: { with: %r{\Ahttps?://\S+\z}i, message: "must be an http(s) link" }, allow_blank: true
normalizes :document_url, with: ->(url) { url.strip.presence }
scope :ordered, -> { order(:name) }
# "2009-10-09 r2" → "2009-10-09 R2"
def self.normalize_number(number)
number.to_s.strip.upcase.gsub(/\s+/, " ")
end
def self.find_by_number(number)
find_by("upper(replace(name, ' ', '')) = ?", normalize_number(number).delete(" "))
end
def self.applicable_to(aircraft)
direct = joins(:aircraft).where(aircraft: { id: aircraft.id }).select(:id)
via_component = joins(:components).where(components: { aircraft_id: aircraft.id }).select(:id)
@@ -24,6 +35,14 @@ class AirworthinessDirective < ApplicationRecord
end
def to_s = name
# [url, label] for this AD's document, when we have its link (DRS Excel
# exports carry one per AD; it can also be pasted in). DRS links use an
# internal document id, so they can't be derived from the AD number.
def reference_link
[ document_url, "View AD" ] if document_url.present?
end
def conditional? = compliance_type == "conditional"
def bulletin_label = BULLETIN_LABELS[bulletin_type]