diff --git a/Gemfile.lock b/Gemfile.lock index 9794e77..8c84aa6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,84 +1,84 @@ PATH remote: . specs: - trestle-active_storage (3.0.1) - rails (>= 5.2, < 8) - trestle (~> 0.9.0, >= 0.9.3) + trestle-active_storage (3.1.0) + rails (>= 6, < 8) + trestle (~> 0.9, >= 0.9.3) GEM remote: https://rubygems.org/ specs: - actioncable (7.0.4.1) - actionpack (= 7.0.4.1) - activesupport (= 7.0.4.1) + actioncable (7.0.4.3) + actionpack (= 7.0.4.3) + activesupport (= 7.0.4.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.4.1) - actionpack (= 7.0.4.1) - activejob (= 7.0.4.1) - activerecord (= 7.0.4.1) - activestorage (= 7.0.4.1) - activesupport (= 7.0.4.1) + actionmailbox (7.0.4.3) + actionpack (= 7.0.4.3) + activejob (= 7.0.4.3) + activerecord (= 7.0.4.3) + activestorage (= 7.0.4.3) + activesupport (= 7.0.4.3) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.4.1) - actionpack (= 7.0.4.1) - actionview (= 7.0.4.1) - activejob (= 7.0.4.1) - activesupport (= 7.0.4.1) + actionmailer (7.0.4.3) + actionpack (= 7.0.4.3) + actionview (= 7.0.4.3) + activejob (= 7.0.4.3) + activesupport (= 7.0.4.3) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) - actionpack (7.0.4.1) - actionview (= 7.0.4.1) - activesupport (= 7.0.4.1) + actionpack (7.0.4.3) + actionview (= 7.0.4.3) + activesupport (= 7.0.4.3) rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.4.1) - actionpack (= 7.0.4.1) - activerecord (= 7.0.4.1) - activestorage (= 7.0.4.1) - activesupport (= 7.0.4.1) + actiontext (7.0.4.3) + actionpack (= 7.0.4.3) + activerecord (= 7.0.4.3) + activestorage (= 7.0.4.3) + activesupport (= 7.0.4.3) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.4.1) - activesupport (= 7.0.4.1) + actionview (7.0.4.3) + activesupport (= 7.0.4.3) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.4.1) - activesupport (= 7.0.4.1) + activejob (7.0.4.3) + activesupport (= 7.0.4.3) globalid (>= 0.3.6) - activemodel (7.0.4.1) - activesupport (= 7.0.4.1) - activerecord (7.0.4.1) - activemodel (= 7.0.4.1) - activesupport (= 7.0.4.1) - activestorage (7.0.4.1) - actionpack (= 7.0.4.1) - activejob (= 7.0.4.1) - activerecord (= 7.0.4.1) - activesupport (= 7.0.4.1) + activemodel (7.0.4.3) + activesupport (= 7.0.4.3) + activerecord (7.0.4.3) + activemodel (= 7.0.4.3) + activesupport (= 7.0.4.3) + activestorage (7.0.4.3) + actionpack (= 7.0.4.3) + activejob (= 7.0.4.3) + activerecord (= 7.0.4.3) + activesupport (= 7.0.4.3) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.4.1) + activesupport (7.0.4.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) builder (3.2.4) - concurrent-ruby (1.1.10) + concurrent-ruby (1.2.2) crass (1.0.6) date (3.3.3) erubi (1.12.0) - globalid (1.0.1) + globalid (1.1.0) activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) @@ -97,7 +97,7 @@ GEM loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.8.0.1) + mail (2.8.1) mini_mime (>= 0.1.1) net-imap net-pop @@ -105,8 +105,7 @@ GEM marcel (1.0.2) method_source (1.0.0) mini_mime (1.1.2) - mini_portile2 (2.8.1) - minitest (5.17.0) + minitest (5.18.0) net-imap (0.3.4) date net-protocol @@ -117,35 +116,34 @@ GEM net-smtp (0.3.3) net-protocol nio4r (2.5.8) - nokogiri (1.14.0) - mini_portile2 (~> 2.8.0) + nokogiri (1.14.2-x86_64-darwin) racc (~> 1.4) racc (1.6.2) - rack (2.2.6.2) - rack-test (2.0.2) + rack (2.2.6.4) + rack-test (2.1.0) rack (>= 1.3) - rails (7.0.4.1) - actioncable (= 7.0.4.1) - actionmailbox (= 7.0.4.1) - actionmailer (= 7.0.4.1) - actionpack (= 7.0.4.1) - actiontext (= 7.0.4.1) - actionview (= 7.0.4.1) - activejob (= 7.0.4.1) - activemodel (= 7.0.4.1) - activerecord (= 7.0.4.1) - activestorage (= 7.0.4.1) - activesupport (= 7.0.4.1) + rails (7.0.4.3) + actioncable (= 7.0.4.3) + actionmailbox (= 7.0.4.3) + actionmailer (= 7.0.4.3) + actionpack (= 7.0.4.3) + actiontext (= 7.0.4.3) + actionview (= 7.0.4.3) + activejob (= 7.0.4.3) + activemodel (= 7.0.4.3) + activerecord (= 7.0.4.3) + activestorage (= 7.0.4.3) + activesupport (= 7.0.4.3) bundler (>= 1.15.0) - railties (= 7.0.4.1) + railties (= 7.0.4.3) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.5.0) loofah (~> 2.19, >= 2.19.1) - railties (7.0.4.1) - actionpack (= 7.0.4.1) - activesupport (= 7.0.4.1) + railties (7.0.4.3) + actionpack (= 7.0.4.3) + activesupport (= 7.0.4.3) method_source rake (>= 12.2) thor (~> 1.0) @@ -159,18 +157,18 @@ GEM activesupport (>= 5.2) sprockets (>= 3.0.0) thor (1.2.1) - timeout (0.3.1) + timeout (0.3.2) trestle (0.9.7) activemodel (>= 4.2.0) kaminari (>= 1.1.0) railties (>= 4.2.0) sprockets-rails (>= 2.0.0) - tzinfo (2.0.5) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - zeitwerk (2.6.6) + zeitwerk (2.6.7) PLATFORMS ruby @@ -179,4 +177,4 @@ DEPENDENCIES trestle-active_storage! BUNDLED WITH - 1.16.1 + 2.1.2 diff --git a/app/views/trestle/active_storage/_has_many_field.html.erb b/app/views/trestle/active_storage/_has_many_field.html.erb index 228b05d..8c0529b 100644 --- a/app/views/trestle/active_storage/_has_many_field.html.erb +++ b/app/views/trestle/active_storage/_has_many_field.html.erb @@ -10,11 +10,13 @@ <% elsif attachment.variable? %> <%= link_to image_tag(main_app.url_for(attachment.variant(resize_to_limit: [300, 300])), class: "active-storage__image"), main_app.rails_blob_path(attachment, disposition: "attachment") %> - <% elsif attachment.persisted? %> + <% else %> <%= link_to main_app.rails_blob_path(attachment, disposition: "attachment"), class: "btn btn-info" do %> Download <%= field_name %> <% end %> + <% end %> + <% if attachment.persisted? %>
<%= attachment.blob.filename %> <%= builder.check_box("delete_#{field_name}_#{attachment.blob_id.to_s.gsub('-', '')}", label: "Delete this #{field_name.to_s.singularize}") %> diff --git a/lib/trestle/active_storage/controller_concern.rb b/lib/trestle/active_storage/controller_concern.rb index 43ab3a3..74fbc0e 100644 --- a/lib/trestle/active_storage/controller_concern.rb +++ b/lib/trestle/active_storage/controller_concern.rb @@ -5,10 +5,33 @@ module ControllerConcern included do before_action :define_attachment_accessors, only: [:show, :edit, :update, :destroy] + before_action :filter_has_many_attachments, only: [:update] after_action :purge_attachments, only: [:update] + after_action :attach_attachments, only: [:update] end private + def filter_has_many_attachments + return if admin.active_storage_fields.empty? + + @removed_attachments = Hash.new + admin.active_storage_fields.each do |field| + if instance.send(field).respond_to?(:each) + if params.key?(admin.parameter_name) + @removed_attachments[field] = params[admin.parameter_name].delete field.to_sym + end + end + end + end + + def attach_attachments + return if @removed_attachments.blank? + + @removed_attachments.each do |field, attachments| + instance.send(field).attach(attachments) + end + end + def define_attachment_accessors self.instance = admin.find_instance(params) diff --git a/lib/trestle/active_storage/version.rb b/lib/trestle/active_storage/version.rb index 3ab6241..62ee2e0 100644 --- a/lib/trestle/active_storage/version.rb +++ b/lib/trestle/active_storage/version.rb @@ -1,5 +1,5 @@ module Trestle module ActiveStorage - VERSION = '3.0.1' + VERSION = '3.1.0' end end diff --git a/trestle-active_storage.gemspec b/trestle-active_storage.gemspec index 62e100e..fba7618 100644 --- a/trestle-active_storage.gemspec +++ b/trestle-active_storage.gemspec @@ -17,6 +17,6 @@ Gem::Specification.new do |s| s.files = Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md'] s.require_paths = ['lib'] - s.add_dependency 'rails', '>= 5.2', '< 8' - s.add_dependency "trestle", "~> 0.9.0", ">= 0.9.3" + s.add_dependency 'rails', '>= 6', '< 8' + s.add_dependency "trestle", "~> 0.9", ">= 0.9.3" end