To all Rails bounty hunters, Here at Hyperxmedia are in need of an improved act_as_nested_set extension but due to the current load we cannot spend the time to code it ourselves. So we thought, why don''t we get somebody to code it for us, pay him and give the code back to the community? Sounds like a good idea so we are opening the process to anybody that would like to make some money and raise to fame at the same time here are the requirements: Expansion of ActiveRecord::Acts::NestedSet Goal * Improve the current act_as_nested_set implementation with new features: o Get parent/s o Move branches around the tree * Maintain backwards compatibility Process * Contact Adrian Madrid <aemadrid-kSB444ljgzMmlAP/+Wk3EA@public.gmane.org> with the following: o Projected delivery time o References (Rails sites/patches/contributions) * A person is selected from all requesting bounty hunters o If all deliverables are received on time and all the requirements are met the bounty is given to the programmer o In case the deadline or requirements are not met and no other arrangement is made the bounty opens again Requirements * New instance methods o parent() - returns the parent o parents() - returns a flat array of parents o full_parents_set() - returns a flat array of parents including self o move_tree( node_id, position ) - moves self and all its children [before | after] node_id o level() - calculate the tree level (unless provided by already, see Optional) * Full set of unit tests * Well documented code * License: MIT * Maintain backwards compatibility as much as possible. o If is not possible to maintain BC to achieve the previous requirements then this requirements becomes optional. Optional * Configuration options o level_column - column name to maintain level (root == 1) Deliverables * Code including: o nested_set.rb (expanded) o unit tests (expanded) o packaged as a plugin or a replacement for the current code Bounty * $800 on code approval References * Current Implementation o http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/ClassMethods.html#M000458 o http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/InstanceMethods.html#M000462 * Theory o http://www.amazon.com/exec/obidos/ASIN/1558605762/o/qid%3D976072005/sr%3D8-1/ref%3Daps%5Fsr%5Fb%5F1%5F3/104-5998917-1403162 * Other Implementations (PHP) o http://www.klempert.de/php/nested_sets/ o http://www.edutech.ch/contribution/nstrees/ o http://pear.php.net/package/DB_NestedSet/ Please send me any questions you might have about the bounty or the process through the list or directly to my email address: aemadrid-kSB444ljgzMmlAP/+Wk3EA@public.gmane.org Sincerely, -- Adrian Madrid HyperX Inc. Mobile: 801.815.1870 Office: 801.566.0670 aemadrid-kSB444ljgzMmlAP/+Wk3EA@public.gmane.org www.hyperxmedia.com 9000 S. 45 W. Sandy, UT 84070 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Michael Schuerig
2005-Oct-28 18:11 UTC
Re: [ANN] Bounty for expansion of act_as_nested_set
On Friday 28 October 2005 18:59, Adrian Madrid wrote:> Get parent/sThat one''s easy. Just make your AR subclass acts_as_tree as well. Michael -- Michael Schuerig There is no matrix, mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org only reality. http://www.schuerig.de/michael/ --Lawrence Fishburn
Adrian Madrid
2005-Oct-28 19:39 UTC
Re: Re: [ANN] Bounty for expansion of act_as_nested_set
Michael, You''re probably right although it would be nice to have all in one act_as set. The hardest part though is to be able to move a branch to somewhere else in the tree. Thanks, Adrian Madrid On 10/28/05, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> wrote:> On Friday 28 October 2005 18:59, Adrian Madrid wrote: > > Get parent/s > > That one''s easy. Just make your AR subclass acts_as_tree as well. > > Michael > > -- > Michael Schuerig There is no matrix, > mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org only reality. > http://www.schuerig.de/michael/ --Lawrence Fishburn > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Adrian Esteban Madrid aemadrid-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Don''t know which DB you''re using, but if you are using a recent version of MySQL you should give file ''sqltree'' a gander, at: http://rubyforge.org/frs/?group_id=835 The ''move'' method moves tree branches (and renormalizes the entire tree). The ''exits'' method returns an array of parent IDs (starting at the root) if the leaf record exists (is found). Tests only work for MySQL. HTH, -lv Adrian Madrid wrote:> To all Rails bounty hunters, > > Here at Hyperxmedia are in need of an improved act_as_nested_set > extension but due to the current load we cannot spend the time to code > it ourselves. So we thought, why don''t we get somebody to code it for > us, pay him and give the code back to the community? Sounds like a good > idea so we are opening the process to anybody that would like to make > some money and raise to fame at the same time here are the requirements: > > > Expansion of ActiveRecord::Acts::NestedSet > > > Goal > > * Improve the current act_as_nested_set implementation with new > features: > o Get parent/s > o Move branches around the tree > * Maintain backwards compatibility > > > Process > > * Contact Adrian Madrid > <aemadrid-kSB444ljgzMmlAP/+Wk3EA@public.gmane.org> with the following: > o Projected delivery time > o References (Rails sites/patches/contributions) > * A person is selected from all requesting bounty hunters > o If all deliverables are received on time and all the > requirements are met the bounty is given to the programmer > o In case the deadline or requirements are not met and no > other arrangement is made the bounty opens again > > > Requirements > > * New instance methods > o parent() - returns the parent > o parents() - returns a flat array of parents > o full_parents_set() - returns a flat array of parents > including self > o move_tree( node_id, position ) - moves self and all its > children [before | after] node_id > o level() - calculate the tree level (unless provided by > already, see Optional) > * Full set of unit tests > * Well documented code > * License: MIT > * Maintain backwards compatibility as much as possible. > o If is not possible to maintain BC to achieve the previous > requirements then this requirements becomes optional. > > > Optional > > * Configuration options > o level_column - column name to maintain level (root == 1) > > > Deliverables > > * Code including: > o nested_set.rb (expanded) > o unit tests (expanded) > o packaged as a plugin or a replacement for the current code > > > Bounty > > * $800 on code approval > > > References > > * Current Implementation > o http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/ClassMethods.html#M000458 > o http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/InstanceMethods.html#M000462 > * Theory > o http://www.amazon.com/exec/obidos/ASIN/1558605762/o/qid%3D976072005/sr%3D8-1/ref%3Daps%5Fsr%5Fb%5F1%5F3/104-5998917-1403162 > * Other Implementations (PHP) > o http://www.klempert.de/php/nested_sets/ > o http://www.edutech.ch/contribution/nstrees/ > o http://pear.php.net/package/DB_NestedSet/ > > > Please send me any questions you might have about the bounty or the > process through the list or directly to my email address: > aemadrid-kSB444ljgzMmlAP/+Wk3EA@public.gmane.org > > Sincerely, > > > -- > Adrian Madrid > HyperX Inc. > Mobile: 801.815.1870 > Office: 801.566.0670 > aemadrid-kSB444ljgzMmlAP/+Wk3EA@public.gmane.org > www.hyperxmedia.com > > 9000 S. 45 W. > Sandy, UT 84070 > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Adrian Madrid
2005-Oct-28 22:33 UTC
Re: Re: [ANN] Bounty for expansion of act_as_nested_set
Lou, That''s a great find! I''ve been looking for something like this for a long time. The one thing I don''t think it can do is move a node (or branch) inside of the same lavel, meaning if I have a tree like this: Authors - Strauss - Bethoven - Mozart and I want it to end like: Authors - Strauss - Mozart - Bethoven I can''t because I can only move nodes/branches inside another parent and not inside the same parent. Am I missing something? Thanks again, Adrian Madrid Lou Vanek wrote:> Don''t know which DB you''re using, but if you are using a recent > version of MySQL > you should give file ''sqltree'' a gander, at: > > http://rubyforge.org/frs/?group_id=835 > > The ''move'' method moves tree branches (and renormalizes the entire tree). > The ''exits'' method returns an array of parent IDs (starting at the root) > if the leaf record exists (is found). > Tests only work for MySQL. > > HTH, > > -lv > > Adrian Madrid wrote: >> To all Rails bounty hunters, >> >> Here at Hyperxmedia are in need of an improved act_as_nested_set >> extension but due to the current load we cannot spend the time to >> code it ourselves. So we thought, why don''t we get somebody to code >> it for us, pay him and give the code back to the community? Sounds >> like a good idea so we are opening the process to anybody that would >> like to make some money and raise to fame at the same time here are >> the requirements: >> >> >> Expansion of ActiveRecord::Acts::NestedSet >> >> >> Goal >> >> * Improve the current act_as_nested_set implementation with new >> features: >> o Get parent/s >> o Move branches around the tree >> * Maintain backwards compatibility >> >> >> Process >> >> * Contact Adrian Madrid >> <aemadrid-kSB444ljgzMmlAP/+Wk3EA@public.gmane.org> with the following: >> o Projected delivery time >> o References (Rails sites/patches/contributions) >> * A person is selected from all requesting bounty hunters >> o If all deliverables are received on time and all the >> requirements are met the bounty is given to the programmer >> o In case the deadline or requirements are not met and no >> other arrangement is made the bounty opens again >> >> >> Requirements >> >> * New instance methods >> o parent() - returns the parent >> o parents() - returns a flat array of parents >> o full_parents_set() - returns a flat array of parents >> including self >> o move_tree( node_id, position ) - moves self and all its >> children [before | after] node_id >> o level() - calculate the tree level (unless provided by >> already, see Optional) >> * Full set of unit tests >> * Well documented code >> * License: MIT >> * Maintain backwards compatibility as much as possible. >> o If is not possible to maintain BC to achieve the previous >> requirements then this requirements becomes optional. >> >> >> Optional >> >> * Configuration options >> o level_column - column name to maintain level (root == 1) >> >> >> Deliverables >> >> * Code including: >> o nested_set.rb (expanded) >> o unit tests (expanded) >> o packaged as a plugin or a replacement for the current code >> >> >> Bounty >> >> * $800 on code approval >> >> >> References >> >> * Current Implementation >> o >> http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/ClassMethods.html#M000458 >> >> o >> http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/InstanceMethods.html#M000462 >> >> * Theory >> o >> http://www.amazon.com/exec/obidos/ASIN/1558605762/o/qid%3D976072005/sr%3D8-1/ref%3Daps%5Fsr%5Fb%5F1%5F3/104-5998917-1403162 >> >> * Other Implementations (PHP) >> o http://www.klempert.de/php/nested_sets/ >> o http://www.edutech.ch/contribution/nstrees/ >> o http://pear.php.net/package/DB_NestedSet/ >> >> >> Please send me any questions you might have about the bounty or the >> process through the list or directly to my email address: >> aemadrid-kSB444ljgzMmlAP/+Wk3EA@public.gmane.org >> >> Sincerely, >> >> >> -- >> Adrian Madrid >> HyperX Inc. Mobile: 801.815.1870 >> Office: 801.566.0670 aemadrid-kSB444ljgzMmlAP/+Wk3EA@public.gmane.org www.hyperxmedia.com >> 9000 S. 45 W. >> Sandy, UT 84070 >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Adrian Madrid HyperX Inc. Mobile: 801.815.1870 Office: 801.566.0670 aemadrid-kSB444ljgzMmlAP/+Wk3EA@public.gmane.org www.hyperxmedia.com 9000 S. 45 W. Sandy, UT 84070 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Barry Walker
2005-Oct-28 22:36 UTC
Re: Re: [ANN] Bounty for expansion of act_as_nested_set
I was able to satisfy my moving needs with a move_up method that moves a node up in front of its previous sibling. def move_up self.reload prev = self.class.find(:first, :conditions => "#{right_col_name} #{self[left_col_name] - 1}") if !(prev.nil?) then # has a higher sibling self.class.update_all( "#{left_col_name} = IF(#{left_col_name}>= #{self[left_col_name]},(#{left _col_name} - #{self[left_col_name] -prev[left_col_name]}),(#{left_col_name} + #{self[right_col_name] - prev[right_col_name]})), #{right_col_name} = IF(#{right_col_name} >#{self[left_col_name]},(#{right_col_name}- #{self[left_col_name] - prev[left_col_name]}),(#{right_col_name}+ #{self[right_col_name] - prev[right_col_name]})) WHERE #{left_col_name} >#{prev[left_col_name]} AND #{right_col_name} <#{self[right_col_name]}") end The set clause is a little long, but it modifies both the moved up entry and the moved down entry and all their children in a single query. You can call it multiple times to reach a specific point. Move_down could be implemented similarly. I also considered promote and demote to move a child up to it''s parent''s or down to it''s child''s level. They would be a similar process. On 10/28/05, Adrian Madrid <aemadrid-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Michael, > > You''re probably right although it would be nice to have all in one > act_as set. The hardest part though is to be able to move a branch to > somewhere else in the tree. > > Thanks, > > > Adrian Madrid > > > On 10/28/05, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> wrote: > > On Friday 28 October 2005 18:59, Adrian Madrid wrote: > > > Get parent/s > > > > That one''s easy. Just make your AR subclass acts_as_tree as well. > > > > Michael > > > > -- > > Michael Schuerig There is no matrix, > > mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org only reality. > > http://www.schuerig.de/michael/ --Lawrence Fishburn > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > Adrian Esteban Madrid > aemadrid-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
You are correct that the ''move'' method only moves branches (it doesn''t swap children). However, the ''children'' instance method allows for a run-time ''sort'' clause so that you can sort children on any arbitrary field. You could add a special ''sort'' field to the table if no other field gives you the sort order. If you manually updated this ''sort'' field (i.e. if you manually swapped children), you would then have to call the ''renumber'' method to renormalize the tree. -lv Adrian Madrid wrote:> Lou, > > That''s a great find! I''ve been looking for something like this for a > long time. The one thing I don''t think it can do is move a node (or > branch) inside of the same lavel, meaning if I have a tree like this: > > Authors > - Strauss > - Bethoven > - Mozart > > and I want it to end like: > > Authors > - Strauss > - Mozart > - Bethoven > > I can''t because I can only move nodes/branches inside another parent and > not inside the same parent. Am I missing something? > > Thanks again, > > > > Adrian Madrid[snip]
P.S. the ''descendants'' method also provides a way to order children nodes. Lou Vanek wrote:> You are correct that the ''move'' method only moves branches (it doesn''t > swap children). > However, the ''children'' instance method allows for a run-time ''sort'' > clause so > that you can sort children on any arbitrary field. You could add a > special ''sort'' field to the table if no other field gives you the sort > order. > If you manually updated this ''sort'' field (i.e. if you manually swapped > children), > you would then have to call the ''renumber'' method to renormalize the tree. > > -lv...
Michael Houghton
2005-Oct-29 00:34 UTC
Re: [ANN] Bounty for expansion of act_as_nested_set
Right, well, I wish I had time to go for this. If anyone is going for this, there are two books by Joe Celko that will interest (Trees In SQL For Smarties being the obvious one). As for all_parents(), if this is not already obvious, consider this a freebie to start. I use this code in my nested category model (the rest of the code is fairly ugly and not of any value here). # Get all the parents for this item, all the way up the tree def all_parents unless @all_parents @all_parents = ContentCategory.find_by_sql([ "select p.* from content_categories as p, content_categories as me where me.id=? and me.lft between p.lft and p.rgt and p.id! =me.id order by p.lft", self.id]) unless self.root? @all_parents ||= Array.new end @all_parents end (The parents of ''me'' are all the nodes where me.lft is between the node''s lft and rgt) Best of luck, anyone :) On 28 Oct 2005, at 17:59, Adrian Madrid wrote:> To all Rails bounty hunters, > > Here at Hyperxmedia are in need of an improved act_as_nested_set > extension but due to the current load we cannot spend the time to > code it ourselves. So we thought, why don''t we get somebody to code > it for us, pay him and give the code back to the community? Sounds > like a good idea so we are opening the process to anybody that > would like to make some money and raise to fame at the same time > here are the requirements:_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Adrian Madrid
2005-Oct-31 18:25 UTC
Re: Re: [ANN] Bounty for expansion of act_as_nested_set
Lou, Sorry for answering so late but I was out for the weekend. I have seen already options to move siblings that coupled with your moving of branches would be a great combo. I wish I had the time ti do it myself but that is not going to happen for quite some time. That is the reason why we are looking for somebody that can package together all this code either in a patch (that won''t break BC) or a plugin so everyone can enjoy this. Thanks, Adrian Madrid Lou Vanek wrote:> P.S. the ''descendants'' method also provides a way to order children > nodes. > > > Lou Vanek wrote: > >> You are correct that the ''move'' method only moves branches (it >> doesn''t swap children). >> However, the ''children'' instance method allows for a run-time ''sort'' >> clause so >> that you can sort children on any arbitrary field. You could add a >> special ''sort'' field to the table if no other field gives you the >> sort order. >> If you manually updated this ''sort'' field (i.e. if you manually >> swapped children), >> you would then have to call the ''renumber'' method to renormalize the >> tree. >> >> -lv > ... > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Adrian Madrid HyperX Inc. Mobile: 801.815.1870 Office: 801.566.0670 aemadrid-kSB444ljgzMmlAP/+Wk3EA@public.gmane.org www.hyperxmedia.com 9000 S. 45 W. Sandy, UT 84070 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Michael, Thanks for your code. Implementing parents is very easy and I wonder why it wasn''t there before. Where I really need help is in moving branches around and we''ve seen some code in this thread that would help. There is one person that has offered his services to put it all together and if nobody else answers the call in the next couple of days that person will be the chosen one ;-) Thanks, Adrian Madrid Michael Houghton wrote:> Right, well, I wish I had time to go for this. > > If anyone is going for this, there are two books by Joe Celko that > will interest (Trees In SQL For Smarties being the obvious one). > > As for all_parents(), if this is not already obvious, consider this a > freebie to start. I use this code in my nested category model (the > rest of the code is fairly ugly and not of any value here). > > # Get all the parents for this item, all the way up the tree > def all_parents > unless @all_parents > @all_parents = ContentCategory.find_by_sql([ > "select p.* > from content_categories as p, content_categories as me > where me.id=? and me.lft between p.lft and p.rgt and p.id!=me.id > order by p.lft", > self.id]) unless self.root? > @all_parents ||= Array.new > end > @all_parents > end > > (The parents of ''me'' are all the nodes where me.lft is between the > node''s lft and rgt) > > Best of luck, anyone :) > > > On 28 Oct 2005, at 17:59, Adrian Madrid wrote: > >> To all Rails bounty hunters, >> >> Here at Hyperxmedia are in need of an improved act_as_nested_set >> extension but due to the current load we cannot spend the time to >> code it ourselves. So we thought, why don''t we get somebody to code >> it for us, pay him and give the code back to the community? Sounds >> like a good idea so we are opening the process to anybody that would >> like to make some money and raise to fame at the same time here are >> the requirements: > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Adrian Madrid HyperX Inc. Mobile: 801.815.1870 Office: 801.566.0670 aemadrid-kSB444ljgzMmlAP/+Wk3EA@public.gmane.org www.hyperxmedia.com 9000 S. 45 W. Sandy, UT 84070 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I''m looking forward to seeing the results. -lv Adrian Madrid wrote:> Lou, > > Sorry for answering so late but I was out for the weekend. I have seen > already options to move siblings that coupled with your moving of > branches would be a great combo. I wish I had the time ti do it myself > but that is not going to happen for quite some time. That is the reason > why we are looking for somebody that can package together all this code > either in a patch (that won''t break BC) or a plugin so everyone can > enjoy this. > > Thanks, > > > Adrian Madrid[snip]