From 03b9ad65cbdaed967ec9c6c287263c4817488caa Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Sat, 14 Nov 2026 07:43:03 -0500 Subject: [PATCH] Workflow polish: setup checklist, next leg, grouped component limits - Setup checklist on a new aircraft's Overview (owners): components, standard inspections, DRS AD import, registration/airworthiness certificate, weight and balance; hideable per device - Log Flight: "Save and log next leg" reopens the form on the same date, starting where the leg ended - Component form: limits in two collapsible groups (replacement and expiry; overhaul and TBO), open when in use - Squawk form warns what "Ground Aircraft" does - Logbook entry form: inspection result only for inspection entries (show-when controller); document names default from the file - Dates in pickers, the activity log, airworthiness lines, search, audits and transcription notes use the app format - No duplicate Report Squawk button on Squawks; "Record service" label Co-Authored-By: Claude Opus 5.5 --- app/controllers/documents_controller.rb | 1 + app/controllers/flight_logs_controller.rb | 15 +++- app/controllers/logbook_entries_controller.rb | 16 ++-- app/controllers/oil_analyses_controller.rb | 6 +- .../signing_invitations_controller.rb | 2 +- app/controllers/squawks_controller.rb | 2 +- .../weight_balance_records_controller.rb | 4 +- app/helpers/aircraft_helper.rb | 13 +++- .../controllers/dismiss_controller.js | 15 ++++ .../controllers/entry_template_controller.js | 5 +- .../controllers/name_from_file_controller.js | 13 ++++ .../controllers/show_when_controller.js | 20 +++++ app/jobs/logbook_transcription_job.rb | 4 +- app/services/airworthiness.rb | 12 +-- app/services/entry_signer.rb | 2 +- app/services/records_audit.rb | 2 +- app/services/records_integrity.rb | 2 +- app/services/site_search.rb | 4 +- app/views/aircraft/_setup.html.erb | 28 +++++++ app/views/aircraft/show.html.erb | 1 + app/views/components/_form.html.erb | 52 ++++++++----- app/views/documents/_form.html.erb | 6 +- app/views/flight_logs/new.html.erb | 6 +- app/views/logbook_entries/_form.html.erb | 11 ++- app/views/squawks/_form.html.erb | 10 ++- app/views/squawks/index.html.erb | 1 - config/locales/en.yml | 34 +++++++- .../integration/electronic_signatures_test.rb | 2 +- test/integration/logbook_entry_parts_test.rb | 4 +- test/integration/oil_analysis_flow_test.rb | 2 +- test/integration/pwa_features_test.rb | 4 +- test/integration/records_integrity_test.rb | 2 +- test/integration/user_certificates_test.rb | 2 +- test/integration/workflow_polish_test.rb | 77 +++++++++++++++++++ 34 files changed, 303 insertions(+), 77 deletions(-) create mode 100644 app/javascript/controllers/dismiss_controller.js create mode 100644 app/javascript/controllers/name_from_file_controller.js create mode 100644 app/javascript/controllers/show_when_controller.js create mode 100644 app/views/aircraft/_setup.html.erb create mode 100644 test/integration/workflow_polish_test.rb diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 267e2fb..6d70f8f 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -14,6 +14,7 @@ class DocumentsController < ApplicationController def new @document = @aircraft.documents.new(document_collection_id: params[:collection_id]) + @document.doc_type = params[:doc_type] if Document::TYPES.key?(params[:doc_type]) end def create diff --git a/app/controllers/flight_logs_controller.rb b/app/controllers/flight_logs_controller.rb index 297141e..28322f7 100644 --- a/app/controllers/flight_logs_controller.rb +++ b/app/controllers/flight_logs_controller.rb @@ -49,7 +49,13 @@ class FlightLogsController < ApplicationController def new # Aircraft almost always depart from where they last landed. last = @aircraft.flight_logs.where.not(destination_location: [ nil, "" ]).recent_first.first - @flight_log = @aircraft.flight_logs.new(date: Date.current, tach_out: @aircraft.tach_time, + # "Save and log next leg" comes back here with that flight's date. + date = begin + Date.iso8601(params[:date].to_s) + rescue Date::Error + Date.current + end + @flight_log = @aircraft.flight_logs.new(date: date, tach_out: @aircraft.tach_time, hobbs_out: @aircraft.hobbs_time, departure_location: last&.destination_location) end @@ -62,7 +68,12 @@ class FlightLogsController < ApplicationController @flight_log = @aircraft.flight_logs.new(flight_log_params) if @flight_log.valid? HoursService.new(@aircraft).log_flight!(@flight_log) - redirect_to aircraft_flight_logs_path(@aircraft), notice: t("flash.flight_logs.flight_logged_hrs", tach_time: @flight_log.tach_time) + notice = t("flash.flight_logs.flight_logged_hrs", tach_time: @flight_log.tach_time) + if params[:next_leg].present? + redirect_to new_aircraft_flight_log_path(@aircraft, date: @flight_log.date.iso8601), notice: "#{notice} #{t('flash.flight_logs.next_leg')}" + else + redirect_to aircraft_flight_logs_path(@aircraft), notice: notice + end else render :new, status: :unprocessable_entity end diff --git a/app/controllers/logbook_entries_controller.rb b/app/controllers/logbook_entries_controller.rb index a46cf1e..1b49bad 100644 --- a/app/controllers/logbook_entries_controller.rb +++ b/app/controllers/logbook_entries_controller.rb @@ -18,7 +18,7 @@ class LogbookEntriesController < ApplicationController # Someone has checked a transcribed entry against the scan. def verify @entry.update!(verified: true) - log_event("logbook", t("flash.logbook_entries.transcribed_logbook_entry_verified", date: @entry.date)) + log_event("logbook", t("flash.logbook_entries.transcribed_logbook_entry_verified", date: l(@entry.date, format: :app))) next_entry = @aircraft.logbook_entries.unverified.order(:date, :id).first redirect_to next_entry ? aircraft_logbook_entry_path(@aircraft, next_entry) : aircraft_logbook_entries_path(@aircraft), notice: next_entry ? t("flash.logbook_entries.verified_next") : t("flash.logbook_entries.verified_all") @@ -36,7 +36,7 @@ class LogbookEntriesController < ApplicationController @entry.supersedes = correctable(params.dig(:logbook_entry, :supersedes_id)) @entry.assign_parts(parts_params, @aircraft) if @entry.save - log_event("logbook", t(@entry.supersedes ? "flash.logbook_entries.correction_added_event" : "flash.logbook_entries.logbook_entry_added", date: @entry.date)) + log_event("logbook", t(@entry.supersedes ? "flash.logbook_entries.correction_added_event" : "flash.logbook_entries.logbook_entry_added", date: l(@entry.date, format: :app))) record_parts_service record_inspections redirect_to aircraft_logbook_entry_path(@aircraft, @entry), @@ -52,7 +52,7 @@ class LogbookEntriesController < ApplicationController @entry.assign_attributes(entry_params) @entry.assign_parts(parts_params, @aircraft) if @entry.save - log_event("logbook", t("flash.logbook_entries.logbook_entry_updated_2", date: @entry.date)) + log_event("logbook", t("flash.logbook_entries.logbook_entry_updated_2", date: l(@entry.date, format: :app))) redirect_to aircraft_logbook_entry_path(@aircraft, @entry), notice: t("flash.logbook_entries.logbook_entry_updated") else render :edit, status: :unprocessable_entity @@ -61,7 +61,7 @@ class LogbookEntriesController < ApplicationController def destroy @entry.destroy! - log_event("logbook", t("flash.logbook_entries.logbook_entry_deleted_2", date: @entry.date)) + log_event("logbook", t("flash.logbook_entries.logbook_entry_deleted_2", date: l(@entry.date, format: :app))) redirect_to aircraft_logbook_entries_path(@aircraft), notice: t("flash.logbook_entries.logbook_entry_deleted") end @@ -98,8 +98,8 @@ class LogbookEntriesController < ApplicationController next unless p["include"] == "1" && %w[serviced replaced].include?(p["service"]) part = @entry.parts.find { _1.component_id == id.to_i } or next component = part.component - component.service_from_entry!(date: @entry.date, hours_at_entry: part.hours_at_entry, flown_since: flown, replaced: p["service"] == "replaced") - log_event("component", t(p["service"] == "replaced" ? "flash.logbook_entries.replaced_event" : "flash.logbook_entries.serviced_event", component: component, date: @entry.date)) + component.service_from_entry!(date: l(@entry.date, format: :app), hours_at_entry: part.hours_at_entry, flown_since: flown, replaced: p["service"] == "replaced") + log_event("component", t(p["service"] == "replaced" ? "flash.logbook_entries.replaced_event" : "flash.logbook_entries.serviced_event", component: component, date: l(@entry.date, format: :app))) end end @@ -108,9 +108,9 @@ class LogbookEntriesController < ApplicationController def record_inspections ids = Array(params.dig(:logbook_entry, :inspection_type_ids)).compact_blank @aircraft.applicable_inspection_types.where(id: ids).find_each do |type| - @aircraft.inspection_records.create!(inspection_type: type, logbook_entry: @entry, date: @entry.date, + @aircraft.inspection_records.create!(inspection_type: type, logbook_entry: @entry, date: l(@entry.date, format: :app), aircraft_hours: @entry.aircraft_hours_at_entry) - log_event("inspection", t("flash.logbook_entries.inspection_completed_logbook_entry", name: type.name, date: @entry.date)) + log_event("inspection", t("flash.logbook_entries.inspection_completed_logbook_entry", name: type.name, date: l(@entry.date, format: :app))) end end diff --git a/app/controllers/oil_analyses_controller.rb b/app/controllers/oil_analyses_controller.rb index 0223a58..fc6c301 100644 --- a/app/controllers/oil_analyses_controller.rb +++ b/app/controllers/oil_analyses_controller.rb @@ -24,7 +24,7 @@ class OilAnalysesController < ApplicationController def create @analysis = @aircraft.oil_analyses.new(analysis_params) if @analysis.save - log_event("oil_analysis", t("flash.oil_analyses.oil_analysis_added_sampled", sample_date: @analysis.sample_date)) + log_event("oil_analysis", t("flash.oil_analyses.oil_analysis_added_sampled", sample_date: l(@analysis.sample_date, format: :app))) redirect_to aircraft_oil_analysis_path(@aircraft, @analysis), notice: t("flash.oil_analyses.oil_analysis_saved") else render :new, status: :unprocessable_entity @@ -69,7 +69,7 @@ class OilAnalysesController < ApplicationController def update if @analysis.update(analysis_params) - log_event("oil_analysis", t("flash.oil_analyses.oil_analysis_updated_sampled", sample_date: @analysis.sample_date)) + log_event("oil_analysis", t("flash.oil_analyses.oil_analysis_updated_sampled", sample_date: l(@analysis.sample_date, format: :app))) redirect_to aircraft_oil_analysis_path(@aircraft, @analysis), notice: t("flash.oil_analyses.oil_analysis_updated") else render :edit, status: :unprocessable_entity @@ -78,7 +78,7 @@ class OilAnalysesController < ApplicationController def destroy @analysis.destroy! - log_event("oil_analysis", t("flash.oil_analyses.oil_analysis_deleted_sampled", sample_date: @analysis.sample_date)) + log_event("oil_analysis", t("flash.oil_analyses.oil_analysis_deleted_sampled", sample_date: l(@analysis.sample_date, format: :app))) redirect_to aircraft_oil_analyses_path(@aircraft), notice: t("flash.oil_analyses.oil_analysis_deleted") end diff --git a/app/controllers/signing_invitations_controller.rb b/app/controllers/signing_invitations_controller.rb index f0a1d10..af662d5 100644 --- a/app/controllers/signing_invitations_controller.rb +++ b/app/controllers/signing_invitations_controller.rb @@ -21,7 +21,7 @@ class SigningInvitationsController < ApplicationController PushNotifier.notify(invitee, :signing_request, path: invited_signing_path(@invitation.token), tag: "sign-#{@invitation.id}", tail: @aircraft.tail_number, name: current_user.display_name) end - log_event("logbook", t("flash.signing_invitations.signature_requested_from_entry", email: @invitation.email, date: @entry.date)) + log_event("logbook", t("flash.signing_invitations.signature_requested_from_entry", email: @invitation.email, date: l(@entry.date, format: :app))) redirect_to aircraft_logbook_entry_path(@aircraft, @entry), notice: t("flash.signing_invitations.invitation_sent_to_the", email: @invitation.email, days: SigningInvitation::VALID_FOR.in_days.to_i) else render :new, status: :unprocessable_entity diff --git a/app/controllers/squawks_controller.rb b/app/controllers/squawks_controller.rb index 0dd74f9..faaad7a 100644 --- a/app/controllers/squawks_controller.rb +++ b/app/controllers/squawks_controller.rb @@ -64,7 +64,7 @@ class SquawksController < ApplicationController @entry = @aircraft.logbook_entries.new(resolution_entry_params.merge(entry_type: "MAINTENANCE")) @entry.assign_parts(params.fetch(:logbook_entry, {}).permit(parts: {})[:parts]&.to_h || {}, @aircraft) return render(:resolution, status: :unprocessable_entity) unless @entry.save - log_event("logbook", t("flash.squawks.logbook_entry_added", date: @entry.date)) + log_event("logbook", t("flash.squawks.logbook_entry_added", date: l(@entry.date, format: :app))) @entry when "existing" then @aircraft.logbook_entries.find_by(id: params[:logbook_entry_id]) end diff --git a/app/controllers/weight_balance_records_controller.rb b/app/controllers/weight_balance_records_controller.rb index 05a7dd8..3f19d91 100644 --- a/app/controllers/weight_balance_records_controller.rb +++ b/app/controllers/weight_balance_records_controller.rb @@ -30,7 +30,7 @@ class WeightBalanceRecordsController < ApplicationController def update if @record.update(record_params) - log_event("aircraft", t("flash.weight_balance_records.weight_balance_updated_2", date: @record.date)) + log_event("aircraft", t("flash.weight_balance_records.weight_balance_updated_2", date: l(@record.date, format: :app))) redirect_to aircraft_weight_balance_records_path(@aircraft), notice: t("flash.weight_balance_records.weight_balance_updated") else render :edit, status: :unprocessable_entity @@ -39,7 +39,7 @@ class WeightBalanceRecordsController < ApplicationController def destroy @record.destroy! - log_event("aircraft", t("flash.weight_balance_records.weight_balance_record_deleted", date: @record.date)) + log_event("aircraft", t("flash.weight_balance_records.weight_balance_record_deleted", date: l(@record.date, format: :app))) redirect_to aircraft_weight_balance_records_path(@aircraft), notice: t("flash.weight_balance_records.record_deleted") end diff --git a/app/helpers/aircraft_helper.rb b/app/helpers/aircraft_helper.rb index 7e575d1..8a52fb2 100644 --- a/app/helpers/aircraft_helper.rb +++ b/app/helpers/aircraft_helper.rb @@ -30,6 +30,17 @@ module AircraftHelper ] end + # Getting a new aircraft set up (Overview): [key, done?, path] for each step. + def setup_steps(aircraft) + [ + [ :components, aircraft.components.exists?, new_aircraft_component_path(aircraft) ], + [ :inspections, aircraft.applicable_inspection_types.exists?, new_aircraft_standard_inspections_path(aircraft) ], + [ :ads, aircraft.drs_imports.exists? || aircraft.applicable_ads.exists?, new_aircraft_ad_import_path(aircraft) ], + [ :documents, aircraft.documents.where(doc_type: %w[REGISTRATION AIRWORTHINESS_CERT]).exists?, new_aircraft_document_path(aircraft, doc_type: "REGISTRATION") ], + [ :weight_balance, aircraft.weight_balance_records.exists?, new_aircraft_weight_balance_record_path(aircraft) ] + ] + end + def component_options(aircraft, include_blank: true) opts = aircraft.components.where.not(status: "DISPOSED").includes(:component_type).map { [ _1.to_s, _1.id ] } include_blank ? [ [ I18n.t("helpers.aircraft.none"), nil ] ] + opts : opts @@ -40,6 +51,6 @@ module AircraftHelper end def logbook_options(aircraft) - [ [ I18n.t("helpers.aircraft.none"), nil ] ] + aircraft.logbook_entries.recent_first.limit(300).map { [ I18n.t("helpers.aircraft.text", date: _1.date, truncate: (_1.text.truncate(60))), _1.id ] } + [ [ I18n.t("helpers.aircraft.none"), nil ] ] + aircraft.logbook_entries.recent_first.limit(300).map { [ I18n.t("helpers.aircraft.entry_option", date: fmt_date(_1.date), text: _1.text.truncate(60)), _1.id ] } end end diff --git a/app/javascript/controllers/dismiss_controller.js b/app/javascript/controllers/dismiss_controller.js new file mode 100644 index 0000000..af8445a --- /dev/null +++ b/app/javascript/controllers/dismiss_controller.js @@ -0,0 +1,15 @@ +import { Controller } from "@hotwired/stimulus" + +// A card that can be hidden for good on this device (e.g. the setup checklist). +export default class extends Controller { + static values = { key: String } + + connect() { + try { if (localStorage.getItem(this.keyValue)) this.element.hidden = true } catch (_) { /* storage off */ } + } + + hide() { + try { localStorage.setItem(this.keyValue, "1") } catch (_) { /* storage off */ } + this.element.hidden = true + } +} diff --git a/app/javascript/controllers/entry_template_controller.js b/app/javascript/controllers/entry_template_controller.js index 01cc6b2..14419c1 100644 --- a/app/javascript/controllers/entry_template_controller.js +++ b/app/javascript/controllers/entry_template_controller.js @@ -13,7 +13,10 @@ export default class extends Controller { if (this.textTarget.value.trim() && !confirm(t("entry_template.confirm"))) return const { text, entryType, logType, certificate } = option.dataset this.textTarget.value = text - if (entryType && this.hasEntryTypeTarget) this.entryTypeTarget.value = entryType + if (entryType && this.hasEntryTypeTarget) { + this.entryTypeTarget.value = entryType + this.entryTypeTarget.dispatchEvent(new Event("change", { bubbles: true })) + } if (logType && this.hasLogTypeTarget && this.logTypeTarget.value !== logType) { this.logTypeTarget.value = logType this.logTypeTarget.dispatchEvent(new Event("change", { bubbles: true })) diff --git a/app/javascript/controllers/name_from_file_controller.js b/app/javascript/controllers/name_from_file_controller.js new file mode 100644 index 0000000..7924882 --- /dev/null +++ b/app/javascript/controllers/name_from_file_controller.js @@ -0,0 +1,13 @@ +import { Controller } from "@hotwired/stimulus" + +// A new document's name, when left blank, comes from its first file's name +// ("annual-2026_scan.pdf" → "annual 2026 scan"). +export default class extends Controller { + static targets = [ "name", "file" ] + + fill() { + const file = this.fileTarget.files[0] + if (!file || this.nameTarget.value.trim()) return + this.nameTarget.value = file.name.replace(/\.[^.]+$/, "").replace(/[_-]+/g, " ").replace(/\s+/g, " ").trim() + } +} diff --git a/app/javascript/controllers/show_when_controller.js b/app/javascript/controllers/show_when_controller.js new file mode 100644 index 0000000..152a45e --- /dev/null +++ b/app/javascript/controllers/show_when_controller.js @@ -0,0 +1,20 @@ +import { Controller } from "@hotwired/stimulus" + +// Shows parts of a form only when a select has a given value, e.g. the +// inspection result only for inspection entries. A part hidden by changing +// the select is cleared, so it isn't saved. +//