From 11e58d96ea70af7601df35109b625b94b0ce40f1 Mon Sep 17 00:00:00 2001 From: Quinn Daley Date: Thu, 16 May 2024 10:08:54 +0100 Subject: [PATCH] Fix behaviour for index_display_preview to match documentation --- Gemfile.lock | 22 ++++++++------ .../fields/active_storage/_index.html.erb | 29 +++++-------------- .../fields/active_storage/_item.html.erb | 5 ++-- .../fields/active_storage/_items.html.erb | 2 ++ test_app/Gemfile.lock | 6 ++-- test_app/db/schema.rb | 4 +-- 6 files changed, 32 insertions(+), 36 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b70a40b..45ec493 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - administrate-field-active_storage (1.0.1) + administrate-field-active_storage (1.0.2) administrate (>= 0.2.2) rails (>= 7.0) @@ -121,23 +121,25 @@ GEM net-imap net-pop net-smtp - marcel (1.0.2) + marcel (1.0.4) method_source (1.0.0) mini_mime (1.1.5) - mini_portile2 (2.8.5) minitest (5.15.0) - net-imap (0.4.10) + net-imap (0.4.11) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout - net-smtp (0.4.0.1) + net-smtp (0.5.0) net-protocol - nio4r (2.7.0) - nokogiri (1.13.3) - mini_portile2 (~> 2.8.0) + nio4r (2.7.3) + nokogiri (1.13.3-arm64-darwin) + racc (~> 1.4) + nokogiri (1.13.3-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.13.3-x86_64-linux) racc (~> 1.4) parser (3.0.3.2) ast (~> 2.4.1) @@ -192,7 +194,9 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.4.2) + sqlite3 (1.7.3-arm64-darwin) + sqlite3 (1.7.3-x86_64-darwin) + sqlite3 (1.7.3-x86_64-linux) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) thor (1.1.0) diff --git a/app/views/fields/active_storage/_index.html.erb b/app/views/fields/active_storage/_index.html.erb index 304ad9b..f05eab9 100644 --- a/app/views/fields/active_storage/_index.html.erb +++ b/app/views/fields/active_storage/_index.html.erb @@ -16,27 +16,14 @@ By default, the attribute is rendered as an image tag. %> <% if field.attached? %> - <% if field.index_display_preview? %> - <% if field.many? %> - <%= render partial: 'fields/active_storage/items', - locals: { - field: field, - variant: field.index_preview_variant, - size: field.index_preview_size, - preview_only: field.index_preview_only? - } %> - <% else %> - <%= render partial: 'fields/active_storage/item', - locals: { - field: field, - attachment: field.data, - variant: field.index_preview_variant, - size: field.index_preview_size, - preview_only: field.index_preview_only? - } %> - <% end %> - <% end %> - + <%= render partial: "fields/active_storage/items", + locals: { + field: field, + variant: field.index_preview_variant, + size: field.index_preview_size, + display_preview: field.index_display_preview?, + preview_only: field.index_preview_only? + } %> <% if field.index_display_count? %>
<%= pluralize(field.attachments.count, diff --git a/app/views/fields/active_storage/_item.html.erb b/app/views/fields/active_storage/_item.html.erb index 5019fc6..d913fdc 100644 --- a/app/views/fields/active_storage/_item.html.erb +++ b/app/views/fields/active_storage/_item.html.erb @@ -22,8 +22,9 @@ controlled via a boolean local variable. - `preview_only`: If true, show only the previous and not the name or destroy link %> -<% preview_only = local_assigns.fetch(:preview_only, false) %> -<% if field.show_display_preview? && attachment.persisted? %> +<% preview_only = local_assigns.fetch(:preview_only, false) + display_preview = local_assigns.fetch(:display_preview, field.show_display_preview?) %> +<% if display_preview && attachment.persisted? %>
<%= render partial: 'fields/active_storage/preview', locals: local_assigns %>
diff --git a/app/views/fields/active_storage/_items.html.erb b/app/views/fields/active_storage/_items.html.erb index 47088b6..638200b 100644 --- a/app/views/fields/active_storage/_items.html.erb +++ b/app/views/fields/active_storage/_items.html.erb @@ -17,6 +17,7 @@ This partial renders one or more attachments <% variant = local_assigns.fetch(:variant, field.show_preview_variant) size = local_assigns.fetch(:size, field.show_preview_size) + display_preview = local_assigns.fetch(:display_preview, field.show_display_preview?) preview_only = local_assigns.fetch(:preview_only, false) %> @@ -28,6 +29,7 @@ This partial renders one or more attachments attachment: attachment, variant: variant, size: size, + display_preview: display_preview, preview_only: preview_only } %>
diff --git a/test_app/Gemfile.lock b/test_app/Gemfile.lock index 3468a24..9fad960 100644 --- a/test_app/Gemfile.lock +++ b/test_app/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - administrate-field-active_storage (0.4.1) + administrate-field-active_storage (1.0.2) administrate (>= 0.2.2) rails (>= 7.0) @@ -256,7 +256,9 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.4.2) + sqlite3 (1.7.3-arm64-darwin) + sqlite3 (1.7.3-x86_64-darwin) + sqlite3 (1.7.3-x86_64-linux) stringio (3.0.9) thor (1.3.0) tilt (2.0.10) diff --git a/test_app/db/schema.rb b/test_app/db/schema.rb index c2aedd6..fd625e9 100644 --- a/test_app/db/schema.rb +++ b/test_app/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_11_17_224946) do +ActiveRecord::Schema[7.1].define(version: 2023_11_17_224946) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -40,9 +40,9 @@ end create_table "posts", force: :cascade do |t| - t.string "title" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "title" end add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"