Files
simple-aircraft-manager-rails/app/controllers/airworthiness_directives_controller.rb
T
rickyandClaude Opus 5.5 89ed0a76f9 Move all user-facing text into config/locales/en.yml for localization
- Views use lazy t(".key") lookups; sentences with values or links stay
  whole (interpolation, _html keys); counts use one/other plurals
- Stored-value labels (statuses, types, priorities...) are LabelSets read
  from labels: in the current locale; field names and validation messages
  under activerecord:; flash and activity text under flash:
- Services, models, helpers, mailer subjects, the logbook PDF, procedures
  templates, records package README and transcription warnings localized;
  the PDF reuses LogbookEntry#certification_statement instead of a copy
- Scripts read js: strings from a JSON tag via app/javascript/i18n.js
- Dates through I18n.l (app, weekday, month_year, long formats); html lang
  follows the locale
- APP_LOCALE picks the language (falls back to English); missing
  translations raise in development and tests
- README: Translating section and APP_LOCALE

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 22:08:20 -05:00

77 lines
3.4 KiB
Ruby

class AirworthinessDirectivesController < ApplicationController
include AircraftScoped
include Applicability
before_action :require_owner!, except: :index
before_action :set_ad, only: %i[edit update destroy]
def index
@rows = Compliance.ad_rows(@aircraft)
@history = AdCompliance.for_aircraft(@aircraft).recent_first
.includes(:component, :logbook_entry, airworthiness_directive: :document, inspection_record: :inspection_type)
@attachable = AirworthinessDirective.where.not(id: @aircraft.applicable_ads.select(:id)).ordered if owner?
@alerts = @aircraft.ad_alerts.pending
end
def new
@ad = AirworthinessDirective.new
@applies_to_airframe = true
end
def create
@ad = AirworthinessDirective.new(ad_params)
AirworthinessDirective.transaction do
@ad.save!
apply_applicability(@ad, to_airframe: applies_to_airframe?, component_ids: applicable_component_ids)
end
log_event("ad", t("flash.airworthiness_directives.added_2", bulletin_label: @ad.bulletin_label, name: @ad.name))
redirect_to aircraft_airworthiness_directives_path(@aircraft), notice: t("flash.airworthiness_directives.added", bulletin_label: @ad.bulletin_label)
rescue ActiveRecord::RecordInvalid
@applies_to_airframe = applies_to_airframe?
render :new, status: :unprocessable_entity
end
# Link an AD that already exists (e.g. tracked on another aircraft).
def attach
ad = AirworthinessDirective.find(params[:airworthiness_directive_id])
ad.aircraft << @aircraft unless ad.aircraft.include?(@aircraft)
log_event("ad", t("flash.airworthiness_directives.linked_2", bulletin_label: ad.bulletin_label, name: ad.name))
redirect_to aircraft_airworthiness_directives_path(@aircraft), notice: t("flash.airworthiness_directives.linked", name: ad.name)
end
def edit
@applies_to_airframe = @ad.aircraft.include?(@aircraft)
end
def update
AirworthinessDirective.transaction do
@ad.update!(ad_params)
apply_applicability(@ad, to_airframe: applies_to_airframe?, component_ids: applicable_component_ids)
end
log_event("ad", t("flash.airworthiness_directives.updated_2", bulletin_label: @ad.bulletin_label, name: @ad.name))
redirect_to aircraft_airworthiness_directives_path(@aircraft), notice: t("flash.airworthiness_directives.updated", bulletin_label: @ad.bulletin_label)
rescue ActiveRecord::RecordInvalid
@applies_to_airframe = applies_to_airframe?
render :edit, status: :unprocessable_entity
end
# Removes the AD from this aircraft (the shared AD record survives if other aircraft use it).
def destroy
detach_from_aircraft(@ad)
log_event("ad", t("flash.airworthiness_directives.removed", bulletin_label: @ad.bulletin_label, name: @ad.name))
redirect_to aircraft_airworthiness_directives_path(@aircraft), notice: t("flash.airworthiness_directives.removed_from", name: @ad.name, tail_number: @aircraft.tail_number)
end
private
def set_ad = @ad = @aircraft.applicable_ads.find(params[:id])
def ad_params
p = params.require(:airworthiness_directive).permit(
:name, :short_description, :required_action, :compliance_type, :trigger_condition, :recurring,
:recurring_hours, :recurring_months, :recurring_days, :recurring_every, :recurring_unit, :bulletin_type, :mandatory, :document_id, :document_url
)
p[:document_id] = scoped_id(@aircraft.documents, p[:document_id])
p
end
end