Skip to content

Commit

Permalink
active_admin 1.3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyShirykalov committed Jul 20, 2018
1 parent f45042a commit b11db54
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
3 changes: 1 addition & 2 deletions lib/active_admin/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
require 'active_admin/mongoid/filters/resource_extension'
require 'active_admin/mongoid/controllers/resource_controller'
require 'active_admin/mongoid/resource/attributes'

#ActiveAdmin::ResourceController.prepend(ActiveAdmin::Mongoid::ResourceController)
require 'active_admin/mongoid/csv_builder'

module ActiveAdmin
module Mongoid
Expand Down
27 changes: 27 additions & 0 deletions lib/active_admin/mongoid/csv_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module ActiveAdmin
class CSVBuilder
def build(controller, csv)
@collection = controller.send :find_collection, except: :pagination
columns = exec_columns controller.view_context
options = ActiveAdmin.application.csv_options.merge self.options
bom = options.delete :byte_order_mark
column_names = options.delete(:column_names) { true }
csv_options = options.except :encoding_options, :humanize_name

csv << bom if bom

if column_names
csv << CSV.generate_line(columns.map{ |c| encode c.name, options }, csv_options)
end

(1..paginated_collection.total_pages).each do |page|
paginated_collection(page).each do |resource|
resource = controller.send :apply_decorator, resource
csv << CSV.generate_line(build_row(resource, columns, options), csv_options)
end
end

csv
end
end
end
7 changes: 1 addition & 6 deletions lib/active_admin/mongoid/filter_form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ class ActiveAdmin::Filters::FormBuilder

def filter(method, options = {})
if method.present? && options[:as] ||= default_input_type(method)

if @object.is_a?(Ransack::Search) && @object.respond_to?(:klass)
template.concat input(method, options)
else
template.concat input(method, options)
end
template.concat input(method, options)
end
end

Expand Down
8 changes: 4 additions & 4 deletions lib/active_admin/mongoid/inputs/filters/select_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
class ActiveAdmin::Inputs::Filters::SelectInput
def searchable_method_name
name = if searchable_has_many_through?
"#{reflection.through_reflection.name}_#{reflection.foreign_key}"
else
reflection.key if reflection_searchable?
end
"#{reflection.through_reflection.name}_#{reflection.foreign_key}"
elsif reflection_searchable?
reflection.key
end
(name == '_id') ? 'id' : name
end
end
1 change: 0 additions & 1 deletion lib/active_admin/mongoid/resource/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module Attributes
def foreign_methods
@foreign_methods ||= resource_class.reflect_on_all_associations.
select{ |r| r.macro == :belongs_to }.
#reject{ |r| r.chain.length > 2 && !r.options[:polymorphic] }.
index_by{ |r| r.foreign_key.to_sym }
end

Expand Down
5 changes: 5 additions & 0 deletions spec/features/smoke_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@
end
end

it "builds csv" do
visit '/admin/admin_users.csv'
expect(page.status_code).to eq(200) or eq(304)
end


end
end
Expand Down

0 comments on commit b11db54

Please sign in to comment.