Markdown notes and a phone-friendly layout

- Notes render GitHub-flavored Markdown (commonmarker, sanitized), with a
  Write/Preview editor; overview shows a plain-text excerpt
- Phone header collapses into a menu; aircraft sections use a dropdown
- Tables stack into labelled cards under 640px (opt out with .table-keep)
- Fix horizontal overflow on overview and logbook; bigger touch targets;
  16px inputs to stop iOS zoom

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-06 21:18:23 -05:00
1 parent 1c6c2f88c0
commit 230a569b77
19 files changed
+331 -15

No files matched your search

+63
View File
@@ -107,3 +107,66 @@
--color-blue-100: color-mix(in oklab, oklch(62.3% 0.214 259.815) 22%, transparent);
--color-blue-700: oklch(80.9% 0.105 251.813);
}
/* Rendered Markdown (notes). Colors use the palette, so dark mode follows. */
@layer components {
.markdown { overflow-wrap: anywhere; }
.markdown > * + * { margin-top: 0.5em; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { font-weight: 600; color: var(--color-slate-900); line-height: 1.3; }
.markdown h1 { font-size: 1.15rem; }
.markdown h2 { font-size: 1.05rem; }
.markdown h3, .markdown h4 { font-size: 1rem; }
.markdown a { color: var(--color-sky-700); text-decoration: underline; text-underline-offset: 2px; }
.markdown ul { list-style: disc; padding-left: 1.25rem; }
.markdown ol { list-style: decimal; padding-left: 1.25rem; }
.markdown li + li { margin-top: 0.15em; }
.markdown li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.25rem; }
.markdown input[type="checkbox"] { margin-right: 0.4em; vertical-align: -1px; }
.markdown blockquote { border-left: 3px solid var(--color-slate-300); padding-left: 0.75rem; color: var(--color-slate-600); }
.markdown code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em; background: var(--color-slate-100); border-radius: 0.25rem; padding: 0.1em 0.3em; }
.markdown pre { background: var(--color-slate-100); border-radius: 0.375rem; padding: 0.6rem 0.75rem; overflow-x: auto; }
.markdown pre code { background: none; padding: 0; }
.markdown hr { border-color: var(--color-slate-200); }
.markdown table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 0.85em; }
.markdown th, .markdown td { border: 1px solid var(--color-slate-200); padding: 0.25rem 0.5rem; text-align: left; }
.markdown th { background: var(--color-slate-50); font-weight: 600; }
}
/* ---- Phones ---------------------------------------------------------- */
@layer base {
/* Grid columns may shrink below their content (a wide table scrolls inside
its card instead of widening the page). */
.grid > * { min-width: 0; }
}
/* Phones: each table row becomes a card; cells carry their column's name
(data-label, copied from the header by application.js). Tables that read
across columns (e.g. oil results by sample date) opt out with .table-keep. */
@media (max-width: 639px) {
.table:not(.table-keep) { display: block; min-width: 0; }
.table:not(.table-keep) thead { display: none; }
.table:not(.table-keep) tbody, .table:not(.table-keep) tfoot { display: block; }
.table:not(.table-keep) tr { display: block; padding: 0.625rem 1rem; border-bottom: 1px solid var(--color-slate-100); }
.table:not(.table-keep) td { display: block; padding: 0.125rem 0 !important; border: 0; text-align: left !important; white-space: normal !important; max-width: none !important; }
.table:not(.table-keep) td:empty { display: none; }
.table:not(.table-keep) td[data-label]:not([data-label=""])::before {
content: attr(data-label) " ";
margin-right: 0.35rem; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase;
color: var(--color-slate-500);
}
/* The first column names the row: show it as the card's title. */
.table:not(.table-keep) td:first-child { font-weight: 500; }
.table:not(.table-keep) td:first-child::before { content: none !important; }
/* Buttons-only cells (Edit / Resolve…) sit at the end of the card. */
.table:not(.table-keep) td[data-label=""]:not(:first-child) { padding-top: 0.375rem !important; }
.overflow-x-auto:has(> .table:not(.table-keep)) { overflow-x: visible; }
/* 16px text stops iOS zooming into fields on focus. */
.input, select.input, textarea.input { font-size: 16px; }
}
/* Touch screens: small buttons and tabs get a finger-sized target. */
@media (pointer: coarse) {
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8125rem; }
.btn-primary, .btn-secondary, .btn-danger { min-height: 2.5rem; }
}
+5
View File
@@ -7,6 +7,11 @@ class NotesController < ApplicationController
@notes = @aircraft.notes.recent_first.includes(:user)
end
# Rendered Markdown for the editor's Preview tab.
def preview
render html: helpers.markdown(params[:text].to_s.first(50_000)).presence || helpers.tag.p("Nothing to preview.", class: "hint")
end
def new
@note = @aircraft.notes.new
end
+29
View File
@@ -0,0 +1,29 @@
# GitHub-flavored Markdown for notes. Raw HTML in the source is dropped and the
# output is sanitized again, so notes (some shown on public share links) can't
# inject markup. Single line breaks are kept, so plain-text notes written
# before Markdown support look the same as before.
module MarkdownHelper
OPTIONS = {
parse: { smart: true },
render: { hardbreaks: true, unsafe: false, escape: false },
extension: { strikethrough: true, tagfilter: true, table: true, autolink: true, tasklist: true, header_ids: nil, footnotes: false }
}.freeze
TAGS = %w[p br strong em del a ul ol li blockquote code pre h1 h2 h3 h4 h5 h6 hr table thead tbody tr th td input span].freeze
ATTRIBUTES = %w[href title type checked disabled align class].freeze
def markdown(text)
return "".html_safe if text.blank?
html = Commonmarker.to_html(text.to_s, options: OPTIONS, plugins: { syntax_highlighter: nil })
html = sanitize(html, tags: TAGS, attributes: ATTRIBUTES)
# Links open in a new tab (notes often link to manuals and vendors).
html = html.gsub(/<a href=/, '<a target="_blank" rel="noopener nofollow" href=')
tag.div(html.html_safe, class: "markdown") # rubocop:disable Rails/OutputSafety -- sanitized above
end
# Plain-text excerpt for previews ("**Oil** leak at…" → "Oil leak at…").
def markdown_excerpt(text, length: 200)
return "" if text.blank?
html = Commonmarker.to_html(text.to_s, options: OPTIONS.merge(render: { hardbreaks: false, unsafe: false }), plugins: { syntax_highlighter: nil })
CGI.unescapeHTML(strip_tags(html.gsub(%r{</(p|li|h\d|tr|blockquote)>}, " "))).squish.truncate(length)
end
end
+18
View File
@@ -24,3 +24,21 @@ window.addEventListener("theme:change", restyleCharts)
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))
@@ -0,0 +1,47 @@
import { Controller } from "@hotwired/stimulus"
// Write / Preview tabs for a Markdown textarea. The preview is rendered by the
// server, with the same Markdown rules and sanitizing as the saved note.
export default class extends Controller {
static targets = [ "input", "output", "writeTab", "previewTab" ]
static values = { url: String }
connect() {
this.select(false)
}
write() {
this.select(false)
this.inputTarget.focus()
}
async preview() {
this.select(true)
this.outputTarget.textContent = "Loading preview…"
const token = document.querySelector("meta[name=csrf-token]")?.content
try {
const response = await fetch(this.urlValue, {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded", "X-CSRF-Token": token, Accept: "text/html" },
body: new URLSearchParams({ text: this.inputTarget.value }),
credentials: "same-origin"
})
if (!response.ok) throw new Error(`HTTP ${response.status}`)
this.outputTarget.innerHTML = await response.text() // sanitized server-side
} catch (error) {
this.outputTarget.textContent = `Couldn't load the preview (${error.message}).`
}
}
select(previewing) {
this.inputTarget.hidden = previewing
this.outputTarget.hidden = !previewing
const tabs = [ [ this.writeTabTarget, !previewing ], [ this.previewTabTarget, previewing ] ]
tabs.forEach(([ tab, active ]) => {
tab.setAttribute("aria-selected", active)
tab.classList.toggle("bg-slate-200", active)
tab.classList.toggle("text-slate-900", active)
tab.classList.toggle("text-slate-500", !active)
})
}
}
+1 -1
View File
@@ -90,7 +90,7 @@
<ul class="divide-y divide-slate-100">
<% @notes.each do |note| %>
<li class="px-4 py-2 text-sm">
<div><%= note.text.truncate(200) %></div>
<div><%= markdown_excerpt note.text %></div>
<div class="text-xs text-slate-500"><%= note.user&.display_name %> · <%= time_ago_in_words(note.created_at) %> ago <%= "· public" if note.public? %></div>
</li>
<% end %>
+22 -3
View File
@@ -22,11 +22,30 @@
<body class="min-h-full text-slate-800">
<header class="bg-header text-white">
<div class="mx-auto flex max-w-7xl items-center justify-between gap-4 px-4 py-3">
<%= link_to root_path, class: "flex items-center gap-2 font-semibold tracking-tight" do %>
<span class="text-xl">✈</span> Simple Aircraft Manager
<%= link_to root_path, class: "flex items-center gap-2 font-semibold tracking-tight whitespace-nowrap" do %>
<span class="text-xl">✈</span> <span class="hidden sm:inline">Simple Aircraft Manager</span><span class="sm:hidden" aria-label="Simple Aircraft Manager">SAM</span>
<% end %>
<% if current_user %>
<nav class="flex items-center gap-4 text-sm">
<%# Phones: Fleet, theme and one menu for the rest. %>
<nav class="flex items-center gap-1 text-sm sm:hidden" aria-label="Main">
<%= link_to "Fleet", root_path, class: "rounded px-3 py-2 hover:bg-white/10" %>
<%= render "shared/theme_toggle" %>
<details class="relative" data-controller="dropdown" data-action="click@window->dropdown#closeOutside keydown.esc@window->dropdown#close">
<summary class="flex cursor-pointer list-none items-center rounded px-3 py-2 text-lg leading-none hover:bg-white/10 [&::-webkit-details-marker]:hidden" aria-label="Menu">☰</summary>
<div class="absolute right-0 z-30 mt-2 w-56 rounded-md bg-surface py-1 text-slate-700 shadow-lg ring-1 ring-slate-200">
<p class="truncate px-4 pt-2 pb-1 text-xs text-slate-500"><%= current_user.email_address %></p>
<%= link_to "Profile", edit_profile_path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
<% if current_user.admin? %>
<p class="border-t border-slate-100 px-4 pt-2 pb-1 text-xs font-semibold text-slate-500">Admin</p>
<% [ [ "Users", admin_users_path ], [ "Component Types", admin_component_types_path ], [ "Airports", admin_airports_path ] ].each do |label, path| %>
<%= link_to label, path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
<% end %>
<% end %>
<div class="border-t border-slate-100"><%= button_to "Sign out", session_path, method: :delete, class: "block w-full px-4 py-2.5 text-left hover:bg-slate-100" %></div>
</div>
</details>
</nav>
<nav class="hidden items-center gap-4 text-sm sm:flex" aria-label="Main">
<%= link_to "Fleet", root_path, class: "hover:text-sky-300" %>
<% if current_user.admin? %>
<details class="relative" data-controller="dropdown" data-action="click@window->dropdown#closeOutside keydown.esc@window->dropdown#close">
+2 -2
View File
@@ -4,8 +4,8 @@
<div class="card-header">
<h2 class="card-title">Maintenance Logbook</h2>
<div class="flex flex-wrap items-center gap-2">
<%= form_with url: aircraft_logbook_entries_path(@aircraft), method: :get, class: "flex gap-2" do |f| %>
<%= f.search_field :q, value: @query, placeholder: "Search entries…", class: "input w-48" %>
<%= form_with url: aircraft_logbook_entries_path(@aircraft), method: :get, class: "flex w-full flex-wrap gap-2 sm:w-auto" do |f| %>
<%= f.search_field :q, value: @query, placeholder: "Search entries…", class: "input min-w-0 flex-1 sm:w-48 sm:flex-none" %>
<%= f.select :log_type, LogbookEntry::LOG_TYPES.invert, { include_blank: "All logs", selected: @log_type }, class: "input w-32" %>
<%= f.submit "Filter", class: "btn-secondary" %>
<% end %>
+14 -1
View File
@@ -1,6 +1,19 @@
<%= form_with model: note, url: note.new_record? ? aircraft_notes_path(aircraft) : aircraft_note_path(aircraft, note), class: "card card-body space-y-4 max-w-2xl" do |f| %>
<%= f.errors_summary %>
<%= f.field :text, as: :textarea, label: "Note", rows: 5, autofocus: true %>
<div data-controller="markdown-editor" data-markdown-editor-url-value="<%= preview_aircraft_notes_path(aircraft) %>">
<div class="mb-1 flex items-end justify-between gap-2">
<%= f.label :text, "Note", class: "block text-sm font-medium text-slate-700" %>
<div class="flex gap-1 text-xs" role="tablist">
<button type="button" role="tab" data-markdown-editor-target="writeTab" data-action="markdown-editor#write" class="rounded px-2 py-1 font-medium">Write</button>
<button type="button" role="tab" data-markdown-editor-target="previewTab" data-action="markdown-editor#preview" class="rounded px-2 py-1 font-medium">Preview</button>
</div>
</div>
<%= f.text_area :text, rows: 8, autofocus: true, class: "input font-mono text-sm", data: { markdown_editor_target: "input" },
placeholder: "**Bold**, *italic*, - lists, - [ ] checklists, [links](https://…), | tables |" %>
<div data-markdown-editor-target="output" hidden class="min-h-[10rem] rounded-md p-3 text-sm ring-1 ring-slate-300"></div>
<% if note.errors[:text].any? %><p class="mt-1 text-sm text-red-600"><%= note.errors.full_messages_for(:text).to_sentence %></p><% end %>
<p class="hint mt-1">Markdown works: **bold**, *italic*, # headings, lists, - [ ] checklists, links, `code` and tables.</p>
</div>
<%= f.field :public, as: :checkbox, label: "Show on share links" %>
<div class="flex gap-2"><%= f.submit "Save Note" %><%= link_to "Cancel", aircraft_notes_path(aircraft), class: "btn-secondary" %></div>
<% end %>
+2 -2
View File
@@ -6,8 +6,8 @@
<ul class="divide-y divide-slate-100">
<% @notes.each do |note| %>
<li class="flex items-start justify-between gap-4 px-4 py-3">
<div>
<div class="text-sm"><%= simple_format note.text %></div>
<div class="min-w-0 flex-1">
<div class="text-sm"><%= markdown note.text %></div>
<div class="mt-1 text-xs text-slate-500">
<%= note.user&.display_name || "Unknown" %> · <%= l note.created_at, format: :short %>
<%= "· edited" if note.edited_at %>
+1 -1
View File
@@ -33,7 +33,7 @@
<div class="card-header"><h2 class="card-title">Results (ppm)</h2>
<span class="text-xs text-slate-500">Lab average for similar engines in (parentheses); <span class="font-semibold text-red-700">red</span> is <%= OilAnalysis::FLAG_RATIO %>× or more above it.</span></div>
<div class="overflow-x-auto">
<table class="table">
<table class="table table-keep">
<thead>
<tr><th>Element</th>
<% recent.each do |a| %><th class="text-right whitespace-nowrap"><%= link_to fmt_date(a.sample_date), aircraft_oil_analysis_path(@aircraft, a), class: "link" %></th><% end %></tr>
+18 -3
View File
@@ -18,13 +18,28 @@
</div>
</div>
</div>
<div class="flex gap-2">
<div class="flex w-full gap-2 sm:w-auto [&>*]:flex-1 [&>*]:justify-center sm:[&>*]:flex-none">
<%= link_to "Log Flight", new_aircraft_flight_log_path(aircraft), class: "btn-primary" %>
<%= link_to "Report Squawk", new_aircraft_squawk_path(aircraft), class: "btn-secondary" %>
</div>
</div>
<nav class="mb-5 flex overflow-x-auto border-b border-slate-200">
<% aircraft_tabs(aircraft).each do |label, path, names| %>
<% tabs = aircraft_tabs(aircraft) %>
<% current_tab = tabs.find { |_, _, names| names.include?(controller_name) } %>
<%# Phones: the current section, with every section a tap away. %>
<details class="relative mb-5 md:hidden" data-controller="dropdown" data-action="click@window->dropdown#closeOutside keydown.esc@window->dropdown#close">
<summary class="flex cursor-pointer list-none items-center justify-between rounded-md bg-surface px-4 py-3 font-medium shadow-sm ring-1 ring-slate-200 [&::-webkit-details-marker]:hidden">
<span><span class="text-xs font-normal text-slate-500">Section</span><br><%= current_tab&.first || "Overview" %></span>
<span aria-hidden="true" class="text-slate-500">▾</span>
</summary>
<nav class="absolute inset-x-0 z-30 mt-2 grid grid-cols-2 gap-1 rounded-md bg-surface p-2 shadow-lg ring-1 ring-slate-200" aria-label="Aircraft sections">
<% tabs.each do |label, path, names| %>
<%= link_to label, path, class: [ "rounded px-3 py-2.5 text-sm hover:bg-slate-100", (names.include?(controller_name) ? "bg-slate-100 font-semibold text-sky-700" : "text-slate-700") ],
aria: { current: (names.include?(controller_name) ? "page" : nil) } %>
<% end %>
</nav>
</details>
<nav class="mb-5 hidden flex-wrap border-b border-slate-200 md:flex" aria-label="Aircraft sections">
<% tabs.each do |label, path, names| %>
<%= nav_tab label, path, names.include?(controller_name) %>
<% end %>
</nav>
+1 -1
View File
@@ -65,7 +65,7 @@
<% if @notes.any? %>
<section class="card"><div class="card-header"><h2 class="card-title">Notes</h2></div>
<ul class="divide-y divide-slate-100"><% @notes.each do |n| %><li class="px-4 py-2 text-sm"><%= simple_format n.text %><div class="text-xs text-slate-500"><%= n.created_at.to_date %></div></li><% end %></ul></section>
<ul class="divide-y divide-slate-100"><% @notes.each do |n| %><li class="px-4 py-2 text-sm"><%= markdown n.text %><div class="text-xs text-slate-500"><%= n.created_at.to_date %></div></li><% end %></ul></section>
<% end %>
<% if @documents.any? %>