mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Deferrals, expirations, standard inspections, reminders, squawk fixes
- Squawks: defer an inoperative item under 91.213(d) once each condition is confirmed (pilots may too); deferred items stop grounding and are listed for awareness. Resolving can record the fix as a logbook entry (43.9 fields) or link an existing one - Expiration dates on components (ELT battery, 91.207(c)) and documents; new document types (registration, airworthiness certificate, insurance, radio license). Expired replacement-critical parts and an expired registration (91.203) ground; others warn; registration warns 90 days out - Standard inspections: one click adds annual, 100-hour, 91.411, 91.413, ELT (91.207(d)) and VOR (91.171) checks with the right rules, skipping ones already tracked and linking annual to 100-hour - Weekly Monday reminder email to owners when something needs attention; profile opt-out; admin "send me this week's reminder" - README feature table updated Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a4ec7a691e
commit
61c3749793
41 files changed
+649
-48
No files matched your search
@@ -1,11 +1,23 @@
|
||||
class Admin::AboutController < ApplicationController
|
||||
before_action :require_admin!
|
||||
rate_limit to: 5, within: 1.minute, only: :test_email, with: -> { redirect_to admin_about_path, alert: "Try again in a minute." }
|
||||
rate_limit to: 5, within: 1.minute, only: %i[test_email test_reminder], with: -> { redirect_to admin_about_path, alert: "Try again in a minute." }
|
||||
|
||||
def show
|
||||
@info = SystemInfo.new
|
||||
end
|
||||
|
||||
# This week's reminder for the current admin, now.
|
||||
def test_reminder
|
||||
return redirect_to(admin_about_path, alert: "Email isn't set up yet.") unless MailSettings.configured?
|
||||
if ReminderMailer.items_for(current_user).empty?
|
||||
return redirect_to admin_about_path, notice: "Nothing needs attention on the aircraft you own, so there's no reminder to send."
|
||||
end
|
||||
ReminderMailer.weekly(current_user).deliver_now
|
||||
redirect_to admin_about_path, notice: "Reminder sent to #{current_user.email_address}."
|
||||
rescue StandardError => e
|
||||
redirect_to admin_about_path, alert: "Sending failed: #{e.class.name.demodulize}: #{e.message.to_s.squish.truncate(240)}"
|
||||
end
|
||||
|
||||
# Sends right away (not via the job queue) so problems show up here.
|
||||
def test_email
|
||||
unless MailSettings.configured?
|
||||
|
||||
@@ -78,7 +78,7 @@ class ComponentsController < ApplicationController
|
||||
:install_location, :notes, :status, :date_in_service, :hours_in_service,
|
||||
:hours_since_overhaul, :overhaul_date, :tbo_hours, :tbo_days, :inspection_hours,
|
||||
:inspection_days, :replacement_hours, :replacement_days, :tbo_critical, :on_condition,
|
||||
:inspection_critical, :replacement_critical
|
||||
:inspection_critical, :replacement_critical, :expires_on
|
||||
).tap do |p|
|
||||
# Owners can create a component type inline instead of asking an admin.
|
||||
if (name = params[:new_component_type].to_s.strip).present?
|
||||
|
||||
@@ -126,7 +126,7 @@ class DocumentsController < ApplicationController
|
||||
def set_document = @document = @aircraft.documents.find(params[:id])
|
||||
|
||||
def document_params
|
||||
p = params.require(:document).permit(:name, :description, :doc_type, :visibility, :document_collection_id, pages: [])
|
||||
p = params.require(:document).permit(:name, :description, :doc_type, :visibility, :document_collection_id, :expires_on, pages: [])
|
||||
p[:pages]&.compact_blank!
|
||||
p.delete(:pages) if p[:pages].blank?
|
||||
p[:document_collection_id] = scoped_id(@aircraft.document_collections, p[:document_collection_id])
|
||||
|
||||
@@ -7,7 +7,7 @@ class ProfilesController < ApplicationController
|
||||
# left open somewhere can't be turned into a takeover of the account.
|
||||
def update
|
||||
@user = current_user
|
||||
attrs = params.require(:user).permit(:name, :email_address, :password, :password_confirmation)
|
||||
attrs = params.require(:user).permit(:name, :email_address, :password, :password_confirmation, :reminder_emails)
|
||||
attrs = attrs.except(:password, :password_confirmation) if attrs[:password].blank?
|
||||
new_email = User.normalize_value_for(:email_address, attrs[:email_address].to_s) if attrs.key?(:email_address)
|
||||
sensitive = (new_email && new_email != @user.email_address) || attrs.key?(:password)
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
class SquawksController < ApplicationController
|
||||
include AircraftScoped
|
||||
# Pilots may create squawks; editing/resolving needs an owner.
|
||||
before_action :require_owner!, except: %i[index new create]
|
||||
before_action :set_squawk, only: %i[edit update destroy resolve reopen]
|
||||
# Pilots may create squawks and defer inoperative items (91.213(d) lets the
|
||||
# pilot decide); editing and resolving need an owner.
|
||||
before_action :require_owner!, except: %i[index new create deferral defer]
|
||||
before_action :set_squawk, only: %i[edit update destroy resolution resolve reopen deferral defer undefer]
|
||||
|
||||
def index
|
||||
@active = @aircraft.squawks.active.by_priority.includes(:component, :reported_by).with_attached_attachments
|
||||
@resolved = @aircraft.squawks.resolved.order(resolved_at: :desc).includes(:component).with_attached_attachments.limit(100)
|
||||
@resolved = @aircraft.squawks.resolved.order(resolved_at: :desc).includes(:component, :logbook_entry).with_attached_attachments.limit(100)
|
||||
end
|
||||
|
||||
def new
|
||||
@@ -36,10 +37,45 @@ class SquawksController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# Resolve form: record the fix in the logbook (who returned it to
|
||||
# service, 43.9), link an existing entry, or just close the squawk.
|
||||
def resolution
|
||||
@entry = @aircraft.logbook_entries.new(date: Date.current, entry_type: "MAINTENANCE", log_type: "AC",
|
||||
aircraft_hours_at_entry: @aircraft.current_hours,
|
||||
text: "Corrected: #{@squawk.issue_reported}")
|
||||
end
|
||||
|
||||
def resolve
|
||||
@squawk.resolve!(notes: params[:resolution_notes])
|
||||
entry =
|
||||
case params[:logbook]
|
||||
when "new"
|
||||
@entry = @aircraft.logbook_entries.new(resolution_entry_params.merge(entry_type: "MAINTENANCE"))
|
||||
return render(:resolution, status: :unprocessable_entity) unless @entry.save
|
||||
log_event("logbook", "Logbook entry added: #{@entry.date}")
|
||||
@entry
|
||||
when "existing" then @aircraft.logbook_entries.find_by(id: params[:logbook_entry_id])
|
||||
end
|
||||
@squawk.resolve!(notes: params[:resolution_notes], logbook_entry: entry)
|
||||
log_event("squawk", "Squawk resolved", notes: @squawk.issue_reported.truncate(200))
|
||||
redirect_back fallback_location: aircraft_squawks_path(@aircraft), notice: "Squawk resolved."
|
||||
redirect_to aircraft_squawks_path(@aircraft), notice: "Squawk resolved#{' and recorded in the logbook' if entry}."
|
||||
end
|
||||
|
||||
def deferral; end
|
||||
|
||||
def defer
|
||||
if @squawk.defer(checks: params[:checks], name: params[:deferred_by_name], role: params[:deferred_by_role],
|
||||
action: params[:deferral_action], notes: params[:deferral_notes])
|
||||
log_event("squawk", "Inoperative item deferred (91.213(d))", notes: @squawk.issue_reported.truncate(200))
|
||||
redirect_to aircraft_squawks_path(@aircraft), notice: "Deferred. Keep the placard in place until it's fixed."
|
||||
else
|
||||
render :deferral, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def undefer
|
||||
@squawk.undefer!
|
||||
log_event("squawk", "Deferral removed", notes: @squawk.issue_reported.truncate(200))
|
||||
redirect_to aircraft_squawks_path(@aircraft), notice: "Deferral removed."
|
||||
end
|
||||
|
||||
def reopen
|
||||
@@ -58,6 +94,11 @@ class SquawksController < ApplicationController
|
||||
|
||||
def set_squawk = @squawk = @aircraft.squawks.find(params[:id])
|
||||
|
||||
def resolution_entry_params
|
||||
params.require(:logbook_entry).permit(:date, :log_type, :text, :aircraft_hours_at_entry, :signoff_person,
|
||||
:signoff_certificate_type, :signoff_certificate_number, :signoff_location)
|
||||
end
|
||||
|
||||
# Adds uploads and drops ticked files in one change, so nothing is saved
|
||||
# (or purged) unless the whole update validates.
|
||||
def change_attachments
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
class StandardInspectionsController < ApplicationController
|
||||
include AircraftScoped
|
||||
before_action :require_owner!
|
||||
|
||||
def new; end
|
||||
|
||||
def create
|
||||
added = StandardInspections.add!(@aircraft, params[:templates])
|
||||
if added.any?
|
||||
log_event("inspection", "Standard inspections added", notes: added.map(&:name).join(", "))
|
||||
redirect_to aircraft_inspections_path(@aircraft), notice: "Added #{added.map(&:name).to_sentence}. Record when each was last done to see when it's next due."
|
||||
else
|
||||
redirect_to new_aircraft_standard_inspections_path(@aircraft), alert: "Nothing new was chosen."
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user