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

Possibility to sort children of a parent (Has many association) #54

Open
gotjosh opened this issue Feb 27, 2016 · 6 comments
Open

Possibility to sort children of a parent (Has many association) #54

gotjosh opened this issue Feb 27, 2016 · 6 comments

Comments

@gotjosh
Copy link

gotjosh commented Feb 27, 2016

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.

@gotjosh
Copy link
Author

gotjosh commented Mar 1, 2016

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.

@dalpo
Copy link
Owner

dalpo commented Mar 1, 2016

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 😃

@dalpo
Copy link
Owner

dalpo commented Mar 1, 2016

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

@JArmando
Copy link

JArmando commented Mar 2, 2016

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.

@ain
Copy link

ain commented Jan 13, 2017

Any updates here? I'm facing the exact same challenge.

@hainam8x
Copy link

Hi, do you have any update on this issues, I having exact the same issues

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

5 participants