Hi all, as a newbie to ROR and user of better nested set, I''m wondering if someone has a code snippet to put me in the right way for displaying a partial tree of a node in the view. The problem is that I don''t know how up front how many levels my tree will have. I''m thinking of the Composite pattern of the GoF for displaying the three. But how would you use that pattern with a clean model, view and controller separtion? Any suggestions are welcome! Best regards, Mark Noten ________________________________________________ Message sent using UebiMiau 2.7.10
Hi Mark, I''m not sure exactly what you mean, but have you looked at the helper provided with the plugin? Krishna> as a newbie to ROR and user of better nested set, I''m wondering if someone > has a code snippet to put me in the right way for displaying a partial tree > of a node in the view. > > The problem is that I don''t know how up front how many levels my tree will > have. I''m thinking of the Composite pattern of the GoF for displaying the > three. But how would you use that pattern with a clean model, view and > controller separtion? > > Any suggestions are welcome! > > Best regards, > > Mark Noten > > > ________________________________________________ > Message sent using UebiMiau 2.7.10 > > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk >
Jean-Christophe Michel
2007-Jan-05 16:57 UTC
[Betternestedset-talk] Output a tree in the view
Hi Mark, Le 5 janv. 07, ? 16:28, Mark.noten a ?crit :> as a newbie to ROR and user of better nested set, I''m wondering if > someone > has a code snippet to put me in the right way for displaying a partial > tree > of a node in the view.You can use style="margin-left:<%= item.level %>em;" in your view to have items indented according to their level. Displaying vertical lines like in a mail thread is harder... Jean-Christophe Michel -- symetrie.com Better Nested Set for rails: http://opensource.symetrie.com/trac/better_nested_set
Hi all, Sorry about my brief explanation. I think a small example will quickly show what I''m trying to say. To model a sales organization, I''m using better nested set with a :scope on the column product_id that is a FK to a products table. There can be multiple roots that represent top level sales agents for a certain product and each node is ofcourse a sales agent. A sales agent can write multiple contracts and for each contract he gets a commission on the month he wrote it. A sales agent also gets commission from his children that wrote contracts. Enough said, the sales structure like the following A | \ \ B C D | | E F Could generate a monthly sales report for sales agent A like the following: == Own contracts =A Contract 1 Contract 2 == Contracts children = B Contract 3 == Contracts from children = E Contract 5 D Contract 4 For sales agent B the sales report of that month would just be just a part of the above report: == Own contracts =B Contract 3 == Contracts from children = E Contract 5 I would need a displaying algorithm that would work for any node of the tree and with a tree of unknown depth. I apologize if this mail has little or nothing to do with the better nested set talk. But I think that displaying a tree is as important than creating the tree itself. Thanks for your reply, Mark -----Original Message----- From: Krishna Dole [mailto:dontfall at gmail.com] Sent: vrijdag 5 januari 2007 17:11 To: Mark.noten; betternestedset-talk at rubyforge.org Subject: Re: [Betternestedset-talk] Output a tree in the view Hi Mark, I''m not sure exactly what you mean, but have you looked at the helper provided with the plugin? Krishna> as a newbie to ROR and user of better nested set, I''m wondering if someone > has a code snippet to put me in the right way for displaying a partialtree> of a node in the view. > > The problem is that I don''t know how up front how many levels my tree will > have. I''m thinking of the Composite pattern of the GoF for displaying the > three. But how would you use that pattern with a clean model, view and > controller separtion? > > Any suggestions are welcome! > > Best regards, > > Mark Noten > > > ________________________________________________ > Message sent using UebiMiau 2.7.10 > > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk >
Jean-Christophe Michel
2007-Jan-06 14:01 UTC
[Betternestedset-talk] Output a tree in the view
Hi, Le 5 janv. 07, ? 22:55, Mark Noten a ?crit :> Enough said, the sales structure like the following > > A > | \ \ > B C D > | | > E F > > Could generate a monthly sales report for sales agent A like the > following: > > == Own contracts => A > Contract 1 > Contract 2 > > == Contracts children => B > Contract 3 > == Contracts from children => E > Contract 5 > D > Contract 4 > > For sales agent B the sales report of that month would just be just a > part > of the above report: > > == Own contracts => B > Contract 3 > == Contracts from children => E Contract 5 > > I would need a displaying algorithm that would work for any node of > the tree > and with a tree of unknown depth.Seems that you would need to render :partial => ''contract'', and call the same render :partial from inside _contract.rhtml to render sub contracts. Jean-Christophe Michel -- symetrie.com Better Nested Set for rails: http://opensource.symetrie.com/trac/better_nested_set