diff --git a/Gemfile b/Gemfile index 48de394..0d035e1 100644 --- a/Gemfile +++ b/Gemfile @@ -23,10 +23,9 @@ gem "bcrypt", "~> 3.1.7" # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem "tzinfo-data", platforms: %i[ windows jruby ] -# Use the database-backed adapters for Rails.cache, Active Job, and Action Cable +# Use the database-backed adapters for Rails.cache and Active Job gem "solid_cache" gem "solid_queue" -gem "solid_cable" # Reduces boot times through caching; required in config/boot.rb gem "bootsnap", require: false @@ -56,12 +55,6 @@ group :development do gem "web-console" end -group :test do - # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] - gem "capybara" - gem "selenium-webdriver" -end - gem "chartkick", "~> 5.2" gem "json", "~> 3.1" diff --git a/Gemfile.lock b/Gemfile.lock index 99faae5..0f5e695 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -100,15 +100,6 @@ GEM brakeman (8.1.0) racc builder (3.3.0) - capybara (3.40.0) - addressable - matrix - mini_mime (>= 0.1.3) - nokogiri (~> 1.11) - rack (>= 1.6.0) - rack-test (>= 0.6.3) - regexp_parser (>= 1.5, < 3.0) - xpath (~> 3.2) caxlsx (4.5.0) htmlentities (~> 4.3, >= 4.3.4) marcel (~> 1.0) @@ -404,16 +395,6 @@ GEM ruby-progressbar (1.13.0) rubyzip (3.7.0) securerandom (0.4.1) - selenium-webdriver (4.52.0) - base64 (~> 0.2) - logger (~> 1.4) - rubyzip (>= 1.2.2, < 4.0) - websocket (~> 1.0) - solid_cable (4.1.0) - actioncable (>= 7.2) - activejob (>= 7.2) - activerecord (>= 7.2) - railties (>= 7.2) solid_cache (1.0.10) activejob (>= 7.2) activerecord (>= 7.2) @@ -493,13 +474,10 @@ GEM addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - websocket (1.2.11) websocket-driver (0.8.2) base64 websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - xpath (3.2.0) - nokogiri (~> 1.8) zeitwerk (2.8.3) PLATFORMS @@ -518,7 +496,6 @@ DEPENDENCIES bcrypt (~> 3.1.7) bootsnap brakeman - capybara caxlsx (~> 4.5) chartkick (~> 5.2) commonmarker (~> 2.10) @@ -540,8 +517,6 @@ DEPENDENCIES rqrcode (~> 3.1) rubocop-rails-omakase rubyzip (~> 3.7) - selenium-webdriver - solid_cable solid_cache solid_queue sqlite3 (>= 2.1) @@ -584,7 +559,6 @@ CHECKSUMS bootsnap (1.26.1) sha256=5b5bd90f8f13ea338627c1d56ffbe2ea25e743ac48c2afec1a9bea3a06a264e2 brakeman (8.1.0) sha256=cfa9e5214e4925842f4bc849a64f8a7e6c5d0425fe98eac8d7b7bc60fdc17e07 builder (3.3.0) sha256=497918d2f9dca528fdca4b88d84e4ef4387256d984b8154e9d5d3fe5a9c8835f - capybara (3.40.0) sha256=42dba720578ea1ca65fd7a41d163dd368502c191804558f6e0f71b391054aeef caxlsx (4.5.0) sha256=e3d98d859f148df05d5462086b5079b523f29c1766b569535f1d68629ce743ff chartkick (5.3.0) sha256=19a2bba39decf54c4939d3f31460535f8814c85045672ba2ed616c6897325b00 chunky_png (1.4.0) sha256=89d5b31b55c0cf4da3cf89a2b4ebc3178d8abe8cbaf116a1dba95668502fdcfe @@ -700,8 +674,6 @@ CHECKSUMS ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33 rubyzip (3.7.0) sha256=65c19294da75297a939006f3516deacc33185fbd721ff1954f7a231db6d3e121 securerandom (0.4.1) sha256=cc5193d414a4341b6e225f0cb4446aceca8e50d5e1888743fac16987638ea0b1 - selenium-webdriver (4.52.0) sha256=5d45ba100ea8b57f5a8c25979a636d48b4c60c39973478930d78e884bdeecd2d - solid_cable (4.1.0) sha256=828e3d509207b82b4f05f4e9c85f696994710679b52d511aa7f97ebd212d3226 solid_cache (1.0.10) sha256=bc05a2fb3ac78a6f43cbb5946679cf9db67dd30d22939ededc385cb93e120d41 solid_queue (1.7.2) sha256=a22685e1d2ee14ce7b4e5d4592c9d8e837951884c51555609dee58679ed03325 sqlite3 (2.10.2-aarch64-linux-gnu) sha256=e9aea2c2b3476fc875dd8a89313a9a2862818519c0186bfb5b56d6f57bb08d98 @@ -743,10 +715,8 @@ CHECKSUMS web-console (4.3.0) sha256=e13b71301cdfc2093f155b5aa3a622db80b4672d1f2f713119cc7ec7ac6a6da4 webfinger (2.1.3) sha256=567a52bde77fb38ca6b67e55db755f988766ec4651c1d24916a65aa70540695c webmock (3.34.0) sha256=72eed29dc8c00148d592acaedaaa6b869e2e397de57dfc8602b84aa834f46b33 - websocket (1.2.11) sha256=b7e7a74e2410b5e85c25858b26b3322f29161e300935f70a0e0d3c35e0462737 websocket-driver (0.8.2) sha256=97c556b019bf3410b4961002ac501621e9322d3f8a7bc02161a09301cc4c4146 websocket-extensions (0.1.5) sha256=1c6ba63092cda343eb53fc657110c71c754c56484aad42578495227d717a8241 - xpath (3.2.0) sha256=6dfda79d91bb3b949b947ecc5919f042ef2f399b904013eb3ef6d20dd3a4082e zeitwerk (2.8.3) sha256=2c85125a8467ce069e20123d1e709a08955c9d29c118c25b46b7b7fafdbb92e5 BUNDLED WITH diff --git a/README.md b/README.md index 4d08e58..734d7d4 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The port aims to be **easy to host**. It runs as one process with one SQLite dat ## Stack -- Ruby 4.0, Rails 8.1, SQLite. Solid Queue, Solid Cache, and Solid Cable all use SQLite, so there are no extra services. Background jobs (nightly backup and records check, weekly reminders and AD search) run in the web process. +- Ruby 4.0, Rails 8.1, SQLite. Solid Queue and Solid Cache both use SQLite, so there are no extra services. Background jobs (nightly backup and records check, weekly reminders and AD search) run in the web process. - Hotwire (Turbo and Stimulus) with importmap, so there is no Node build step. Tailwind CSS 4 runs through `tailwindcss-rails`. - Active Storage on local disk handles pictures, document pages, squawk attachments, and track logs. Identical files are stored once (hard links). - Chartkick and Chart.js draw the oil and fuel charts. diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb deleted file mode 100644 index 4264c74..0000000 --- a/app/channels/application_cable/connection.rb +++ /dev/null @@ -1,16 +0,0 @@ -module ApplicationCable - class Connection < ActionCable::Connection::Base - identified_by :current_user - - def connect - set_current_user || reject_unauthorized_connection - end - - private - def set_current_user - if session = Session.find_by(id: cookies.signed[:session_id]) - self.current_user = session.user - end - end - end -end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e661e36..fcf3c05 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -21,11 +21,6 @@ module ApplicationHelper title: Airworthiness::DISCLAIMER) end - def airworthiness_dot(status) - color = { "RED" => "bg-red-500", "LIMITED" => "bg-sky-500", "ORANGE" => "bg-amber-400", "GREEN" => "bg-emerald-500" }[status.status] - tag.span(class: "inline-block h-3 w-3 rounded-full #{color}", title: status.label) - end - # Badge class (or text class) for one airworthiness issue. def issue_badge_class(issue) = "badge-#{AIRWORTHINESS_COLORS[issue.severity]}" diff --git a/app/javascript/controllers/theme_controller.js b/app/javascript/controllers/theme_controller.js index 7efd5c2..4a31b06 100644 --- a/app/javascript/controllers/theme_controller.js +++ b/app/javascript/controllers/theme_controller.js @@ -6,8 +6,6 @@ const LABELS = { system: "System", light: "Light", dark: "Dark" } // Light / dark / follow-the-OS theme toggle. The choice is kept in // localStorage; the layout's inline script applies it before first paint. export default class extends Controller { - static targets = ["button"] - connect() { this.media = window.matchMedia("(prefers-color-scheme: dark)") this.onSystemChange = () => { if (this.choice === "system") this.apply() } diff --git a/app/models/airworthiness_directive.rb b/app/models/airworthiness_directive.rb index be8444e..fa4e5a2 100644 --- a/app/models/airworthiness_directive.rb +++ b/app/models/airworthiness_directive.rb @@ -30,12 +30,6 @@ class AirworthinessDirective < ApplicationRecord 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) - where(id: direct).or(where(id: via_component)) - end - def to_s = name # [url, label] for this AD's document, when we have its link (DRS Excel diff --git a/app/models/backup_run.rb b/app/models/backup_run.rb index f74e64b..72ac080 100644 --- a/app/models/backup_run.rb +++ b/app/models/backup_run.rb @@ -1,5 +1,4 @@ class BackupRun < ApplicationRecord scope :latest_first, -> { order(created_at: :desc) } def self.latest = latest_first.first - def self.last_good = where(ok: true).latest_first.first end diff --git a/app/models/concerns/shared_record_history.rb b/app/models/concerns/shared_record_history.rb index 1df6180..cffd87c 100644 --- a/app/models/concerns/shared_record_history.rb +++ b/app/models/concerns/shared_record_history.rb @@ -15,6 +15,15 @@ module SharedRecordHistory before_destroy { linked_aircraft_ids.each { |id| history!(id, "destroy", attributes.except(*IGNORED)) } } end + class_methods do + # Records that apply to the aircraft directly, or to one of its components. + def 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) + where(id: direct).or(where(id: via_component)) + end + end + # Aircraft this record applies to, directly or through a component. def linked_aircraft_ids = (aircraft_ids + components.map(&:aircraft_id)).compact.uniq diff --git a/app/models/entry_signature.rb b/app/models/entry_signature.rb index 4010728..adf5bd3 100644 --- a/app/models/entry_signature.rb +++ b/app/models/entry_signature.rb @@ -26,7 +26,6 @@ class EntrySignature < ApplicationRecord def imported? = origin.present? def certificate_label = UserCertificate::SHORT_LABELS.fetch(certificate_kind, certificate_kind) - def short_id = content_digest.first(12) def compute_seal payload = [ logbook_entry_id, user_id, signer_name, certificate_kind, certificate_number, statement, diff --git a/app/models/inspection_type.rb b/app/models/inspection_type.rb index da16dee..871d7b0 100644 --- a/app/models/inspection_type.rb +++ b/app/models/inspection_type.rb @@ -28,15 +28,7 @@ class InspectionType < ApplicationRecord scope :ordered, -> { order(:name) } - # Applies to the aircraft directly, or to one of its components. - 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) - where(id: direct).or(where(id: via_component)) - end - def to_s = name - def effect_label = EFFECTS[effect] def limitation = LIMITATIONS[effect] def advisory? = effect == "advisory" @@ -46,8 +38,6 @@ class InspectionType < ApplicationRecord InspectionRecord.for_aircraft(aircraft).where(inspection_type_id: [ id, *satisfied_by.ids ]) end - def latest_record_for(aircraft) = records_for(aircraft).recent_first.first - def due_rule { hours: recurring_hours.to_f, months: recurring_months, days: recurring_days } if recurring? end diff --git a/app/models/sso.rb b/app/models/sso.rb index 922afa5..b557af6 100644 --- a/app/models/sso.rb +++ b/app/models/sso.rb @@ -33,13 +33,4 @@ module Sso ENV["APP_URL"].presence&.chomp("/") || "#{ENV.fetch('FORCE_SSL', 'true') == 'true' ? 'https' : 'http'}://#{ENV.fetch('APP_HOST', 'localhost:3000')}" end - - # Origin of the provider, for the CSP form-action list (the sign-in POST - # redirects there). - def issuer_origin - uri = URI.parse(ENV["OIDC_ISSUER"].to_s) - uri.host && "#{uri.scheme}://#{uri.host}#{":#{uri.port}" unless uri.port == uri.default_port}" - rescue URI::InvalidURIError - nil - end end diff --git a/app/models/system_info.rb b/app/models/system_info.rb index d8f57c7..b85b880 100644 --- a/app/models/system_info.rb +++ b/app/models/system_info.rb @@ -3,14 +3,14 @@ class SystemInfo KEY_GEMS = %w[ puma thruster propshaft importmap-rails turbo-rails stimulus-rails tailwindcss-rails tailwindcss-ruby - solid_queue solid_cache solid_cable sqlite3 chartkick commonmarker anthropic + solid_queue solid_cache sqlite3 chartkick commonmarker anthropic omniauth omniauth_openid_connect rubyzip roo pdf-reader bcrypt ].freeze # Where the source lives; APP_REPOSITORY_URL overrides it for a fork. REPOSITORY_URL = ENV["APP_REPOSITORY_URL"].presence || "https://github.com/rickbarrette/simple-aircraft-manager-rails" - DATABASES = { "Main" => :primary, "Cache" => :cache, "Jobs" => :queue, "Cable" => :cable }.freeze + DATABASES = { "Main" => :primary, "Cache" => :cache, "Jobs" => :queue }.freeze # The release version, YYYY.MM.N (the repository's VERSION file). def version diff --git a/app/services/airworthiness.rb b/app/services/airworthiness.rb index 01f77d0..71cc108 100644 --- a/app/services/airworthiness.rb +++ b/app/services/airworthiness.rb @@ -27,7 +27,6 @@ class Airworthiness def limited? = status == LIMITED def orange? = status == ORANGE def green? = status == GREEN - def can_fly? = !red? def red_issues = issues.select { |i| i.severity == RED } def limitations = issues.filter_map(&:limitation).uniq diff --git a/app/services/compliance.rb b/app/services/compliance.rb index c49f193..1523ff5 100644 --- a/app/services/compliance.rb +++ b/app/services/compliance.rb @@ -38,31 +38,9 @@ module Compliance return Result.new(rank: OVERDUE) unless compliance return Result.new(rank: COMPLIANT) if compliance.closed? - rank = COMPLIANT - result = Result.new - + due_date = next_due(ad.due_rule, date: compliance.date_complied, hours: nil)[:date] if ad.recurring? && ad.recurring_calendar? due_hours = compliance.next_due_at_time.to_d - if due_hours > 0 - result.next_due_hours = due_hours - if current_hours >= due_hours - rank = OVERDUE - elsif current_hours + Airworthiness::HOURS_WARNING >= due_hours - rank = [ rank, DUE_SOON ].max - end - end - - if ad.recurring? && ad.recurring_calendar? - due = next_due(ad.due_rule, date: compliance.date_complied, hours: nil)[:date] - result.next_due_date = due - if today > due - rank = OVERDUE - elsif today + Airworthiness::DAYS_WARNING >= due - rank = [ rank, DUE_SOON ].max - end - end - - result.rank = rank - result + due_result(due_date, (due_hours if due_hours.positive?), current_hours, today) end # `records` are those that count for the type (InspectionType#records_for). @@ -77,32 +55,17 @@ module Compliance return Result.new(rank: OVERDUE) unless last_record return Result.new(rank: COMPLIANT) unless type.recurring? - rank = COMPLIANT - result = Result.new + due_date = next_due(type.due_rule, date: last_record.date, hours: nil)[:date] + due_result(due_date, next_due_hours(type, records), current_hours, today) + end - if type.recurring_months.positive? || type.recurring_days.positive? - due = last_record.date - due = end_of_month_after(due, type.recurring_months) if type.recurring_months.positive? - due += type.recurring_days.days if type.recurring_days.positive? - result.next_due_date = due - if today > due - rank = OVERDUE - elsif today + Airworthiness::DAYS_WARNING >= due - rank = [ rank, DUE_SOON ].max - end - end - - if (due_hours = next_due_hours(type, records)) - result.next_due_hours = due_hours - if current_hours >= due_hours - rank = OVERDUE - elsif current_hours + Airworthiness::HOURS_WARNING >= due_hours - rank = [ rank, DUE_SOON ].max - end - end - - result.rank = rank - result + # Overdue once the date has passed or the hours are reached; due soon + # within the warning window of either. + def due_result(due_date, due_hours, current_hours, today) + overdue = (due_date && today > due_date) || (due_hours && current_hours >= due_hours) + soon = (due_date && today + Airworthiness::DAYS_WARNING >= due_date) || + (due_hours && current_hours + Airworthiness::HOURS_WARNING >= due_hours) + Result.new(rank: overdue ? OVERDUE : (soon ? DUE_SOON : COMPLIANT), next_due_date: due_date, next_due_hours: due_hours) end def next_due_hours(type, records) diff --git a/app/services/flight_stats.rb b/app/services/flight_stats.rb index e06062c..120f96f 100644 --- a/app/services/flight_stats.rb +++ b/app/services/flight_stats.rb @@ -24,7 +24,6 @@ class FlightStats def total_fuel = @fuel.sum { _2.to_f }.round(1) def average_flight = count.zero? ? nil : (total_flight / count).round(1) - def shortest_flight = @flights.map { flight_hours(_1) }.min&.round(1) def longest_flight = @flights.map { flight_hours(_1) }.max&.round(1) # Gallons per tach hour over all fuel records. diff --git a/app/views/shared/_theme_toggle.html.erb b/app/views/shared/_theme_toggle.html.erb index c4d89ae..3ff24ee 100644 --- a/app/views/shared/_theme_toggle.html.erb +++ b/app/views/shared/_theme_toggle.html.erb @@ -1,5 +1,5 @@ <%# Cycles System → Light → Dark. Icons are swapped by theme_controller.js. %> -