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

Add collection actions support #186

Open
yagudaev opened this issue Mar 12, 2019 · 6 comments
Open

Add collection actions support #186

yagudaev opened this issue Mar 12, 2019 · 6 comments

Comments

@yagudaev
Copy link

yagudaev commented Mar 12, 2019

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

@metronom72
Copy link

Is this issue exists in the roadmap?

@McRipper
Copy link
Contributor

McRipper commented Jan 9, 2020

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

@nir0
Copy link

nir0 commented Feb 6, 2020

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

@McRipper
Copy link
Contributor

McRipper commented Apr 7, 2020

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

@asad-ali-bhatti
Copy link

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

@coezbek
Copy link
Contributor

coezbek commented Dec 16, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants