Module: ActiveAdmin::AsyncExporter::Reports::DSL
- Defined in:
- lib/active_admin/async_exporter/reports/dsl.rb
Instance Attribute Summary collapse
-
#csv_fields ⇒ Object
readonly
Returns the value of attribute csv_fields.
Instance Method Summary collapse
- #csv_async(decorate_model: false, file_name: nil) ⇒ Object
- #csv_column(column_name, column_value = nil, &block) ⇒ Object
- #csv_report(columns:, decorate_model: false, file_name: nil) ⇒ Object
Instance Attribute Details
#csv_fields ⇒ Object (readonly)
Returns the value of attribute csv_fields.
7 8 9 |
# File 'lib/active_admin/async_exporter/reports/dsl.rb', line 7 def csv_fields @csv_fields end |
Instance Method Details
#csv_async(decorate_model: false, file_name: nil) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/active_admin/async_exporter/reports/dsl.rb', line 9 def csv_async(decorate_model: false, file_name: nil) @csv_fields ||= {} yield csv_report(columns: csv_fields, decorate_model: decorate_model, file_name: file_name) end |
#csv_column(column_name, column_value = nil, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_admin/async_exporter/reports/dsl.rb', line 17 def csv_column(column_name, column_value = nil, &block) column_value ||= column_name column_value = block.source if block_given? raise ActiveAdmin::AsyncExporter::Error, 'No argument given' if block_given? && block.parameters.blank? csv_fields[column_name.to_sym] = { block: block_given?, value: column_value.to_s } end |
#csv_report(columns:, decorate_model: false, file_name: nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/active_admin/async_exporter/reports/dsl.rb', line 28 def csv_report(columns:, decorate_model: false, file_name: nil) action_item :download_csv, only: :index do link_to 'Download CSV', { action: :download_csv, params: params.to_enum.to_h }, method: :post, data: { confirm: 'Are you sure you want to generate this report?' } end collection_action :download_csv, method: :post do admin_report = AdminReport.create!( author_id: current_admin_user.id, entity: current_collection.name, status: :pending ) = { admin_report_id: admin_report.id, controller: self.class.name, columns: columns, decorate_model: decorate_model, file_name: file_name, query: params['q'] } ActiveAdmin::AsyncExporter::Worker.perform_later() redirect_to admin_admin_report_path(admin_report) end controller do def current_collection scoped_collection end end end |