Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

max_csv_records = 2000 (fixed to work with lastest activedadmin) #45

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PATH
remote: .
specs:
activeadmin-axlsx (3.0.0)
activeadmin (~> 0.6.0)
activeadmin (>= 1.0.0.pre2)
axlsx

GEM
Expand Down
4 changes: 2 additions & 2 deletions activeadmin-axlsx.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Gem::Specification.new do |s|
s.description = <<-eof
This gem uses axlsx to provide excel/xlsx downloads for resources in Active Admin. Often, users are happier with excel, so why not give it to them instead of CSV?
eof
s.files = `git ls-files`.split("\n").sort
s.files = `git ls-files`.split("\n").sort
s.test_files = `git ls-files -- {spec}/*`.split("\n")
s.test_files = Dir.glob("{spec/**/*}")

s.add_runtime_dependency 'activeadmin', "~> 0.6.0"
s.add_runtime_dependency 'activeadmin', ">= 1.0.0.pre2"
s.add_runtime_dependency 'axlsx'

s.required_ruby_version = '>= 1.9.2'
Expand Down
6 changes: 0 additions & 6 deletions lib/active_admin/axlsx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@ class Railtie < ::Rails::Railtie
rescue NameError
# noop
end

end

config.after_initialize do
ActiveAdmin::ResourceDSL.send :include, ActiveAdmin::Axlsx::DSL
ActiveAdmin::Resource.send :include, ActiveAdmin::Axlsx::ResourceExtension
ActiveAdmin::Views::PaginatedCollection.add_format :xlsx
ActiveAdmin::ResourceController.send :include, ActiveAdmin::Axlsx::ResourceControllerExtension
end
end


21 changes: 12 additions & 9 deletions lib/active_admin/axlsx/resource_controller_extension.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
module ActiveAdmin
module Axlsx
module ResourceControllerExtension

def self.included(base)
base.send :alias_method_chain, :per_page, :xlsx
base.send :alias_method_chain, :index, :xlsx
# base.send :alias_method_chain, :per_page, :xlsx
# base.send :alias_method_chain, :index, :xlsx
base.preprend(ResourceControllerExtension)
base.send :respond_to, :xlsx
end

# patching the index method to allow the xlsx format.
def index_with_xlsx(options={}, &block)
index_without_xlsx(options) do |format|
def index(&block)
index_without_xlsx do |format|
format.xlsx do
xlsx = active_admin_config.xlsx_builder.serialize(collection)
send_data xlsx, :filename => "#{xlsx_filename}", :type => Mime::Type.lookup_by_extension(:xlsx)
Expand All @@ -18,11 +20,12 @@ def index_with_xlsx(options={}, &block)
end

# patching per_page to use the CSV record max for pagination when the format is xlsx
def per_page_with_xlsx
if request.format == Mime::Type.lookup_by_extension(:xlsx)
return max_csv_records
end
per_page_without_xlsx
def per_page
max_csv_records = 2000
if request.format == Mime::Type.lookup_by_extension(:xlsx)
return max_csv_records
end
per_page_without_xlsx
end

# Returns a filename for the xlsx file using the collection_name
Expand Down