trestle icon indicating copy to clipboard operation
trestle copied to clipboard

Add collection actions support

Open yagudaev opened this issue 5 years ago • 6 comments

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

yagudaev avatar Mar 12 '19 22:03 yagudaev

Is this issue exists in the roadmap?

metronom72 avatar Sep 04 '19 15:09 metronom72

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

McRipper avatar Jan 09 '20 10:01 McRipper

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

nir0 avatar Feb 06 '20 03:02 nir0

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

McRipper avatar Apr 07 '20 10:04 McRipper

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

image

asad-ali-bhatti avatar May 27 '21 15:05 asad-ali-bhatti

One issue with this is that it does not integrate with the scopes features.

coezbek avatar Dec 16 '21 22:12 coezbek