Hey there, I just subscribed so i hope this question isn''t redundant. I''m trying to implement a sortable nested set. I''ve already got an application with better_nested_set in place. I also got a nice nested <ul> rendering for my tree. No I''d be able to drag an drop / sort elements across the set. I found this Wiki entry which says that it wouldn''t be a good idea in general to use sortable.create with :tree => true http://whynotwiki.com/Rails_/_Sortable_trees On the same page there is a link to the rubyonrails wiki stating that there is a fix expecially for better_nested_set. http://dev.rubyonrails.org/ticket/7807 My question would be what your experiences are. Is there a good way to implement a sortable / draggable better_nested_set ? If not do you have any suggestions, thoughs on this ? Thanks and kind regards, John (Berlin / Germany)
Hello John-Paul, I''ve done this in a recent project. Basically the way I do it is check to see what order the a selected item in a list is in, and then move that item before/after a child node in the target parent based off this information. It''s a bit complicated, but it''s doable. I monkey patched the module SymetrieCom::Acts::NestedSet to include the following method to help me with this scenario: ------------------------------------------------------------------------ def move_to_parent_location(parent, location) parent = nil if parent == 0 parent = parent === self.class ? parent : self.class.find(parent) if parent children = parent ? parent.children : self.class.roots if children.length > 0 ord = location.to_i if ord > children.length self.move_to(children.last, :right) elsif children[ord] != self self.move_to(children[ord], :left) end elsif parent self.move_to(parent, :child) end end ------------------------------------------------------------------------ *Jeremy Nicoll* www.gnexp.com <http://www.gnexp.com> (801) 783-3831 John-Paul Bader wrote:> Hey there, > > I just subscribed so i hope this question isn''t redundant. > > I''m trying to implement a sortable nested set. > > I''ve already got an application with better_nested_set in place. I > also got a nice nested <ul> rendering for my tree. No I''d be able to > drag an drop / sort elements across the set. > > I found this Wiki entry which says that it wouldn''t be a good idea in > general to use sortable.create with :tree => true > > http://whynotwiki.com/Rails_/_Sortable_trees > > On the same page there is a link to the rubyonrails wiki stating that > there is a fix expecially for better_nested_set. http://dev.rubyonrails.org/ticket/7807 > > My question would be what your experiences are. Is there a good way to > implement a sortable / draggable better_nested_set ? If not do you > have any suggestions, thoughs on this ? > > Thanks and kind regards, > > John (Berlin / Germany) > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/betternestedset-talk/attachments/20080319/cf89fb10/attachment-0001.html -------------- next part -------------- A non-text attachment was scrubbed... Name: logo_sig.jpg Type: image/jpeg Size: 2312 bytes Desc: not available Url : http://rubyforge.org/pipermail/betternestedset-talk/attachments/20080319/cf89fb10/attachment-0001.jpg
After lots of reading I think the best way is to use simple draggables and droppables. After the drop i''ll move the dragged node to the dropped one with move_to_child_of and after that i''ll redraw the tree. Any thoughts on that ? Kind regards, John On 19.03.2008, at 20:45, Jeremy Nicoll wrote:> Hello John-Paul, > > I''ve done this in a recent project. Basically the way I do it > is check to see what order the a selected item in a list is in, and > then move that item before/after a child node in the target parent > based off this information. It''s a bit complicated, but it''s > doable. I monkey patched the module SymetrieCom::Acts::NestedSet to > include the following method to help me with this scenario: > > def move_to_parent_location(parent, location) > parent = nil if parent == 0 > parent = parent === self.class ? parent : > self.class.find(parent) if parent > children = parent ? parent.children : self.class.roots > > if children.length > 0 > ord = location.to_i > if ord > children.length > self.move_to(children.last, :right) > elsif children[ord] != self > self.move_to(children[ord], :left) > end > elsif parent > self.move_to(parent, :child) > end > end > > > <logo_sig.jpg> > Jeremy Nicoll > www.gnexp.com > (801) 783-3831 > > > John-Paul Bader wrote: >> >> Hey there, >> >> I just subscribed so i hope this question isn''t redundant. >> >> I''m trying to implement a sortable nested set. >> >> I''ve already got an application with better_nested_set in place. I >> also got a nice nested <ul> rendering for my tree. No I''d be able to >> drag an drop / sort elements across the set. >> >> I found this Wiki entry which says that it wouldn''t be a good idea in >> general to use sortable.create with :tree => true >> >> http://whynotwiki.com/Rails_/_Sortable_trees >> >> On the same page there is a link to the rubyonrails wiki stating that >> there is a fix expecially for better_nested_set. http://dev.rubyonrails.org/ticket/7807 >> >> My question would be what your experiences are. Is there a good way >> to >> implement a sortable / draggable better_nested_set ? If not do you >> have any suggestions, thoughs on this ? >> >> Thanks and kind regards, >> >> John (Berlin / Germany) >> _______________________________________________ >> Betternestedset-talk mailing list >> Betternestedset-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/betternestedset-talk >> >> > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/betternestedset-talk/attachments/20080319/3b2a0fa7/attachment.html
No thoughts at the moment, but if you run into any problems I''ll see if I can help you. FYI, I have not used the two components that you are using together - mostly I''ve just used better_nested_set. Ordering things in a list is pretty easy and so I''ve always just done my own code because I''ve felt the other helpers just get in my way. *Jeremy Nicoll* www.gnexp.com <http://www.gnexp.com> (801) 783-3831 John-Paul Bader wrote:> After lots of reading I think the best way is to use simple draggables > and droppables. After the drop i''ll move the dragged node to the > dropped one with move_to_child_of and after that i''ll redraw the tree. > > Any thoughts on that ? > > Kind regards, John > > On 19.03.2008, at 20:45, Jeremy Nicoll wrote: >> Hello John-Paul, >> >> I''ve done this in a recent project. Basically the way I do it is >> check to see what order the a selected item in a list is in, and then >> move that item before/after a child node in the target parent based >> off this information. It''s a bit complicated, but it''s doable. I >> monkey patched the module SymetrieCom::Acts::NestedSet to include the >> following method to help me with this scenario: >> >> ------------------------------------------------------------------------ >> def move_to_parent_location(parent, location) >> parent = nil if parent == 0 >> parent = parent === self.class ? parent : >> self.class.find(parent) if parent >> children = parent ? parent.children : self.class.roots >> >> if children.length > 0 >> ord = location.to_i >> if ord > children.length >> self.move_to(children.last, :right) >> elsif children[ord] != self >> self.move_to(children[ord], :left) >> end >> elsif parent >> self.move_to(parent, :child) >> end >> end >> ------------------------------------------------------------------------ >> >> >> <logo_sig.jpg> >> *Jeremy Nicoll* >> www.gnexp.com <http://www.gnexp.com> >> (801) 783-3831 >> >> >> John-Paul Bader wrote: >>> Hey there, >>> >>> I just subscribed so i hope this question isn''t redundant. >>> >>> I''m trying to implement a sortable nested set. >>> >>> I''ve already got an application with better_nested_set in place. I >>> also got a nice nested <ul> rendering for my tree. No I''d be able to >>> drag an drop / sort elements across the set. >>> >>> I found this Wiki entry which says that it wouldn''t be a good idea in >>> general to use sortable.create with :tree => true >>> >>> http://whynotwiki.com/Rails_/_Sortable_trees >>> >>> On the same page there is a link to the rubyonrails wiki stating that >>> there is a fix expecially for better_nested_set. http://dev.rubyonrails.org/ticket/7807 >>> >>> My question would be what your experiences are. Is there a good way to >>> implement a sortable / draggable better_nested_set ? If not do you >>> have any suggestions, thoughs on this ? >>> >>> Thanks and kind regards, >>> >>> John (Berlin / Germany) >>> _______________________________________________ >>> Betternestedset-talk mailing list >>> Betternestedset-talk at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/betternestedset-talk >>> >>> >> _______________________________________________ >> Betternestedset-talk mailing list >> Betternestedset-talk at rubyforge.org >> <mailto:Betternestedset-talk at rubyforge.org> >> http://rubyforge.org/mailman/listinfo/betternestedset-talk > > ------------------------------------------------------------------------ > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/betternestedset-talk/attachments/20080319/dd180f07/attachment.html -------------- next part -------------- A non-text attachment was scrubbed... Name: logo_sig.jpg Type: image/jpeg Size: 2312 bytes Desc: not available Url : http://rubyforge.org/pipermail/betternestedset-talk/attachments/20080319/dd180f07/attachment.jpg
Well I think actually these are two seperate functions. One function is to put nodes on different positions in the tree and the other one would be ordering the nodes within a parent node. Tomorrow at work I''ll try that approach and let you know how it went. Kind regards, John On 19.03.2008, at 23:04, Jeremy Nicoll wrote:> No thoughts at the moment, but if you run into any problems I''ll > see if I can help you. FYI, I have not used the two components that > you are using together - mostly I''ve just used better_nested_set. > Ordering things in a list is pretty easy and so I''ve always just > done my own code because I''ve felt the other helpers just get in my > way. > > <logo_sig.jpg> > Jeremy Nicoll > www.gnexp.com > (801) 783-3831 > > > John-Paul Bader wrote: >> >> After lots of reading I think the best way is to use simple >> draggables and droppables. After the drop i''ll move the dragged >> node to the dropped one with move_to_child_of and after that i''ll >> redraw the tree. >> >> Any thoughts on that ? >> >> Kind regards, John >> >> On 19.03.2008, at 20:45, Jeremy Nicoll wrote: >>> Hello John-Paul, >>> >>> I''ve done this in a recent project. Basically the way I do it >>> is check to see what order the a selected item in a list is in, >>> and then move that item before/after a child node in the target >>> parent based off this information. It''s a bit complicated, but >>> it''s doable. I monkey patched the module >>> SymetrieCom::Acts::NestedSet to include the following method to >>> help me with this scenario: >>> >>> def move_to_parent_location(parent, location) >>> parent = nil if parent == 0 >>> parent = parent === self.class ? parent : >>> self.class.find(parent) if parent >>> children = parent ? parent.children : self.class.roots >>> >>> if children.length > 0 >>> ord = location.to_i >>> if ord > children.length >>> self.move_to(children.last, :right) >>> elsif children[ord] != self >>> self.move_to(children[ord], :left) >>> end >>> elsif parent >>> self.move_to(parent, :child) >>> end >>> end >>> >>> >>> <logo_sig.jpg> >>> Jeremy Nicoll >>> www.gnexp.com >>> (801) 783-3831 >>> >>> >>> John-Paul Bader wrote: >>>> >>>> Hey there, >>>> >>>> I just subscribed so i hope this question isn''t redundant. >>>> >>>> I''m trying to implement a sortable nested set. >>>> >>>> I''ve already got an application with better_nested_set in place. I >>>> also got a nice nested <ul> rendering for my tree. No I''d be able >>>> to >>>> drag an drop / sort elements across the set. >>>> >>>> I found this Wiki entry which says that it wouldn''t be a good >>>> idea in >>>> general to use sortable.create with :tree => true >>>> >>>> http://whynotwiki.com/Rails_/_Sortable_trees >>>> >>>> On the same page there is a link to the rubyonrails wiki stating >>>> that >>>> there is a fix expecially for better_nested_set. http://dev.rubyonrails.org/ticket/7807 >>>> >>>> My question would be what your experiences are. Is there a good >>>> way to >>>> implement a sortable / draggable better_nested_set ? If not do you >>>> have any suggestions, thoughs on this ? >>>> >>>> Thanks and kind regards, >>>> >>>> John (Berlin / Germany) >>>> _______________________________________________ >>>> Betternestedset-talk mailing list >>>> Betternestedset-talk at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/betternestedset-talk >>>> >>>> >>> _______________________________________________ >>> Betternestedset-talk mailing list >>> Betternestedset-talk at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/betternestedset-talk >> >> >> _______________________________________________ >> Betternestedset-talk mailing list >> Betternestedset-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/betternestedset-talk >> > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/betternestedset-talk/attachments/20080319/0cc1fcf2/attachment-0001.html
Oh, I think I know what you are saying now. Actually, it''s a bit more hairy than that because with nested sets, the order is determined by the "lft" column. You cannot change this column directly, as ANS (and as such, BNS) uses this to keep track of where everything belongs. If you don''t care about the ordering of the children when retrieved by the BNS methods then you might be able to do the method that you are thinking. Something to consider. *Jeremy Nicoll* www.gnexp.com <http://www.gnexp.com> (801) 783-3831 John-Paul Bader wrote:> Well I think actually these are two seperate functions. One function > is to put nodes on different positions in the tree and the other one > would be ordering the nodes within a parent node. Tomorrow at work > I''ll try that approach and let you know how it went. > > Kind regards, John > > On 19.03.2008, at 23:04, Jeremy Nicoll wrote: >> No thoughts at the moment, but if you run into any problems I''ll >> see if I can help you. FYI, I have not used the two components that >> you are using together - mostly I''ve just used better_nested_set. >> Ordering things in a list is pretty easy and so I''ve always just done >> my own code because I''ve felt the other helpers just get in my way. >> >> <logo_sig.jpg> >> *Jeremy Nicoll* >> www.gnexp.com <http://www.gnexp.com> >> (801) 783-3831 >> >> >> John-Paul Bader wrote: >>> After lots of reading I think the best way is to use simple >>> draggables and droppables. After the drop i''ll move the dragged node >>> to the dropped one with move_to_child_of and after that i''ll redraw >>> the tree. >>> >>> Any thoughts on that ? >>> >>> Kind regards, John >>> >>> On 19.03.2008, at 20:45, Jeremy Nicoll wrote: >>>> Hello John-Paul, >>>> >>>> I''ve done this in a recent project. Basically the way I do it >>>> is check to see what order the a selected item in a list is in, and >>>> then move that item before/after a child node in the target parent >>>> based off this information. It''s a bit complicated, but it''s >>>> doable. I monkey patched the module SymetrieCom::Acts::NestedSet to >>>> include the following method to help me with this scenario: >>>> >>>> ------------------------------------------------------------------------ >>>> def move_to_parent_location(parent, location) >>>> parent = nil if parent == 0 >>>> parent = parent === self.class ? parent : >>>> self.class.find(parent) if parent >>>> children = parent ? parent.children : self.class.roots >>>> >>>> if children.length > 0 >>>> ord = location.to_i >>>> if ord > children.length >>>> self.move_to(children.last, :right) >>>> elsif children[ord] != self >>>> self.move_to(children[ord], :left) >>>> end >>>> elsif parent >>>> self.move_to(parent, :child) >>>> end >>>> end >>>> ------------------------------------------------------------------------ >>>> >>>> >>>> <logo_sig.jpg> >>>> *Jeremy Nicoll* >>>> www.gnexp.com <http://www.gnexp.com> >>>> (801) 783-3831 >>>> >>>> >>>> John-Paul Bader wrote: >>>>> Hey there, >>>>> >>>>> I just subscribed so i hope this question isn''t redundant. >>>>> >>>>> I''m trying to implement a sortable nested set. >>>>> >>>>> I''ve already got an application with better_nested_set in place. I >>>>> also got a nice nested <ul> rendering for my tree. No I''d be able to >>>>> drag an drop / sort elements across the set. >>>>> >>>>> I found this Wiki entry which says that it wouldn''t be a good idea in >>>>> general to use sortable.create with :tree => true >>>>> >>>>> http://whynotwiki.com/Rails_/_Sortable_trees >>>>> >>>>> On the same page there is a link to the rubyonrails wiki stating that >>>>> there is a fix expecially for better_nested_set. http://dev.rubyonrails.org/ticket/7807 >>>>> >>>>> My question would be what your experiences are. Is there a good way to >>>>> implement a sortable / draggable better_nested_set ? If not do you >>>>> have any suggestions, thoughs on this ? >>>>> >>>>> Thanks and kind regards, >>>>> >>>>> John (Berlin / Germany) >>>>> _______________________________________________ >>>>> Betternestedset-talk mailing list >>>>> Betternestedset-talk at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/betternestedset-talk >>>>> >>>>> >>>> _______________________________________________ >>>> Betternestedset-talk mailing list >>>> Betternestedset-talk at rubyforge.org >>>> <mailto:Betternestedset-talk at rubyforge.org> >>>> http://rubyforge.org/mailman/listinfo/betternestedset-talk >>> >>> ------------------------------------------------------------------------ >>> >>> _______________________________________________ >>> Betternestedset-talk mailing list >>> Betternestedset-talk at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/betternestedset-talk >>> >> _______________________________________________ >> Betternestedset-talk mailing list >> Betternestedset-talk at rubyforge.org >> <mailto:Betternestedset-talk at rubyforge.org> >> http://rubyforge.org/mailman/listinfo/betternestedset-talk > > ------------------------------------------------------------------------ > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/betternestedset-talk/attachments/20080319/ca00a0dc/attachment.html -------------- next part -------------- A non-text attachment was scrubbed... Name: logo_sig.jpg Type: image/jpeg Size: 2312 bytes Desc: not available Url : http://rubyforge.org/pipermail/betternestedset-talk/attachments/20080319/ca00a0dc/attachment.jpg
Just in case you hadn''t seen them, BNS has all the ordering methods of ActsAsList, and a method for swapping 2 nodes in a single operation. This should be everything you need for sorting, correct? Krishna On Wed, Mar 19, 2008 at 4:23 PM, Jeremy Nicoll <jnicoll at gnexp.com> wrote:> > Oh, I think I know what you are saying now. Actually, it''s a bit more > hairy than that because with nested sets, the order is determined by the > "lft" column. You cannot change this column directly, as ANS (and as such, > BNS) uses this to keep track of where everything belongs. If you don''t care > about the ordering of the children when retrieved by the BNS methods then > you might be able to do the method that you are thinking. Something to > consider. > > > > > > > Jeremy Nicoll > www.gnexp.com > (801) 783-3831 > > John-Paul Bader wrote: > > Well I think actually these are two seperate functions. One function is to > put nodes on different positions in the tree and the other one would be > ordering the nodes within a parent node. Tomorrow at work I''ll try that > approach and let you know how it went. > > > Kind regards, John > > > > On 19.03.2008, at 23:04, Jeremy Nicoll wrote: > > > No thoughts at the moment, but if you run into any problems I''ll see if > I can help you. FYI, I have not used the two components that you are using > together - mostly I''ve just used better_nested_set. Ordering things in a > list is pretty easy and so I''ve always just done my own code because I''ve > felt the other helpers just get in my way. > > > > <logo_sig.jpg> > Jeremy Nicoll > www.gnexp.com > (801) 783-3831 > > John-Paul Bader wrote: > > After lots of reading I think the best way is to use simple draggables and > droppables. After the drop i''ll move the dragged node to the dropped one > with move_to_child_of and after that i''ll redraw the tree. > > > Any thoughts on that ? > > > Kind regards, John > > On 19.03.2008, at 20:45, Jeremy Nicoll wrote: > > > Hello John-Paul, > > I''ve done this in a recent project. Basically the way I do it is check > to see what order the a selected item in a list is in, and then move that > item before/after a child node in the target parent based off this > information. It''s a bit complicated, but it''s doable. I monkey patched the > module SymetrieCom::Acts::NestedSet to include the following method to help > me with this scenario: > > ________________________________ > def move_to_parent_location(parent, location) > parent = nil if parent == 0 > parent = parent === self.class ? parent : self.class.find(parent) > if parent > children = parent ? parent.children : self.class.roots > > if children.length > 0 > ord = location.to_i > if ord > children.length > self.move_to(children.last, :right) > elsif children[ord] != self > self.move_to(children[ord], :left) > end > elsif parent > self.move_to(parent, :child) > end > end > ________________________________ > > > > > <logo_sig.jpg> > Jeremy Nicoll > www.gnexp.com > (801) 783-3831 > > John-Paul Bader wrote: > Hey there, > > I just subscribed so i hope this question isn''t redundant. > > I''m trying to implement a sortable nested set. > > I''ve already got an application with better_nested_set in place. I > also got a nice nested <ul> rendering for my tree. No I''d be able to > drag an drop / sort elements across the set. > > I found this Wiki entry which says that it wouldn''t be a good idea in > general to use sortable.create with :tree => true > > http://whynotwiki.com/Rails_/_Sortable_trees > > On the same page there is a link to the rubyonrails wiki stating that > there is a fix expecially for better_nested_set. > http://dev.rubyonrails.org/ticket/7807 > > My question would be what your experiences are. Is there a good way to > implement a sortable / draggable better_nested_set ? If not do you > have any suggestions, thoughs on this ? > > Thanks and kind regards, > > John (Berlin / Germany) > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > ________________________________ > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > ________________________________ > > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > >