mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
- more_menu helper (menu / menu-item styles): each section keeps its main action as a button; imports, exports, printing and tools move under More (flights, logbook, logbook entry, documents, inspections, fleet) - Aircraft header: More with status report and, for owners, access & sharing, edit, .sam.zip and records package; Access & Sharing and Oil Analysis tabs removed (oil analysis is under Oil & Fuel with a switch) - Logbook: Print selected appears once an entry is ticked; filters apply on change; dates use fmt_date (also AirTrail, notes, audits, About) - Header shows the role on the aircraft and hides the usual Available badge; no second Grounded badge on the Overview; AD DRS import listed once - Flights: stat cards 2x2 on phones; By year opens visibly, only with more than one year; duplicate + Log Flight removed - Remove unused hello_controller.js; guide and README updated Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
3.1 KiB
JavaScript
73 lines
3.1 KiB
JavaScript
// Configure your import map in config/importmap.rb.
|
|
import "@hotwired/turbo-rails"
|
|
import "controllers"
|
|
import "chartkick"
|
|
import "Chart.bundle"
|
|
|
|
// Chart text and grid colors follow the light/dark theme.
|
|
function styleCharts() {
|
|
if (!window.Chart) return
|
|
const dark = document.documentElement.dataset.theme === "dark"
|
|
window.Chart.defaults.color = dark ? "#a3b1c6" : "#64748b"
|
|
window.Chart.defaults.borderColor = dark ? "rgba(148, 163, 184, 0.18)" : "rgba(100, 116, 139, 0.15)"
|
|
}
|
|
function restyleCharts() {
|
|
styleCharts()
|
|
if (window.Chartkick) window.Chartkick.eachChart((chart) => chart.redraw())
|
|
}
|
|
styleCharts()
|
|
// Charts can be created before this module runs, so restyle after each page load too.
|
|
document.addEventListener("turbo:load", restyleCharts)
|
|
window.addEventListener("theme:change", restyleCharts)
|
|
|
|
// Installable app (PWA): the service worker adds an offline page and caches static assets.
|
|
if ("serviceWorker" in navigator) {
|
|
window.addEventListener("load", () => navigator.serviceWorker.register("/service-worker.js", { scope: "/" }).catch(() => {}))
|
|
}
|
|
|
|
// Label each table cell with its column header, so phone CSS can show rows as
|
|
// cards ("Status: In Service"). Skips tables marked .table-keep.
|
|
function labelTableCells(root = document) {
|
|
root.querySelectorAll("table.table:not(.table-keep)").forEach((table) => {
|
|
const headers = [ ...table.querySelectorAll("thead th") ].map((th) => th.textContent.trim().replace(/\s+/g, " "))
|
|
if (headers.length === 0) return
|
|
table.querySelectorAll("tbody tr").forEach((row) => {
|
|
let column = 0
|
|
for (const cell of row.children) {
|
|
if (!cell.hasAttribute("data-label")) cell.setAttribute("data-label", headers[column] || "")
|
|
column += cell.colSpan || 1
|
|
}
|
|
})
|
|
})
|
|
}
|
|
document.addEventListener("turbo:load", () => labelTableCells())
|
|
document.addEventListener("turbo:frame-load", (event) => labelTableCells(event.target))
|
|
|
|
// Small behaviours that used to be inline onclick handlers (blocked by the CSP).
|
|
document.addEventListener("click", (event) => {
|
|
const target = event.target
|
|
if (!(target instanceof HTMLInputElement)) return
|
|
if (target.matches("[data-select-on-click]")) target.select()
|
|
if (target.matches("[data-check-all]")) {
|
|
target.closest("table")?.querySelectorAll("tbody input[type=checkbox]").forEach((box) => { box.checked = target.checked })
|
|
}
|
|
if (target.type === "checkbox") showSelectionActions()
|
|
})
|
|
|
|
// Actions on ticked rows (e.g. "Print selected") appear once a row is ticked:
|
|
// data-needs-selection names the form the row checkboxes belong to.
|
|
function showSelectionActions() {
|
|
document.querySelectorAll("[data-needs-selection]").forEach((el) => {
|
|
el.hidden = !document.querySelector(`input[form="${el.dataset.needsSelection}"]:checked`)
|
|
})
|
|
}
|
|
document.addEventListener("turbo:load", showSelectionActions)
|
|
|
|
document.addEventListener("change", (event) => {
|
|
if (event.target.matches?.("[data-submit-on-change]")) event.target.form?.requestSubmit()
|
|
})
|
|
|
|
document.addEventListener("click", (event) => {
|
|
if (event.target.closest?.("[data-print]")) window.print()
|
|
})
|