administrate
administrate copied to clipboard
Adds ability to set the first sort direction on a dashboard.
I wanted this functionality in a project I'm working on, so decided to submit a little PR to be considered.
Basically, in my project we want the first sort order when sorting a dashboard's column to be :desc
instead of the default (:asc
).
This PR allows you to override the default_first_sort_direction
in an application_controller
to be :desc
.
I'm relatively inexperienced with Ruby, so if there is a better way to do some of the things this does, I would love to hear ways to improve it!
Thank you for this PR. I've been trying to wrap my head about all this section of the code, and I see it's tricky.
Initially, your change would work, but I'm feeling uneasy about Administrate::Order
getting too many responsibilities. I feel that it shouldn't know how to order as well as what the next option should be, and instead this second concern should be handled... perhaps by the collection...? This concern is already there though, it's not like your PR adds it.
I'm not sure though. A new question here is how to configure this behaviour in tables for fields of type HasMany. The moment we consider this, perhaps the controller shouldn't have been the place for this in the first place.
I need to think about this a bit. I wonder if someone else may have some ideas. Perhaps @nickcharlton?
Totally understand!
I'm not familiar with the administrate plugin api, but maybe this could be a plugin instead?
Theoretically, it could be done with a plugin, but it would require significant monkeypatching and it could break easily when the affected code changes within Administrate.
I'm with @pablobm on it not quite feeling right in Order
. This feels like maybe it's a Dashboard responsibility, do you have any thoughts on how it could instead go there?