sourcelabsllc / administrate_exportable Goto Github PK
View Code? Open in Web Editor NEWSimple plugin to add CSV export feature to Administrate
Home Page: https://www.sourcelabs.io/
License: MIT License
Simple plugin to add CSV export feature to Administrate
Home Page: https://www.sourcelabs.io/
License: MIT License
When clicking the export button, the page stays the same but a file download popup appears asking where to save the CSV file.
When clicking the export button, the browser navigates to a new page where the CSV contents are rendered in a single line (no line breaks), as if a plain text/HTML response had been given.
turbolinks.start()
Using administrate 0.14.0, administrate_exportable 0.2.0, turbolinks 5.2.0 (node dependency).
Thanks for this helpful gem!
When I am trying to export a resource which has two or three other related models data to be exported along with it, it is generating several N+1 queries and with couple of thousand rows I am facing server time out issues.
Upon installing bullet gem I get following on my bullet.log
USE eager loading detected
Resource => [:sponsorships]
Add to your query: .includes([:sponsorships])
GET /admin/resources/export.csv
USE eager loading detected
Resource => [:organizations]
Add to your query: .includes([:organizations])
Just for example my resource_dashboard contains following:
```ATTRIBUTE_TYPES = {
id: Field::Number,
name: Field::String,
resource_type: Field::Enumerate,
organizations: Field::HasMany.with_options(
transform_on_export: -> (field) { field.data&.map(&:name)&.join(", ") if field.data }
),
event_detail: Field::HasOne,
questions: Field::NestedHasMany.with_options(
skip: :resource,
transform_on_export: -> (field) { field.data&.map(&:text)&.join(", ") if field.data }
),
Is there a way to speed up query or prevent eager loading?
I have just been following the readme to setup administrate_exportable with an administrate 0.11.0 installation. I'm getting the following error after clicking the export button:
NoMethodError (undefined method `collection_includes' for #<PlayerDashboard:0x00007ffb7d0d93c0>
Did you mean? collection_attributes):
administrate_exportable (0.1.2) lib/administrate_exportable/exporter_service.rb:84:in `collection'
administrate_exportable (0.1.2) lib/administrate_exportable/exporter_service.rb:19:in `block in csv'
/Users/Chris/.rbenv/versions/2.4.5/lib/ruby/2.4.0/csv.rb:1183:in `generate'
administrate_exportable (0.1.2) lib/administrate_exportable/exporter_service.rb:15:in `csv'
administrate_exportable (0.1.2) lib/administrate_exportable/exporter_service.rb:6:in `csv'
administrate_exportable (0.1.2) lib/administrate_exportable/exporter.rb:12:in `block in exportable'
actionpack (5.2.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
I have added the include line to my controller and my controller starts as follows:
class PlayersController < Admin::ApplicationController
include AdministrateExportable::Exporter
ArgumentError Please use symbols for polymorphic route arguments.
I get this error trying to manually add the button example code from your docs:
<div>
<%= link_to(
'Export',
[:export, namespace, page.resource_name.to_s.pluralize, sanitized_order_params(page, :id).to_h.merge(format: :csv)],
class: 'button'
) if valid_action?(:export) %>
</div>
I'm using:
administrate 0.17
administrate_exportable 0.5
rails 7.0.1
ruby 3.0.3
Administrate gem changed pagination param name from page
to _page
<%= paginate resources, param_name: '_page' %>
Update this view to pass correct param_name
After setting up, I tried to export and got
NoMethodError: undefined method
association_includes' for #PackageDashboard:0x00007f7fd3f67f98`
In searching, I found this reference in Administrate from October
thoughtbot/administrate@8d86f9f
Is it possible that there is a plugin related issue, or is there something else going on? My setup is pretty simple with the route and controller reference on a single model in Administrate.
Thanks for your time.
Thanks for all the hard work on this gem!
I noticed that 'Field::Text' attributes (and maybe others) are being truncated to 50 characters on export. Is this a feature or a bug, and if it's a feature, is there an option to download the whole string?
Ryan
When you are on an index and you search for something that returns an empty table. When you try to export that it raises an error
uninitialized constant Class::ATTRIBUTE_TYPES
Export link you appear only if records > to 0
How to filter data before export based on custom scoped_resource?
Using administrate_exportable with administrate v0.18.0 will cause a deprecation warning to get logged in test and development. They look like this:
DEPRECATION WARNING: The method `valid_action?` is deprecated. Please use `accessible_action?`
instead, or see the documentation for other options. (called from valid_action?
at <GEM_PATH>/administrate-0.18.0/app/controllers/administrate/application_controller.rb:125)
Apparently the practice of calling valid_action?
and show_action?
was replaced with a single call to a new method, accessible_action?
in this PR: thoughtbot/administrate#1941
As far as I can tell, that PR is part of administrate v0.18.0, and unfortunately accessible_action?
doesn't exist in versions before v0.18.0.
I'm guessing that making the deprecation warning go away at the cost of breaking compatibility with older versions isn't worth it, and neither is making the behavior conditional on e.g. Gem.loaded_specs["administrate"].version
... but I thought I'd make this issue for documentation value at least.
The change, were it made, would result in the export button's link_to
in app/views/admin/application/_index_header.html.erb
becoming:
<%= link_to(
'Export',
[:export, namespace, page.resource_name.to_s.pluralize.to_sym, sanitized_order_params(page, :id).to_h.merge(format: :csv)],
class: 'button',
target: '_blank'
) if accessible_action?(page.resource_name, :export) %>
Folks using the latest administrate who wish to avoid the warning can simply copy administrate_exportable's version of _index_header.html.erb
into their project, and update the export button's link_to
to the above. (Generating views in administrate didn't spit out the file when I tried it.)
Finally, it might be of some use to update the readme to provide both versions -- @andreibondarev I'm happy to make a PR with whatever change is desired, if a change is desired at all.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.