trestle
trestle copied to clipboard
Add collection actions support
It would be nice to have support for collection actions NOT just member action as already described in the documentation.
ActiveAdmin has those https://activeadmin.info/8-custom-actions.html#collection-actions so we can emulate that design.
It is really useful to be able to import/export records.
Looking at the trestle code, I see we are using toolbar(:primary)
in the ERB template to render the toolbar. Maybe something like this:
Trestle.resource(:post) do
toolbar do
default_buttons
link_to "Custom Action", admin.path(:post, model, :custom_action), className: 'fa fa-custom`
end
end
Relates to #185
Is this issue exists in the roadmap?
Would be very usefull, someone can point out how the code can be extended to support this, it's not easy to understand but I'm willing to help
hello guys, just wanted to post a workaround:
app/admin/clients_admin.rb:
Trestle.resource(:clients) do
controller do
def export
# ...
end
end
routes do
get :export, on: :collection
end
end
app/views/admin/clients/index.html.haml:
...
- toolbar(:primary) do |t|
= t.link('Export', export_clients_admin_index_path)
...
you can find full source of this file here: https://github.com/TrestleAdmin/trestle/blob/master/app/views/trestle/resource/index.html.erb
I've found an easy solution without the need of a custom template:
Trestle.resource(:properties) do
...
hook("resource.index.header") do
content_tag(:div, style: "order: 2;align-self: center;") do
link_to(button_tag("Export", icon: 'fa fa-file', class: "btn btn-primary"), export_properties_admin_index_path(format: :xlsx), target: :_blank)
end
end
...
end
I found another workaround which adds new buttons/links to proper toolbar instead of table's toolbar.
controller do
def index
toolbar(:primary) do |t|
t.link(button_tag("+ From Template", icon: 'fa fa-file'), admin.path(:new_organization))
end
end
end
routes do
get :new_organization, on: :collection
end
One issue with this is that it does not integrate with the scopes
features.