Files
simple-aircraft-manager-rails/app/models/squawk.rb
T
rickyandClaude Opus 5.5 ef542ee2a5 Squawks: multiple attachments, in-app photo viewer, downloads
Existing single attachments migrate to the new list. Photos open in a
full-screen viewer (swipe/arrow keys); every file has a download link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 09:51:04 -05:00

28 lines
1012 B
Ruby

class Squawk < ApplicationRecord
include UploadValidation
PRIORITIES = { 0 => "Ground Aircraft", 1 => "Fix Soon", 2 => "Fix at Next Inspection", 3 => "Fix Eventually" }.freeze
PRIORITY_COLORS = { 0 => "red", 1 => "orange", 2 => "blue", 3 => "gray" }.freeze
belongs_to :aircraft
belongs_to :component, optional: true
belongs_to :reported_by, class_name: "User", optional: true
has_many_attached :attachments
validates :priority, inclusion: { in: PRIORITIES.keys }
validates :issue_reported, presence: true
validates_uploads :attachments
scope :active, -> { where(resolved: false) }
scope :resolved, -> { where(resolved: true) }
scope :by_priority, -> { order(:priority, created_at: :desc) }
def priority_label = PRIORITIES[priority]
def priority_color = PRIORITY_COLORS[priority]
def grounding? = priority.zero? && !resolved?
def resolve!(notes: nil)
update!(resolved: true, resolved_at: Time.current, notes: [ self.notes, notes ].compact_blank.join("\n\n"))
end
end