-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2385 from omoshetech-t/refile-support
Add refile support
- Loading branch information
Showing
15 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'rails_admin/config/fields' | ||
require 'rails_admin/config/fields/types' | ||
require 'rails_admin/config/fields/types/file_upload' | ||
|
||
RailsAdmin::Config::Fields.register_factory do |parent, properties, fields| | ||
extensions = [:id, :filename, :size, :content_type] | ||
model = parent.abstract_model.model | ||
if (properties.name.to_s =~ /^(.+)_id$/) && defined?(::Refile) && model.ancestors.map(&:to_s).include?("Refile::Attachment(#{attachment_name = Regexp.last_match[1].to_sym})") | ||
field = RailsAdmin::Config::Fields::Types.load(:refile).new(parent, attachment_name, properties) | ||
children_fields = [] | ||
extensions.each do |ext| | ||
children_column_name = "#{attachment_name}_#{ext}".to_sym | ||
next unless child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s } | ||
children_field = fields.detect { |f| f.name == children_column_name } || RailsAdmin::Config::Fields.default_factory.call(parent, child_properties, fields) | ||
children_field.hide | ||
children_field.filterable(false) | ||
children_fields << children_field.name | ||
end | ||
field.children_fields(children_fields) | ||
fields << field | ||
true | ||
else | ||
false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'rails_admin/config/fields/base' | ||
require 'rails_admin/config/fields/types/file_upload' | ||
|
||
module RailsAdmin | ||
module Config | ||
module Fields | ||
module Types | ||
class Refile < RailsAdmin::Config::Fields::Types::FileUpload | ||
RailsAdmin::Config::Fields::Types.register(self) | ||
|
||
register_instance_option :thumb_method do | ||
[:limit, 100, 100] | ||
end | ||
|
||
register_instance_option :delete_method do | ||
"remove_#{name}" | ||
end | ||
|
||
def resource_url(thumb = []) | ||
return nil unless value | ||
Object.const_get(:Refile).attachment_url(bindings[:object], name, *thumb) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
spec/dummy_app/db/migrate/20150815102450_add_refile_to_field_tests.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class AddRefileToFieldTests < ActiveRecord::Migration | ||
def change | ||
add_column :field_tests, :refile_asset_id, :string | ||
add_column :field_tests, :refile_asset_filename, :string | ||
add_column :field_tests, :refile_asset_size, :string | ||
add_column :field_tests, :refile_asset_content_type, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters