Administrate: Multiple dashboards for the same model

Created on 18 Apr 2020  路  4Comments  路  Source: thoughtbot/administrate

Description

Is there a way to have multiple dashboards for the same model depending on scope? A simple example would be if I had a Task model, where status is an enum of [:planned, :doing, :done].

I'd like to have a dashboard for all my tasks that are currently planned, one for doing and one dashboard for done.

What's the current approach for doing this? Thanks!

dashboards models

All 4 comments

From the top of my head, I think this should be possible by creating three (or as many) models that inherit from Task, and are differentiated using Single Table Inheritance on the status column.

Also I'm looking at /app/controllers/administrate/application_controller.rb, and thinking that it might be possible to do this by overriding scoped_resource on each of the three controllers, to return only the appropriate scope. I'm not 100% sure though, as there might be other methods that need to be overridden, of those currently delegated to resource_resolver.

Could you try if one of these work, and let us know? :-)

I'm going to close this for now, as I don't think it is a bug. Please let us know how it went in any case.

One way that I achieved this was to include a URL query parameter that mapped to a scope name defined in my model. Then, in the ModelController#scoped_resource you can do as follows:

    def scoped_resource
      if params['status']
        return resource_class.send(params['status'])
      end
      resource_class
    end

Of course, you should use Strong Parameters to ensure that only whitelisted values make it through. Now, I can create links in my nav or in buttons on my dashboard pages that I can use to GET these routes with the appropriate scopes.

Thanks @stevenbuccini. I will try this the next chance I get.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Reedian picture Reedian  路  4Comments

trandoanhung1991 picture trandoanhung1991  路  3Comments

amyin picture amyin  路  4Comments

namiwang picture namiwang  路  4Comments

rmarronnier picture rmarronnier  路  4Comments