mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
2026.11.1: offline flight logging fixed, inspections from logbook entries, life limits from installation, component inspections moved to inspection types
- Service worker keeps the Log Flight form when opened via Turbo, serves the offline page's script and icon, and treats 502/503/504 as offline; the offline page only links forms actually kept - Serviced sub-components restart from the airframe time flown since the entry - New logbook entries can complete inspections (recorded and linked to the entry) - Components: replacement limit can count from installation (life limit) - Component-level "Inspect every" / "Inspection critical" removed; a migration converts any unlinked settings into inspection types with a first record; component page lists its inspections Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7552e4a8a3
commit
352a38c7fb
28 files changed
+289
-69
No files matched your search
@@ -29,6 +29,9 @@
|
||||
<legend class="mb-2 text-sm font-semibold text-slate-900">Limits</legend>
|
||||
<%= f.field :replacement_hours, as: :number, label: "Replace every (hrs)" %>
|
||||
<%= f.interval :replacement, label: "Replace every" %>
|
||||
<%= f.field :replacement_from_install, as: :select, label: "Replacement counts from",
|
||||
collection: [ [ "Last service", false ], [ "Installation (life limit)", true ] ],
|
||||
hint: "Installation: for a part that's cleaned and reused but has a life limit (e.g. a reusable oil filter); only Replaced restarts it." %>
|
||||
<%= f.field :replacement_critical, as: :checkbox, label: "Replacement critical", hint: "Overdue replacement or expiry grounds the aircraft (oil, filters, ELT battery…)." %>
|
||||
<%= f.field :expires_on, as: :date, label: "Expires on",
|
||||
hint: "The date marked on the part, e.g. an ELT battery's replacement date (14 CFR 91.207(c): also replace it after 1 hour of cumulative use)." %>
|
||||
@@ -40,10 +43,7 @@
|
||||
<%= 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>
|
||||
<%= f.field :inspection_hours, as: :number, label: "Inspect every (hrs)" %>
|
||||
<%= f.interval :inspection, label: "Inspect every",
|
||||
hint: "Counted from the component's last service. If an inspection (Inspections tab) applies to this component, that inspection and its records govern and these are ignored." %>
|
||||
<%= f.field :inspection_critical, as: :checkbox, label: "Inspection critical" %>
|
||||
<p class="hint sm:col-span-3">Recurring inspections of this part (e.g. a 500-hour magneto inspection) are set up on the Inspections tab and applied to it.</p>
|
||||
</fieldset>
|
||||
|
||||
<%= f.field :notes, as: :textarea, rows: 3 %>
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<td class="text-right tabular-nums"><%= hours(c.hours_since_overhaul) %></td>
|
||||
<td class="text-xs text-slate-600">
|
||||
<% if c.replacement_critical? && (c.replacement_hours || c.replacement_calendar?) %>
|
||||
Replace: <%= [c.replacement_hours && "#{c.replacement_hours} h", c.replacement_interval_label].compact.join(" / ") %><br>
|
||||
Replace: <%= [c.replacement_hours && "#{c.replacement_hours} h", c.replacement_interval_label].compact.join(" / ") %><%= " since installed" if c.replacement_from_install? %><br>
|
||||
<% end %>
|
||||
<% if c.tbo_critical? && c.tbo_hours %>TBO: <%= c.tbo_hours %> h<%= " (on condition)" if c.on_condition? %><br><% end %>
|
||||
<% if c.expires_on %>Expires: <%= fmt_date(c.expires_on) %><% end %>
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
<dt class="text-slate-500">Since OH / service</dt><dd><%= hours(@component.hours_since_overhaul) %></dd>
|
||||
<dt class="text-slate-500">TBO</dt><dd><%= @component.tbo_hours ? "#{@component.tbo_hours} h (#{hours(@component.hours_to_tbo)} remaining)" : "—" %></dd>
|
||||
<dt class="text-slate-500">Replacement</dt><dd>
|
||||
<%= [@component.replacement_hours && "#{@component.replacement_hours} h", @component.replacement_interval_label].compact.join(" / ").presence || "—" %>
|
||||
<%= [@component.replacement_hours && "#{@component.replacement_hours} h", @component.replacement_interval_label].compact.join(" / ").presence&.then { @component.replacement_from_install? ? "#{_1} since installed" : _1 } || "—" %>
|
||||
<% if (d = @component.next_replacement_date) %><div class="text-xs text-slate-500">Next by <%= fmt_date(d) %></div><% end %>
|
||||
</dd>
|
||||
<dt class="text-slate-500">Flags</dt>
|
||||
<dd class="col-span-3 flex flex-wrap gap-1">
|
||||
<% { tbo_critical: "TBO critical", replacement_critical: "Replacement critical", inspection_critical: "Inspection critical", on_condition: "On condition" }.each do |flag, label| %>
|
||||
<% { tbo_critical: "TBO critical", replacement_critical: "Replacement critical", on_condition: "On condition" }.each do |flag, label| %>
|
||||
<% if @component.public_send("#{flag}?") %><span class="badge-blue"><%= label %></span><% end %>
|
||||
<% end %>
|
||||
</dd>
|
||||
@@ -53,6 +53,33 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% if @inspection_rows.any? || owner? %>
|
||||
<section class="card mt-5" id="inspections">
|
||||
<div class="card-header">
|
||||
<h2 class="card-title">Inspections of this component</h2>
|
||||
<% if owner? %><%= link_to "+ Inspection", new_aircraft_inspection_type_path(@aircraft, component_id: @component.id), class: "btn-secondary btn-sm" %><% end %>
|
||||
</div>
|
||||
<% if @inspection_rows.any? %>
|
||||
<table class="table">
|
||||
<thead><tr><th>Inspection</th><th>Interval</th><th>Last done</th><th>Next due</th><th>Status</th></tr></thead>
|
||||
<tbody>
|
||||
<% @inspection_rows.each do |row| %>
|
||||
<tr>
|
||||
<td class="font-medium"><%= row.type.name %><%= tag.span(" advisory", class: "text-xs text-slate-500") if row.type.advisory? %></td>
|
||||
<td class="text-xs"><%= row.type.interval_description %></td>
|
||||
<td class="text-xs"><%= row.latest ? "#{fmt_date(row.latest.date)} @ #{hours(row.latest.hours_at_inspection)} h" : "—" %></td>
|
||||
<td class="text-xs"><%= [row.next_due_date&.to_s, row.next_due_hours && "#{hours(row.next_due_hours)} h"].compact.join(" / ").presence || "—" %></td>
|
||||
<td><%= compliance_badge(row.status) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p class="card-body text-sm text-slate-500">None. Add one for a recurring inspection of this part (e.g. a 500-hour magneto inspection); it's tracked on the Inspections tab and can be completed from a logbook entry.</p>
|
||||
<% end %>
|
||||
</section>
|
||||
<% end %>
|
||||
|
||||
<% if @squawks.any? %>
|
||||
<section class="card mt-5">
|
||||
<div class="card-header"><h2 class="card-title">Squawks on this component</h2></div>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
||||
<%= form_with model: [@aircraft, @flight_log], class: "card card-body space-y-5 max-w-3xl",
|
||||
data: { controller: "offline-flight", offline_flight_tail_value: @aircraft.tail_number,
|
||||
action: "submit->offline-flight#submit turbo:submit-start->offline-flight#remember turbo:fetch-request-error->offline-flight#networkFailed" } do |f| %>
|
||||
action: "submit->offline-flight#submit turbo:submit-start->offline-flight#remember turbo:fetch-request-error->offline-flight#networkFailed turbo:before-fetch-response->offline-flight#gatewayFailed" } do |f| %>
|
||||
<%= f.hidden_field :client_key, data: { offline_flight_target: "key" } %>
|
||||
<div class="hidden rounded-md bg-sky-50 px-3 py-2 text-sm text-sky-900 ring-1 ring-sky-200" data-offline-flight-target="notice" role="status"></div>
|
||||
<%= f.errors_summary %>
|
||||
|
||||
@@ -33,6 +33,23 @@
|
||||
<%= f.field :text, as: :textarea, label: "Entry text", rows: 8, data: { entry_template_target: "text" } %>
|
||||
<p class="hint !mt-1">A maintenance entry needs a description of the work, the date, and the name, signature, certificate number and kind of certificate of whoever approved the return to service (14 CFR 43.9). An inspection entry also needs the type and extent of the inspection, the aircraft's time in service, and the result (43.11).</p>
|
||||
<%= render "shared/sign_as" %>
|
||||
<% if entry.new_record? && (types = aircraft.applicable_inspection_types.order(:name)).any? %>
|
||||
<%# Recurring items this work completes (e.g. an oil change): recorded on the Inspections tab, dated to this entry. %>
|
||||
<% ticked = Array(params.dig(:logbook_entry, :inspection_type_ids)).map(&:to_s) %>
|
||||
<fieldset>
|
||||
<legend class="label">Inspections completed</legend>
|
||||
<div class="grid gap-x-4 gap-y-1 sm:grid-cols-3">
|
||||
<% types.each do |t| %>
|
||||
<label class="flex items-center gap-2 text-sm">
|
||||
<%= check_box_tag "logbook_entry[inspection_type_ids][]", t.id, ticked.include?(t.id.to_s), id: "inspection_type_#{t.id}",
|
||||
class: "h-4 w-4 shrink-0 rounded border-slate-300" %>
|
||||
<span><%= t.name %></span>
|
||||
</label>
|
||||
<% end %>
|
||||
</div>
|
||||
<p class="hint">Ticked ones are recorded as done on the Inspections tab, at this entry's date and airframe time, linked to this entry.</p>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
<div class="grid gap-4 sm:grid-cols-3">
|
||||
<%= f.field :signoff_person, label: "Signed off by", placeholder: "Name", data: { signer_target: "name" } %>
|
||||
<%= f.field :signoff_certificate_type, as: :select, label: "Kind of certificate", include_blank: "—",
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
// static files (the offline page, icons, fingerprinted /assets/) and, so a
|
||||
// flight can be logged without signal, the Log Flight forms you've opened
|
||||
// (tail number and meter readings only). Other aircraft pages are never cached.
|
||||
const VERSION = "v2"
|
||||
const VERSION = "v5"
|
||||
const FORM_CACHE = "sam-flight-forms"
|
||||
const FLIGHT_FORM = /^\/aircraft\/\d+\/flight_logs\/new$/
|
||||
const SHELL_CACHE = `sam-shell-${VERSION}`
|
||||
const ASSET_CACHE = "sam-assets"
|
||||
const MAX_ASSETS = 80
|
||||
// A proxy in front of the app (Traefik, Authentik) answers these when the app
|
||||
// itself can't be reached: treat them like no connection.
|
||||
const UNREACHABLE = [ 502, 503, 504 ]
|
||||
const SHELL = [ "/offline.html", "/offline.js", "/icon.svg", "/icon-192.png" ]
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
@@ -28,11 +31,20 @@ self.addEventListener("fetch", (event) => {
|
||||
const url = new URL(request.url)
|
||||
if (url.origin !== self.location.origin) return
|
||||
|
||||
if (request.mode === "navigate" && FLIGHT_FORM.test(url.pathname)) {
|
||||
// Turbo opens pages with fetch(), not a navigation, so match those too or
|
||||
// the form is never kept when reached by tapping "Log Flight".
|
||||
const wantsHtml = request.mode === "navigate" || (request.headers.get("Accept") || "").includes("text/html")
|
||||
if (wantsHtml && FLIGHT_FORM.test(url.pathname)) {
|
||||
event.respondWith(flightForm(request))
|
||||
} else if (request.mode === "navigate") {
|
||||
// Always go to the network for pages; show the offline page if it's unreachable.
|
||||
event.respondWith(fetch(request).catch(() => caches.match("/offline.html")))
|
||||
event.respondWith(fetch(request)
|
||||
.then((response) => UNREACHABLE.includes(response.status) ? caches.match("/offline.html") : response)
|
||||
.catch(() => caches.match("/offline.html")))
|
||||
} else if (SHELL.includes(url.pathname)) {
|
||||
// The offline page's own script and icon: fresh when online, kept copy when not.
|
||||
event.respondWith(fetch(request).then((r) => r.ok ? r : caches.match(url.pathname).then((hit) => hit || r))
|
||||
.catch(() => caches.match(url.pathname)))
|
||||
} else if (url.pathname.startsWith("/assets/")) {
|
||||
event.respondWith(cachedAsset(request))
|
||||
}
|
||||
@@ -61,11 +73,22 @@ async function trim(cache) {
|
||||
// the kept copy when there isn't.
|
||||
async function flightForm(request) {
|
||||
const cache = await caches.open(FORM_CACHE)
|
||||
const key = request.url.split("?")[0]
|
||||
try {
|
||||
const response = await fetch(request)
|
||||
if (response.ok && !response.redirected) await cache.put(request.url.split("?")[0], response.clone())
|
||||
if (UNREACHABLE.includes(response.status)) {
|
||||
const kept = await cache.match(key)
|
||||
if (kept) return kept
|
||||
return request.mode === "navigate" ? caches.match("/offline.html") : response
|
||||
}
|
||||
const html = (response.headers.get("Content-Type") || "").includes("text/html")
|
||||
if (response.ok && !response.redirected && html) await cache.put(key, response.clone())
|
||||
return response
|
||||
} catch (_) {
|
||||
return (await cache.match(request.url.split("?")[0])) || caches.match("/offline.html")
|
||||
} catch (error) {
|
||||
const kept = await cache.match(key)
|
||||
if (kept) return kept
|
||||
// A Turbo fetch gets the error, so Turbo falls back to a full page load.
|
||||
if (request.mode !== "navigate") throw error
|
||||
return caches.match("/offline.html")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user