Skip to content

Commit

Permalink
Fix behaviour for index_display_preview to match documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
pedantic-git committed May 16, 2024
1 parent 951b0e6 commit 11e58d9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 36 deletions.
22 changes: 13 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 8 additions & 21 deletions app/views/fields/active_storage/_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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? %>
<div class="attachments-count">
<%= pluralize(field.attachments.count,
Expand Down
5 changes: 3 additions & 2 deletions app/views/fields/active_storage/_item.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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? %>
<div>
<%= render partial: 'fields/active_storage/preview', locals: local_assigns %>
</div>
Expand Down
2 changes: 2 additions & 0 deletions app/views/fields/active_storage/_items.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
%>

Expand All @@ -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
} %>
</div>
Expand Down
6 changes: 4 additions & 2 deletions test_app/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test_app/db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 11e58d9

Please sign in to comment.