diff --git a/app/models/component.rb b/app/models/component.rb index b4b52db..32dbcb1 100644 --- a/app/models/component.rb +++ b/app/models/component.rb @@ -49,6 +49,9 @@ class Component < ApplicationRecord def engine? = component_type&.name.to_s.match?(/engine/i) def propeller? = component_type&.name.to_s.match?(/propell?er|\bprop\b/i) + # "On condition" means TBO isn't a limit, so it's never also a hard limit. + before_validation { self.tbo_critical = false if on_condition? } + def hours_to_tbo tbo_hours - hours_since_overhaul if tbo_hours end diff --git a/app/services/records_package.rb b/app/services/records_package.rb index 7e0cb9d..4052abb 100644 --- a/app/services/records_package.rb +++ b/app/services/records_package.rb @@ -95,16 +95,17 @@ class RecordsPackage # The status report as one self-contained HTML file (styles inlined). def status_report_html - inline_styles(ApplicationController.render("maintenance_reports/show", layout: "report", assigns: { report: MaintenanceReport.new(@aircraft) })) + inline_styles(ApplicationController.render("maintenance_reports/show", layout: "report", assigns: { report: MaintenanceReport.new(@aircraft), standalone: true })) end def standalone_html(body, title) - inline_styles(ApplicationController.render(html: body.html_safe, layout: "report", assigns: {}).sub(%r{.*?}m, "#{ERB::Util.h(title)}")) + inline_styles(ApplicationController.render(html: body.html_safe, layout: "report", assigns: { standalone: true }).sub(%r{.*?}m) { "#{ERB::Util.h(title)}" }) end def inline_styles(html) css = %w[tailwind.css application.css].filter_map { Rails.application.assets.load_path.find(_1)&.content }.join("\n") - html.gsub(%r{]*>\s*}, "").sub("", "") + # Block forms: a replacement string would treat "\\&" etc. in the CSS as back-references. + html.gsub(%r{]*>\s*}) { "" }.sub("") { "" } .gsub(%r{]*>.*?}m, "").gsub(%r{]*>\s*}, "") end end diff --git a/app/views/components/_form.html.erb b/app/views/components/_form.html.erb index e3de65b..d77b29b 100644 --- a/app/views/components/_form.html.erb +++ b/app/views/components/_form.html.erb @@ -37,7 +37,8 @@
<%= f.field :tbo_critical, as: :checkbox, label: "Treat TBO as a hard limit", hint: "Under Part 91, TBO is usually the manufacturer's recommendation, unless an AD or the Airworthiness Limitations make it mandatory." %> - <%= f.field :on_condition, as: :checkbox, label: "On condition (Part 91)" %> + <%= f.field :on_condition, as: :checkbox, label: "On condition (Part 91)", + hint: "Run past TBO based on condition: TBO is shown for reference, never as a limit (this overrides the hard limit)." %>
<%= f.field :inspection_hours, as: :number, label: "Inspect every (hrs)" %> <%= f.field :inspection_days, as: :number, label: "Inspect every (days)" %> diff --git a/app/views/layouts/report.html.erb b/app/views/layouts/report.html.erb index a06ab2c..d5b6e99 100644 --- a/app/views/layouts/report.html.erb +++ b/app/views/layouts/report.html.erb @@ -6,7 +6,7 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> - + <% unless @standalone %><% end %> <%= stylesheet_link_tag :app, "data-turbo-track": "reload" %> <%= javascript_importmap_tags %>