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:
rickyandClaude Opus 5.5 committed 2026-11-12 07:30:59 -05:00
1 parent 7552e4a8a3
commit 352a38c7fb
28 files changed
+289 -69

No files matched your search

+29 -6
View File
@@ -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")
}
}