From 8957808536e53bb9329cb6ae12835fde7835210b Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sat, 27 Jun 2026 21:43:55 +0200 Subject: Stage 7 click-testing fixes (2) - nodes_controller: permit staged_slug and staged_parent_id in node params; these were silently dropped since strong parameters migration, breaking the two-phase slug/parent change workflow - file_attachment: add SVG support; vector files are copied to all style directories without rasterisation, preserving scalability in the browser - assets index/show: constrain image display with max-width/max-height via admin.css td img rule; fixes oversized SVG thumbnails while leaving raster variants unaffected --- app/controllers/nodes_controller.rb | 2 +- app/models/concerns/file_attachment.rb | 14 +++++++++++++- app/views/assets/index.html.erb | 2 +- app/views/assets/show.html.erb | 4 ++-- 4 files changed, 17 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index bd60b27..494887d 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb @@ -107,7 +107,7 @@ class NodesController < ApplicationController private def node_params - params.fetch(:node, {}).permit(:slug, :parent_id) + params.fetch(:node, {}).permit(:slug, :parent_id, :staged_slug, :staged_parent_id) end def page_params diff --git a/app/models/concerns/file_attachment.rb b/app/models/concerns/file_attachment.rb index e9acda6..0e99fa2 100644 --- a/app/models/concerns/file_attachment.rb +++ b/app/models/concerns/file_attachment.rb @@ -28,7 +28,9 @@ module FileAttachment headline: { geometry: "460x250!", format: nil } }.freeze - IMAGE_CONTENT_TYPES = %w[image/jpeg image/gif image/png image/webp].freeze + IMAGE_CONTENT_TYPES = %w[image/jpeg image/gif image/png image/webp].freeze + VECTOR_CONTENT_TYPES = %w[image/svg+xml].freeze + DISPLAYABLE_AS_IMAGE = IMAGE_CONTENT_TYPES + VECTOR_CONTENT_TYPES included do attr_reader :upload @@ -69,6 +71,8 @@ module FileAttachment if IMAGE_CONTENT_TYPES.include?(upload_content_type) generate_variants(original_path) + elsif VECTOR_CONTENT_TYPES.include?(upload_content_type) + generate_svg_variants(original_path) end end @@ -80,6 +84,14 @@ module FileAttachment end end + def generate_svg_variants(original_path) + STYLES.each do |style, _| + dest_path = file_path(style) + FileUtils.mkdir_p(File.dirname(dest_path)) + FileUtils.cp(original_path, dest_path) + end + end + def delete_upload_files dir = Rails.root.join("public", "system", "uploads", id.to_s) FileUtils.rm_rf(dir) if Dir.exist?(dir) diff --git a/app/views/assets/index.html.erb b/app/views/assets/index.html.erb index 83d55c2..51fc486 100644 --- a/app/views/assets/index.html.erb +++ b/app/views/assets/index.html.erb @@ -10,7 +10,7 @@ <% @assets.each do |asset| %> - <%= image_tag asset.upload.url(:thumb) %> + <%= image_tag asset.upload.url(:thumb), style: "max-width: 100px; max-height: 100px;" %> <%= link_to asset.name, asset.upload.url %> <%= asset.upload.content_type %> <%= link_to 'Show', asset %> diff --git a/app/views/assets/show.html.erb b/app/views/assets/show.html.erb index a64987c..694be5a 100644 --- a/app/views/assets/show.html.erb +++ b/app/views/assets/show.html.erb @@ -6,7 +6,7 @@ - + @@ -20,4 +20,4 @@ -
Thumbnail<%= image_tag @asset.upload.url(:medium) %><%= image_tag @asset.upload.url(:medium), style: "max-width: 300px; max-height: 300px;" %>
Public PathSize <%= "#{@asset.upload.size/1024} KB" %>
\ No newline at end of file + -- cgit v1.3