rails_admin_nestable
rails_admin_nestable copied to clipboard
Possibility to sort children of a parent (Has many association)
While taking a look at the source code and/or documentation it is unclear on how we could achieve the sortability of children of a parent class (something along of the lines of sorting Players for a given Team).
I would love to have that for a current project I am working on and if you could point me in the right direction I would gladly open up a PR.
My initial analysis takes me on the route to convert (or extend) the Sortable action to be able to use it within an association
field which uses a different kind of configuration. If this is something we want included here I would more than gladly submit more information regarding my investigation.
I have managed to figure out a way this could work. I believe that by adding an additional action that attaches itself to a member and specifying the scope
should be a viable option for when you want to add a member action to sort it's children.
Something along the lines of Team
-> Players
where:
class Team < ActiveRecord::Base
nestable_member({
scope: :players
})
end
This would add a member action on each team that allows players to be sorted. Please let me know if this is a functionality you would like to have inside the gem.
I believe the most effort should be applied in extracting the re-usable parts of the controller Proc
in order keep it as DRY as possible and nifty packed into objects.
Hi @gotjosh! I was thinking to refactor the codebase and implement the same member action for a long time, but I never found the time to realize it.
I didn't understand if you want to realize the nestable_member
as a model's class method or as a rails_admin DSL. For instance:
RailsAdmin.model 'Team' do
nestable_member({
scope: :players
})
end
Personally I prefer the DSL approach.
Anyway I would really appreciate a PR with nestable_member
implementation :smiley:
Moreover I was thinking that we could need to sort different kind of children by a single parent...
What do you think about to receive a nested set of hash in the nestable_member
method?
For instance given Team with many Players and many Coaches, we could need the ability to sort the both children models by a single Team record.
So we could approach that with a something like this:
RailsAdmin.model 'Team' do
nestable_member :players, coaches: {
position_field: :ranking,
live_update: true
}
end
Let me know what do you think
Fantastic! I'll be working with @gotjosh on (by Friday) this one since we're pairing for the implementation of the client work that needed this.
We already have it up and running in our codebase, we would just need to extract it and open up the PR. Feel free to assign it to me.
Any updates here? I'm facing the exact same challenge.
Hi, do you have any update on this issues, I having exact the same issues