mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
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>
76 lines
2.3 KiB
Ruby
76 lines
2.3 KiB
Ruby
class Aircraft < ApplicationRecord
|
|
STATUSES = {
|
|
"AVAILABLE" => "Available",
|
|
"MX" => "In Maintenance",
|
|
"GROUND" => "Grounded",
|
|
"UNAVAILABLE" => "Unavailable"
|
|
}.freeze
|
|
|
|
has_one_attached :picture
|
|
|
|
has_many :roles, class_name: "AircraftRole", dependent: :destroy
|
|
has_many :users, through: :roles
|
|
has_many :notes, class_name: "AircraftNote", dependent: :destroy
|
|
has_many :events, class_name: "AircraftEvent", dependent: :delete_all
|
|
has_many :share_tokens, dependent: :destroy
|
|
has_many :components, dependent: :destroy
|
|
has_many :squawks, dependent: :destroy
|
|
has_many :logbook_entries, dependent: :destroy
|
|
has_many :document_collections, dependent: :destroy
|
|
has_many :documents, dependent: :destroy
|
|
has_many :inspection_records, dependent: :destroy
|
|
has_many :ad_compliances, dependent: :destroy
|
|
has_many :major_records, dependent: :destroy
|
|
has_many :flight_logs, dependent: :destroy
|
|
has_many :consumable_records, dependent: :destroy
|
|
has_and_belongs_to_many :inspection_types
|
|
has_and_belongs_to_many :airworthiness_directives
|
|
|
|
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) }
|
|
|
|
def to_s = tail_number
|
|
|
|
def status_label = STATUSES[status]
|
|
|
|
# Hours used for compliance calculations (tach minus offset, as in the original).
|
|
def current_hours
|
|
tach_time - tach_time_offset
|
|
end
|
|
|
|
def airworthiness
|
|
@airworthiness ||= Airworthiness.new(self).call
|
|
end
|
|
|
|
def reload(*)
|
|
@airworthiness = nil
|
|
super
|
|
end
|
|
|
|
# ADs that apply directly or via any installed component.
|
|
def applicable_ads
|
|
AirworthinessDirective.applicable_to(self)
|
|
end
|
|
|
|
def applicable_inspection_types
|
|
InspectionType.applicable_to(self)
|
|
end
|
|
|
|
def log_event!(category, event_name, user: Current.user, notes: nil)
|
|
events.create!(category: category, event_name: event_name, user: user, notes: notes)
|
|
end
|
|
|
|
private
|
|
|
|
def picture_is_image
|
|
if picture.attached? && !picture.content_type.to_s.start_with?("image/")
|
|
errors.add(:picture, "must be an image")
|
|
end
|
|
end
|
|
end
|