mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Initial commit: Rails port of Simple Aircraft Manager
Rails 8.1 + SQLite rewrite of marbindrakon/simple-aircraft-manager, designed to self-host as a single container (Solid Queue/Cache/Cable, Active Storage on disk, Hotwire + importmap, Tailwind). - Airworthiness engine ported from health/services.py (ADs, grounding squawks, inspection recurrency, component replacement) - Hours updates and flight logs cascading to in-service components, optional airworthiness enforcement - Components, squawks, ADs, inspections, logbook, documents, major records, oil/fuel consumption stats and charts, activity log - Admin/owner/pilot RBAC and public share links (status/maintenance) - Docker Compose and Kamal deployment, env-driven production config - Service and integration tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
38df19c331
264 files changed
+8365
No files matched your search
@@ -0,0 +1,73 @@
|
||||
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 }
|
||||
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
|
||||
Reference in new issue
Block a user