mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Records package: intact status-report styles, no in-app controls; on-condition TSO
- Inlining CSS used String#sub with a replacement string, so "\&" in escaped selectors became "</head>"; use block replacements - Packaged status report and procedures omit the Back link, the print button and the favicon link (they don't work outside the app) - Status report: "On condition (Part 91)" as Tracked as, with remaining hours shown for reference; on condition clears the hard-limit flag Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2fe2f464c1
commit
5471b9317f
6 files changed
+31
-7
No files matched your search
@@ -49,6 +49,9 @@ class Component < ApplicationRecord
|
|||||||
def engine? = component_type&.name.to_s.match?(/engine/i)
|
def engine? = component_type&.name.to_s.match?(/engine/i)
|
||||||
def propeller? = component_type&.name.to_s.match?(/propell?er|\bprop\b/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
|
def hours_to_tbo
|
||||||
tbo_hours - hours_since_overhaul if tbo_hours
|
tbo_hours - hours_since_overhaul if tbo_hours
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -95,16 +95,17 @@ class RecordsPackage
|
|||||||
|
|
||||||
# The status report as one self-contained HTML file (styles inlined).
|
# The status report as one self-contained HTML file (styles inlined).
|
||||||
def status_report_html
|
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
|
end
|
||||||
|
|
||||||
def standalone_html(body, title)
|
def standalone_html(body, title)
|
||||||
inline_styles(ApplicationController.render(html: body.html_safe, layout: "report", assigns: {}).sub(%r{<title>.*?</title>}m, "<title>#{ERB::Util.h(title)}</title>"))
|
inline_styles(ApplicationController.render(html: body.html_safe, layout: "report", assigns: { standalone: true }).sub(%r{<title>.*?</title>}m) { "<title>#{ERB::Util.h(title)}</title>" })
|
||||||
end
|
end
|
||||||
|
|
||||||
def inline_styles(html)
|
def inline_styles(html)
|
||||||
css = %w[tailwind.css application.css].filter_map { Rails.application.assets.load_path.find(_1)&.content }.join("\n")
|
css = %w[tailwind.css application.css].filter_map { Rails.application.assets.load_path.find(_1)&.content }.join("\n")
|
||||||
html.gsub(%r{<link rel="stylesheet"[^>]*>\s*}, "").sub("</head>", "<style>#{css}</style></head>")
|
# Block forms: a replacement string would treat "\\&" etc. in the CSS as back-references.
|
||||||
|
html.gsub(%r{<link rel="stylesheet"[^>]*>\s*}) { "" }.sub("</head>") { "<style>#{css}</style></head>" }
|
||||||
.gsub(%r{<script\b[^>]*>.*?</script>}m, "").gsub(%r{<link rel="modulepreload"[^>]*>\s*}, "")
|
.gsub(%r{<script\b[^>]*>.*?</script>}m, "").gsub(%r{<link rel="modulepreload"[^>]*>\s*}, "")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -37,7 +37,8 @@
|
|||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<%= f.field :tbo_critical, as: :checkbox, label: "Treat TBO as a hard limit",
|
<%= 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." %>
|
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)." %>
|
||||||
</div>
|
</div>
|
||||||
<%= f.field :inspection_hours, as: :number, label: "Inspect every (hrs)" %>
|
<%= f.field :inspection_hours, as: :number, label: "Inspect every (hrs)" %>
|
||||||
<%= f.field :inspection_days, as: :number, label: "Inspect every (days)" %>
|
<%= f.field :inspection_days, as: :number, label: "Inspect every (days)" %>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<meta name="robots" content="noindex, nofollow">
|
<meta name="robots" content="noindex, nofollow">
|
||||||
<%= csrf_meta_tags %>
|
<%= csrf_meta_tags %>
|
||||||
<%= csp_meta_tag %>
|
<%= csp_meta_tag %>
|
||||||
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
<% unless @standalone %><link rel="icon" href="/favicon.svg" type="image/svg+xml"><% end %>
|
||||||
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
|
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
|
||||||
<%= javascript_importmap_tags %>
|
<%= javascript_importmap_tags %>
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
@@ -5,11 +5,13 @@
|
|||||||
<% th = "border-b border-slate-300 py-1 pr-3 text-left text-[11px] font-semibold uppercase tracking-wide text-slate-500" %>
|
<% th = "border-b border-slate-300 py-1 pr-3 text-left text-[11px] font-semibold uppercase tracking-wide text-slate-500" %>
|
||||||
<% td = "border-b border-slate-100 py-1 pr-3 align-top" %>
|
<% td = "border-b border-slate-100 py-1 pr-3 align-top" %>
|
||||||
|
|
||||||
|
<% unless @standalone %>
|
||||||
<div class="mb-4 flex flex-wrap items-center justify-between gap-2 print:hidden">
|
<div class="mb-4 flex flex-wrap items-center justify-between gap-2 print:hidden">
|
||||||
<% back = @share ? shared_path(@share.token) : aircraft_path(a) %>
|
<% back = @share ? shared_path(@share.token) : aircraft_path(a) %>
|
||||||
<%= link_to "← Back", back, class: "link text-sm" %>
|
<%= link_to "← Back", back, class: "link text-sm" %>
|
||||||
<button type="button" class="btn-primary" data-print>Print or save as PDF</button>
|
<button type="button" class="btn-primary" data-print>Print or save as PDF</button>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<header class="flex flex-wrap items-end justify-between gap-4 border-b-2 border-slate-800 pb-3">
|
<header class="flex flex-wrap items-end justify-between gap-4 border-b-2 border-slate-800 pb-3">
|
||||||
<div>
|
<div>
|
||||||
@@ -70,8 +72,8 @@
|
|||||||
<tr><td class="<%= td %>"><%= c %> <span class="text-slate-500"><%= c.model %></span></td><td class="<%= td %>"><%= c.serial_number.presence || "—" %></td>
|
<tr><td class="<%= td %>"><%= c %> <span class="text-slate-500"><%= c.model %></span></td><td class="<%= td %>"><%= c.serial_number.presence || "—" %></td>
|
||||||
<td class="<%= td %>"><%= [ (c.tbo_hours && "#{hours(c.tbo_hours)} hrs"), (c.tbo_days && "#{c.tbo_days} days") ].compact.join(" / ") %></td>
|
<td class="<%= td %>"><%= [ (c.tbo_hours && "#{hours(c.tbo_hours)} hrs"), (c.tbo_days && "#{c.tbo_days} days") ].compact.join(" / ") %></td>
|
||||||
<td class="<%= td %> text-right tabular-nums"><%= hours(c.hours_since_overhaul) %> hrs</td>
|
<td class="<%= td %> text-right tabular-nums"><%= hours(c.hours_since_overhaul) %> hrs</td>
|
||||||
<td class="<%= td %>"><%= c.on_condition? ? "On condition" : (c.hours_to_tbo ? "#{hours(c.hours_to_tbo)} hrs" : "—") %></td>
|
<td class="<%= td %>"><%= c.hours_to_tbo ? "#{hours(c.hours_to_tbo)} hrs" : "—" %></td>
|
||||||
<td class="<%= td %> text-xs"><%= c.tbo_critical? ? "Hard limit" : "Recommended" %></td></tr>
|
<td class="<%= td %> text-xs"><%= c.on_condition? ? "On condition (Part 91)" : (c.tbo_critical? ? "Hard limit" : "Recommended") %></td></tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -111,4 +111,21 @@ class RecordsIntegrityTest < ActionDispatch::IntegrationTest
|
|||||||
ensure
|
ensure
|
||||||
ENV["APP_REVISION"] = saved
|
ENV["APP_REVISION"] = saved
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "the packaged status report has intact styles and no in-app controls" do
|
||||||
|
engine = create_component(@a, tbo_hours: 2000, hours_since_overhaul: 126, on_condition: true)
|
||||||
|
path = Rails.root.join("tmp", "pkg-#{SecureRandom.hex(4)}.zip")
|
||||||
|
RecordsPackage.new(@a, source: "test").write_to(path)
|
||||||
|
html = Zip::File.open(path) { |z| z.read("status-report.html").force_encoding("UTF-8") }
|
||||||
|
File.delete(path)
|
||||||
|
assert_includes html, "<style>"
|
||||||
|
refute_includes html, "\\[</head>" # escaped "&" in CSS selectors left intact
|
||||||
|
assert_equal 1, html.scan("</head>").size
|
||||||
|
refute_includes html, "Print or save as PDF"
|
||||||
|
refute_includes html, "← Back"
|
||||||
|
assert_includes html, "On condition (Part 91)"
|
||||||
|
assert_includes html, "1,874.0 hrs"
|
||||||
|
engine.update!(tbo_critical: true)
|
||||||
|
refute engine.reload.tbo_critical? # on condition wins
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user