Squawk photos as thumbnails

- Photos show as 64px thumbnails (160px resized copies, made once with
  libvips and kept; lazy-loaded) that open the in-app viewer, which has
  Download; other files keep their name chip and download link
- image_processing gem and the vips variant processor (libvips was already
  in the image)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-14 07:16:46 -05:00
1 parent 9d3643df33
commit 79a64cc208
6 files changed
+61 -20

No files matched your search

+1 -1
View File
@@ -37,7 +37,7 @@ gem "kamal", require: false
gem "thruster", require: false
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"
gem "image_processing", "~> 1.2"
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
+28
View File
@@ -141,6 +141,14 @@ GEM
faraday (>= 1, < 3)
faraday-net_http (3.5.0)
net-http (~> 0.5)
ffi (1.17.4-aarch64-linux-gnu)
ffi (1.17.4-aarch64-linux-musl)
ffi (1.17.4-arm-linux-gnu)
ffi (1.17.4-arm-linux-musl)
ffi (1.17.4-arm64-darwin)
ffi (1.17.4-x86_64-darwin)
ffi (1.17.4-x86_64-linux-gnu)
ffi (1.17.4-x86_64-linux-musl)
fugit (1.14.0)
et-orbi (~> 1.4)
raabro (~> 1.4)
@@ -153,6 +161,9 @@ GEM
htmlentities (4.4.2)
i18n (1.15.2)
concurrent-ruby (~> 1.0)
image_processing (1.14.0)
mini_magick (>= 4.9.5, < 6)
ruby-vips (>= 2.0.17, < 3)
importmap-rails (2.2.3)
actionpack (>= 6.0.0)
activesupport (>= 6.0.0)
@@ -198,6 +209,8 @@ GEM
net-smtp
marcel (1.2.1)
matrix (0.4.3)
mini_magick (5.4.0)
logger
mini_mime (1.1.5)
minitest (6.1.0)
drb (~> 2.0)
@@ -396,6 +409,9 @@ GEM
rubocop-performance (>= 1.24)
rubocop-rails (>= 2.30)
ruby-progressbar (1.13.0)
ruby-vips (2.3.0)
ffi (~> 1.12)
logger
rubyzip (3.7.0)
securerandom (0.4.1)
solid_cache (1.0.10)
@@ -507,6 +523,7 @@ DEPENDENCIES
commonmarker (~> 2.10)
csv (~> 3.3)
debug
image_processing (~> 1.2)
importmap-rails
json (~> 3.1)
kamal
@@ -593,6 +610,14 @@ CHECKSUMS
faraday (2.15.1) sha256=8708154deda739c5e86cc42b74960e23e8491fce0eba9e11639a6a34b1ac288f
faraday-follow_redirects (0.5.0) sha256=5cde93c894b30943a5d2b93c2fe9284216a6b756f7af406a1e55f211d97d10ad
faraday-net_http (3.5.0) sha256=2e7094c34e38754ee048cc3df47376f8657005d9375f8473bce1c3b526a22e36
ffi (1.17.4-aarch64-linux-gnu) sha256=b208f06f91ffd8f5e1193da3cae3d2ccfc27fc36fba577baf698d26d91c080df
ffi (1.17.4-aarch64-linux-musl) sha256=9286b7a615f2676245283aef0a0a3b475ae3aae2bb5448baace630bb77b91f39
ffi (1.17.4-arm-linux-gnu) sha256=d6dbddf7cb77bf955411af5f187a65b8cd378cb003c15c05697f5feee1cb1564
ffi (1.17.4-arm-linux-musl) sha256=9d4838ded0465bef6e2426935f6bcc93134b6616785a84ffd2a3d82bc3cf6f95
ffi (1.17.4-arm64-darwin) sha256=19071aaf1419251b0a46852abf960e77330a3b334d13a4ab51d58b31a937001b
ffi (1.17.4-x86_64-darwin) sha256=aa70390523cf3235096cf64962b709b4cfbd5c082a2cb2ae714eb0fe2ccda496
ffi (1.17.4-x86_64-linux-gnu) sha256=9d3db14c2eae074b382fa9c083fe95aec6e0a1451da249eab096c34002bc752d
ffi (1.17.4-x86_64-linux-musl) sha256=3fdf9888483de005f8ef8d1cf2d3b20d86626af206cbf780f6a6a12439a9c49e
fugit (1.14.0) sha256=e311a9cc85a54bb67649df45060e721282a1e2c8ebad40e41874a3a7d576f37e
globalid (1.4.0) sha256=037f12fbf1d9d7a014d501c2d5c77356fd4ddd96d7a7991d6700bba96706f427
hashdiff (1.2.1) sha256=9c079dbc513dfc8833ab59c0c2d8f230fa28499cc5efb4b8dd276cf931457cd1
@@ -600,6 +625,7 @@ CHECKSUMS
hashie (5.2.0) sha256=357a22635195c2e3911fbbc3de9a7d528843d1f42ab0aae02171048f16332d72
htmlentities (4.4.2) sha256=bbafbdf69f2eca9262be4efef7e43e6a1de54c95eb600f26984f71d2fe96c5c3
i18n (1.15.2) sha256=00f9eb62412fe593b2a65a97daa75300d37abb8f7202ec748e94b6d46a9dd1b5
image_processing (1.14.0) sha256=754cc169c9c262980889bec6bfd325ed1dafad34f85242b5a07b60af004742fb
importmap-rails (2.2.3) sha256=7101be2a4dc97cf1558fb8f573a718404c5f6bcfe94f304bf1f39e444feeb16a
io-console (0.9.5) sha256=83dd9bbf4c4680416629245b39cd4212eb5f4d9a4ea91804870c1f6b846414d5
irb (1.18.0) sha256=de9454a0703a54704b9811a5ef31a60c86949fbf4013fcf244fabc7c775248e3
@@ -614,6 +640,7 @@ CHECKSUMS
mail (2.9.1) sha256=06574eca475253d6c18145dd70af80d0eb970182d55053497c5f4d797ea160e8
marcel (1.2.1) sha256=1678e9360e32f9eafa917c80029e2f6d10b2715c66a4b87b6d0da9b9cd1f859f
matrix (0.4.3) sha256=a0d5ab7ddcc1973ff690ab361b67f359acbb16958d1dc072b8b956a286564c5b
mini_magick (5.4.0) sha256=f120af581d9ed4ec52c57f35a67a605d112bb1d8f582d1415b147fda42d11d78
mini_mime (1.1.5) sha256=8681b7e2e4215f2a159f9400b5816d85e9d8c6c6b491e96a12797e798f8bccef
minitest (6.1.0) sha256=ff373595aa8888631e8a5463986a76b3845346ae6d7fa46e139c1633d418076e
msgpack (1.8.7) sha256=dfefec761b5f9047e6e8d95d2c7f8af4b3725d984a01942adc533aa819a2df33
@@ -681,6 +708,7 @@ CHECKSUMS
rubocop-rails (2.38.0) sha256=6e2b7c532efa95e3050371bec20b8f5b025662acead8bc70ee31f0e3e6fa2f06
rubocop-rails-omakase (1.1.0) sha256=2af73ac8ee5852de2919abbd2618af9c15c19b512c4cfc1f9a5d3b6ef009109d
ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
ruby-vips (2.3.0) sha256=e685ec02c13969912debbd98019e50492e12989282da5f37d05f5471442f5374
rubyzip (3.7.0) sha256=65c19294da75297a939006f3516deacc33185fbd721ff1954f7a231db6d3e121
securerandom (0.4.1) sha256=cc5193d414a4341b6e225f0cb4446aceca8e50d5e1888743fac16987638ea0b1
solid_cache (1.0.10) sha256=bc05a2fb3ac78a6f43cbb5946679cf9db67dd30d22939ededc385cb93e120d41
+1 -1
View File
@@ -10,7 +10,7 @@ The port aims to be **easy to host**. It runs as one process with one SQLite dat
- Ruby 4.0, Rails 8.1, SQLite. Solid Queue and Solid Cache both use SQLite, so there are no extra services. Background jobs (nightly backup and records check, weekly reminders and AD search) run in the web process.
- Hotwire (Turbo and Stimulus) with importmap, so there is no Node build step. Tailwind CSS 4 runs through `tailwindcss-rails`.
- Active Storage on local disk handles pictures, document pages, squawk attachments, and track logs. Identical files are stored once (hard links).
- Active Storage on local disk handles pictures, document pages, squawk attachments, and track logs; libvips makes the photo thumbnails. Identical files are stored once (hard links).
- Chartkick and Chart.js draw the oil and fuel charts.
- Authentication uses the Rails 8 built-in generator (sessions plus password reset), emailed sign-in links, and optional OpenID Connect single sign-on (OmniAuth).
- Prawn renders the printable logbook entries; Commonmarker renders Markdown notes and the user guide.
+8 -9
View File
@@ -1,21 +1,20 @@
<%# A squawk's files: photos open in the in-app viewer, everything else opens in
a new tab. Every file has a download link. %>
<%# A squawk's files: photos show as thumbnails that open the in-app viewer
(which has Download); other files open in a new tab and have a download link. %>
<% files = squawk.attachments.to_a %>
<% if files.any? %>
<% photos, others = files.partition(&:image?) %>
<% photos, others = files.partition { _1.image? && _1.variable? } %>
<div class="mt-1" data-controller="gallery">
<ul class="flex flex-wrap gap-1.5">
<% photos.each do |file| %>
<li class="inline-flex items-center overflow-hidden rounded-md text-xs ring-1 ring-slate-300">
<%= link_to rails_blob_path(file, disposition: :inline), class: "px-2 py-1 text-sky-700 hover:bg-slate-100",
<li>
<%= link_to rails_blob_path(file, disposition: :inline),
class: "block overflow-hidden rounded-md ring-1 ring-slate-300 hover:ring-2 hover:ring-sky-500 focus-visible:ring-2 focus-visible:ring-sky-500",
title: t(".preview", filename: file.filename),
data: { gallery_target: "item", action: "gallery#open", gallery_name: file.filename.to_s,
gallery_download: rails_blob_path(file, disposition: :attachment) } do %>
🖼 <%= file.filename.to_s.truncate(28, omission: "…") %>
<%= image_tag file.variant(resize_to_fill: [ 160, 160 ]), alt: file.filename.to_s, loading: "lazy", width: 64, height: 64,
class: "block h-16 w-16 bg-slate-100 object-cover" %>
<% end %>
<%= link_to "⬇", rails_blob_path(file, disposition: :attachment), download: file.filename.to_s,
class: "border-l border-slate-300 px-1.5 py-1 text-slate-500 hover:bg-slate-100 hover:text-sky-700",
title: t(".download", filename: file.filename), aria: { label: t(".download", filename: file.filename) } %>
</li>
<% end %>
<% others.each do |file| %>
+2 -2
View File
@@ -39,7 +39,7 @@ module SimpleAircraftManager
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
# Uploads are served as-is (no image variants), so libvips/image_processing is not needed.
config.active_storage.variant_processor = :disabled
# Small resized copies of photos (squawk thumbnails), made with libvips.
config.active_storage.variant_processor = :vips
end
end
+21 -7
View File
@@ -20,26 +20,40 @@ class SquawkAttachmentsTest < ActionDispatch::IntegrationTest
get aircraft_squawks_path(@a)
assert_select "[data-controller=gallery]" do
assert_select "a[data-gallery-target=item][data-action='gallery#open'][href*='front.jpg']", text: /🖼/
assert_select "a[data-gallery-target=item][data-action='gallery#open'][href*='front.jpg'] img[alt='front.jpg'][loading=lazy][src*='/representations/']"
assert_select "a[data-gallery-target=item]", 1 # only photos open in the viewer
assert_select "a[target=_blank][href*='notes.txt']", text: /📎/
assert_select "dialog[data-gallery-target=dialog] a[data-gallery-target=download]"
end
end
test "every file has a download link that forces a download" do
@a.squawks.create!(priority: 1, issue_reported: "x", attachments: [ upload("pic.png", "image/png"), upload("log.pdf", "application/pdf") ])
test "every file can be downloaded: other files from their link, photos from the viewer" do
@a.squawks.create!(priority: 1, issue_reported: "x", attachments: [ upload("pic.png", "image/png", png), upload("log.pdf", "application/pdf") ])
sign_in @pilot
get aircraft_squawks_path(@a)
downloads = css_select("a[download]").reject { _1["data-gallery-target"] }
assert_equal %w[log.pdf pic.png], downloads.map { _1["download"] }.sort
downloads.each do |link|
get link["href"]
downloads = css_select("a[download]").reject { _1["data-gallery-target"] }.map { _1["href"] }
downloads << css_select("a[data-gallery-target=item]").sole["data-gallery-download"]
assert_equal 2, downloads.size
downloads.each do |href|
get href
follow_redirect! while response.redirect?
assert_match(/\Aattachment;/, response.headers["Content-Disposition"])
end
end
test "photo thumbnails are small resized copies" do
@a.squawks.create!(priority: 1, issue_reported: "x", attachments: [ upload("pic.png", "image/png", png) ])
sign_in @pilot
get aircraft_squawks_path(@a)
get css_select("a[data-gallery-target=item] img").sole["src"]
follow_redirect! while response.redirect?
assert_response :success
assert_equal [ 160, 160 ], Vips::Image.new_from_buffer(response.body, "").then { [ _1.width, _1.height ] }
end
# A 200 × 120 PNG (made when first needed: libvips must not start before the test processes fork).
def png = @png ||= Vips::Image.black(200, 120).write_to_buffer(".png")
test "squawks with no photos get no viewer" do
@a.squawks.create!(priority: 1, issue_reported: "x", attachments: [ upload("notes.txt") ])
sign_in @pilot