Re: [Lift] Re: Change to support dynamic top level menu items
Ross, You can dynamically add child elements right now: new SiteMap(menuItems) { override def buildMenu(current: Box[Loc[_]]): CompleteMenu = { val tmp = super.buildMenu(current) CompleteMenu(tmp.lines.toList ::: List(additional menus)) } } On Mon, Nov 23, 2009 at 5:16 PM, Ross Mellgren dri...@gmail.com wrote: Understood. Thanks. -Ross On Nov 23, 2009, at 8:15 PM, David Pollak wrote: On Mon, Nov 23, 2009 at 4:55 PM, Ross Mellgren dri...@gmail.com wrote: As much as I subscribe to the a lack of dissent is implicit assent policy, I'm hoping somebody deeply familiar with SiteMap can comment on whether this change seems like a bad idea? I guess if I don't hear anything I'll create an issue and submit the patch for review, but I'd feel better with a bit more discussion. Give me a few days to respond please. -Ross On Nov 22, 2009, at 9:28 PM, philip wrote: Essential for the CMS I am programming as the user needs to be able to define the menu structure. On 11月22日, 上午4時46分, Ross Mellgren dri...@gmail.com wrote: In the recent thread, a couple people asked for the ability to create dynamic menu items per request from the database. David suggested Loc.supplimentalKidMenuItems which works fine for dynamic children of a static menu, but doesn't support the ability to make the top level menu dynamic. Menu has a method called makeMenuItem which gives a Box of MenuItem. What about a new method makeMenuItems that gives a possible plurality of MenuItems whose default implementation deferred to the existing makeMenuItem in the case where it's not overridden? I made this change to my local copy of lift and it seems to work alright. Example Menu: case class DynMenu() extends Menu(Loc(dynmenu, Link(List(dynmenu), true, /dynmenu), Dynamic Menu)) { override def makeMenuItems(path: List[Loc[_]]): Iterable[MenuItem] = DynMenuItem.findAll.map(dmi = { MenuItem(Text(dmi.label.is), Text(dmi.link.is), Nil, false, false, Nil) }) } That is, a Menu can generate 0 or more MenuItems when the menu is being generated. The disadvantage I see is similar to the one with supplimentalKidMenuItems -- that is, you have to manually compute the attributes of MenuItem such as current. However, it does give you the full power to make whatever kind of menu items you want. I looked briefly at seeing if it would be feasible to use a function Box[Req] = SiteMap on LiftRules, but I think the RewritePF auto detection thing in LiftRules.setSiteMap prevents this from being the right thing. The change to lift-webkit: diff --git a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala index d33d1dc..79194f5 100644 --- a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala +++ b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala @@ -61,8 +61,10 @@ case class Menu(loc: Loc[_], kids: Menu*) extends HasKids { } // def buildChildLine: List[MenuItem] = kids.toList.flatMap(m = m.loc.buildItem(Nil, false, false)) + def makeMenuItems(path: List[Loc[_]]): Iterable[MenuItem] = makeMenuItem(path) + def makeMenuItem(path: List[Loc[_]]): Box[MenuItem] = - loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath(path), _inPath(path)) +loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath(path), _inPath(path)) private def _inPath(in: List[Loc[_]]): Boolean = in match { case Nil = false diff --git a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala index 7939938..f8fa307 100644 --- a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala +++ b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala @@ -66,7 +66,7 @@ case class SiteMap(globalParamFuncs: List[PartialFunction[Box[Req], Loc.AnyLocPa case Full(loc) = loc.breadCrumbs case _ = Nil } -CompleteMenu(kids.flatMap(_.makeMenuItem(path))) +CompleteMenu(kids.flatMap(_.makeMenuItems(path))) } } Thoughts? -Ross -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl=. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com . For more options, visit this group at
Re: [Lift] Re: Change to support dynamic top level menu items
I considered this but my problem was that you could not place them into the middle of a static flow, without rummaging around in the CompleteMenu looking for known MenuItems. For example, I was thinking in the CMS case that you probably want a static Home Menu and then some dynamic menus and then maybe some more static menus after that, such as logout etc. Of course, I'm just trying to help out, it's not my use case, so the existing solution of overriding SiteMap.buildMenu may work for philip. -Ross On Nov 24, 2009, at 5:42 PM, David Pollak wrote: Ross, You can dynamically add child elements right now: new SiteMap(menuItems) { override def buildMenu(current: Box[Loc[_]]): CompleteMenu = { val tmp = super.buildMenu(current) CompleteMenu(tmp.lines.toList ::: List(additional menus)) } } On Mon, Nov 23, 2009 at 5:16 PM, Ross Mellgren dri...@gmail.com wrote: Understood. Thanks. -Ross On Nov 23, 2009, at 8:15 PM, David Pollak wrote: On Mon, Nov 23, 2009 at 4:55 PM, Ross Mellgren dri...@gmail.com wrote: As much as I subscribe to the a lack of dissent is implicit assent policy, I'm hoping somebody deeply familiar with SiteMap can comment on whether this change seems like a bad idea? I guess if I don't hear anything I'll create an issue and submit the patch for review, but I'd feel better with a bit more discussion. Give me a few days to respond please. -Ross On Nov 22, 2009, at 9:28 PM, philip wrote: Essential for the CMS I am programming as the user needs to be able to define the menu structure. On 11月22日, 上午4時46分, Ross Mellgren dri...@gmail.com wrote: In the recent thread, a couple people asked for the ability to create dynamic menu items per request from the database. David suggested Loc.supplimentalKidMenuItems which works fine for dynamic children of a static menu, but doesn't support the ability to make the top level menu dynamic. Menu has a method called makeMenuItem which gives a Box of MenuItem. What about a new method makeMenuItems that gives a possible plurality of MenuItems whose default implementation deferred to the existing makeMenuItem in the case where it's not overridden? I made this change to my local copy of lift and it seems to work alright. Example Menu: case class DynMenu() extends Menu(Loc(dynmenu, Link(List (dynmenu), true, /dynmenu), Dynamic Menu)) { override def makeMenuItems(path: List[Loc[_]]): Iterable [MenuItem] = DynMenuItem.findAll.map(dmi = { MenuItem(Text(dmi.label.is), Text(dmi.link.is), Nil, false, false, Nil) }) } That is, a Menu can generate 0 or more MenuItems when the menu is being generated. The disadvantage I see is similar to the one with supplimentalKidMenuItems -- that is, you have to manually compute the attributes of MenuItem such as current. However, it does give you the full power to make whatever kind of menu items you want. I looked briefly at seeing if it would be feasible to use a function Box[Req] = SiteMap on LiftRules, but I think the RewritePF auto detection thing in LiftRules.setSiteMap prevents this from being the right thing. The change to lift-webkit: diff --git a/lift-base/lift-webkit/src/main/scala/net/liftweb/ sitemap/Menu.scala b/lift-base/lift-webkit/src/main/scala/net/ liftweb/sitemap/Menu.scala index d33d1dc..79194f5 100644 --- a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/ Menu.scala +++ b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/ Menu.scala @@ -61,8 +61,10 @@ case class Menu(loc: Loc[_], kids: Menu*) extends HasKids { } // def buildChildLine: List[MenuItem] = kids.toList.flatMap(m = m.loc.buildItem(Nil, false, false)) + def makeMenuItems(path: List[Loc[_]]): Iterable[MenuItem] = makeMenuItem(path) + def makeMenuItem(path: List[Loc[_]]): Box[MenuItem] = - loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath(path), _inPath(path)) +loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath (path), _inPath(path)) private def _inPath(in: List[Loc[_]]): Boolean = in match { case Nil = false diff --git a/lift-base/lift-webkit/src/main/scala/net/liftweb/ sitemap/SiteMap.scala b/lift-base/lift-webkit/src/main/scala/net/ liftweb/sitemap/SiteMap.scala index 7939938..f8fa307 100644 --- a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/ SiteMap.scala +++ b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/ SiteMap.scala @@ -66,7 +66,7 @@ case class SiteMap(globalParamFuncs: List [PartialFunction[Box[Req], Loc.AnyLocPa case Full(loc) = loc.breadCrumbs case _ = Nil } -CompleteMenu(kids.flatMap(_.makeMenuItem(path))) +CompleteMenu(kids.flatMap(_.makeMenuItems(path))) } } Thoughts? -Ross -- You received this message because you are
[Lift] Re: Change to support dynamic top level menu items
There is a poor man's approach to creating top-level menus dynamically. Simply create a number of hidden menus - guessing at the max number your app will likely need - whose text representation, paths and hidden attributes can be adjusted programatically as needed by the application. Not a very satisfactory solution, but in a pinch... Glenn On Nov 24, 2:46 pm, Ross Mellgren dri...@gmail.com wrote: I considered this but my problem was that you could not place them into the middle of a static flow, without rummaging around in the CompleteMenu looking for known MenuItems. For example, I was thinking in the CMS case that you probably want a static Home Menu and then some dynamic menus and then maybe some more static menus after that, such as logout etc. Of course, I'm just trying to help out, it's not my use case, so the existing solution of overriding SiteMap.buildMenu may work for philip. -Ross On Nov 24, 2009, at 5:42 PM, David Pollak wrote: Ross, You can dynamically add child elements right now: new SiteMap(menuItems) { override def buildMenu(current: Box[Loc[_]]): CompleteMenu = { val tmp = super.buildMenu(current) CompleteMenu(tmp.lines.toList ::: List(additional menus)) } } On Mon, Nov 23, 2009 at 5:16 PM, Ross Mellgren dri...@gmail.com wrote: Understood. Thanks. -Ross On Nov 23, 2009, at 8:15 PM, David Pollak wrote: On Mon, Nov 23, 2009 at 4:55 PM, Ross Mellgren dri...@gmail.com wrote: As much as I subscribe to the a lack of dissent is implicit assent policy, I'm hoping somebody deeply familiar with SiteMap can comment on whether this change seems like a bad idea? I guess if I don't hear anything I'll create an issue and submit the patch for review, but I'd feel better with a bit more discussion. Give me a few days to respond please. -Ross On Nov 22, 2009, at 9:28 PM, philip wrote: Essential for the CMS I am programming as the user needs to be able to define the menu structure. On 11月22日, 上午4時46分, Ross Mellgren dri...@gmail.com wrote: In the recent thread, a couple people asked for the ability to create dynamic menu items per request from the database. David suggested Loc.supplimentalKidMenuItems which works fine for dynamic children of a static menu, but doesn't support the ability to make the top level menu dynamic. Menu has a method called makeMenuItem which gives a Box of MenuItem. What about a new method makeMenuItems that gives a possible plurality of MenuItems whose default implementation deferred to the existing makeMenuItem in the case where it's not overridden? I made this change to my local copy of lift and it seems to work alright. Example Menu: case class DynMenu() extends Menu(Loc(dynmenu, Link(List (dynmenu), true, /dynmenu), Dynamic Menu)) { override def makeMenuItems(path: List[Loc[_]]): Iterable [MenuItem] = DynMenuItem.findAll.map(dmi = { MenuItem(Text(dmi.label.is), Text(dmi.link.is), Nil, false, false, Nil) }) } That is, a Menu can generate 0 or more MenuItems when the menu is being generated. The disadvantage I see is similar to the one with supplimentalKidMenuItems -- that is, you have to manually compute the attributes of MenuItem such as current. However, it does give you the full power to make whatever kind of menu items you want. I looked briefly at seeing if it would be feasible to use a function Box[Req] = SiteMap on LiftRules, but I think the RewritePF auto detection thing in LiftRules.setSiteMap prevents this from being the right thing. The change to lift-webkit: diff --git a/lift-base/lift-webkit/src/main/scala/net/liftweb/ sitemap/Menu.scala b/lift-base/lift-webkit/src/main/scala/net/ liftweb/sitemap/Menu.scala index d33d1dc..79194f5 100644 --- a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/ Menu.scala +++ b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/ Menu.scala @@ -61,8 +61,10 @@ case class Menu(loc: Loc[_], kids: Menu*) extends HasKids { } // def buildChildLine: List[MenuItem] = kids.toList.flatMap(m = m.loc.buildItem(Nil, false, false)) + def makeMenuItems(path: List[Loc[_]]): Iterable[MenuItem] = makeMenuItem(path) + def makeMenuItem(path: List[Loc[_]]): Box[MenuItem] = - loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath(path), _inPath(path)) + loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath (path), _inPath(path)) private def _inPath(in: List[Loc[_]]): Boolean = in match { case Nil = false diff --git a/lift-base/lift-webkit/src/main/scala/net/liftweb/ sitemap/SiteMap.scala b/lift-base/lift-webkit/src/main/scala/net/ liftweb/sitemap/SiteMap.scala index 7939938..f8fa307 100644 --- a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/
[Lift] Re: Change to support dynamic top level menu items
Hi David, Thanks. This is what works for me in my old fashioned non-functional way of programming. var sitemap:SiteMap = new SiteMap(Nil, MenuInfo.menu :_*) { override def buildMenu(current: Box[Loc[_]]): CompleteMenu = { val tmp = super.buildMenu(current) var childMenus1:ListBuffer[net.liftweb.sitemap.MenuItem] = new ListBuffer[net.liftweb.sitemap.MenuItem] childMenus1 + new MenuItem(Text(Child1), Text(child1), Nil, false, false, Nil) childMenus1 + new MenuItem(Text(Child2), Text(child2), Nil, false, false, Nil) var childMenus2:ListBuffer[net.liftweb.sitemap.MenuItem] = new ListBuffer[net.liftweb.sitemap.MenuItem] childMenus2 + new MenuItem(Text(Child3), Text(child3), Nil, false, false, Nil) childMenus2 + new MenuItem(Text(Child4), Text(child4), Nil, false, false, Nil) var menu:ListBuffer[net.liftweb.sitemap.MenuItem] = new ListBuffer[net.liftweb.sitemap.MenuItem] menu + new MenuItem(Text(Extra menu1), Text(extramenu1/ test), childMenus1.toList, false, false, Nil) menu + new MenuItem(Text(Extra menu2), Text(extramenu2/ test), childMenus2.toList, false, false, Nil) CompleteMenu(tmp.lines.toList ::: menu.toList) } } LiftRules.setSiteMap(sitemap) Philip On 11月25日, 上午6時42分, David Pollak feeder.of.the.be...@gmail.com wrote: Ross, You can dynamically add child elements right now: new SiteMap(menuItems) { override def buildMenu(current: Box[Loc[_]]): CompleteMenu = { val tmp = super.buildMenu(current) CompleteMenu(tmp.lines.toList ::: List(additional menus)) } } On Mon, Nov 23, 2009 at 5:16 PM, Ross Mellgren dri...@gmail.com wrote: Understood. Thanks. -Ross On Nov 23, 2009, at 8:15 PM, David Pollak wrote: On Mon, Nov 23, 2009 at 4:55 PM, Ross Mellgren dri...@gmail.com wrote: As much as I subscribe to the a lack of dissent is implicit assent policy, I'm hoping somebody deeply familiar with SiteMap can comment on whether this change seems like a bad idea? I guess if I don't hear anything I'll create an issue and submit the patch for review, but I'd feel better with a bit more discussion. Give me a few days to respond please. -Ross On Nov 22, 2009, at 9:28 PM, philip wrote: Essential for the CMS I am programming as the user needs to be able to define the menu structure. On 11月22日, 上午4時46分, Ross Mellgren dri...@gmail.com wrote: In the recent thread, a couple people asked for the ability to create dynamic menu items per request from the database. David suggested Loc.supplimentalKidMenuItems which works fine for dynamic children of a static menu, but doesn't support the ability to make the top level menu dynamic. Menu has a method called makeMenuItem which gives a Box of MenuItem. What about a new method makeMenuItems that gives a possible plurality of MenuItems whose default implementation deferred to the existing makeMenuItem in the case where it's not overridden? I made this change to my local copy of lift and it seems to work alright. Example Menu: case class DynMenu() extends Menu(Loc(dynmenu, Link(List(dynmenu), true, /dynmenu), Dynamic Menu)) { override def makeMenuItems(path: List[Loc[_]]): Iterable[MenuItem] = DynMenuItem.findAll.map(dmi = { MenuItem(Text(dmi.label.is), Text(dmi.link.is), Nil, false, false, Nil) }) } That is, a Menu can generate 0 or more MenuItems when the menu is being generated. The disadvantage I see is similar to the one with supplimentalKidMenuItems -- that is, you have to manually compute the attributes of MenuItem such as current. However, it does give you the full power to make whatever kind of menu items you want. I looked briefly at seeing if it would be feasible to use a function Box[Req] = SiteMap on LiftRules, but I think the RewritePF auto detection thing in LiftRules.setSiteMap prevents this from being the right thing. The change to lift-webkit: diff --git a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala index d33d1dc..79194f5 100644 --- a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala +++ b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala @@ -61,8 +61,10 @@ case class Menu(loc: Loc[_], kids: Menu*) extends HasKids { } // def buildChildLine: List[MenuItem] = kids.toList.flatMap(m = m.loc.buildItem(Nil, false, false)) + def makeMenuItems(path: List[Loc[_]]): Iterable[MenuItem] = makeMenuItem(path) + def makeMenuItem(path: List[Loc[_]]): Box[MenuItem] = - loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath(path), _inPath(path)) + loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath(path), _inPath(path)) private def _inPath(in: List[Loc[_]]): Boolean = in match {
Re: [Lift] Re: Change to support dynamic top level menu items
As much as I subscribe to the a lack of dissent is implicit assent policy, I'm hoping somebody deeply familiar with SiteMap can comment on whether this change seems like a bad idea? I guess if I don't hear anything I'll create an issue and submit the patch for review, but I'd feel better with a bit more discussion. -Ross On Nov 22, 2009, at 9:28 PM, philip wrote: Essential for the CMS I am programming as the user needs to be able to define the menu structure. On 11月22日, 上午4時46分, Ross Mellgren dri...@gmail.com wrote: In the recent thread, a couple people asked for the ability to create dynamic menu items per request from the database. David suggested Loc.supplimentalKidMenuItems which works fine for dynamic children of a static menu, but doesn't support the ability to make the top level menu dynamic. Menu has a method called makeMenuItem which gives a Box of MenuItem. What about a new method makeMenuItems that gives a possible plurality of MenuItems whose default implementation deferred to the existing makeMenuItem in the case where it's not overridden? I made this change to my local copy of lift and it seems to work alright. Example Menu: case class DynMenu() extends Menu(Loc(dynmenu, Link(List(dynmenu), true, /dynmenu), Dynamic Menu)) { override def makeMenuItems(path: List[Loc[_]]): Iterable[MenuItem] = DynMenuItem.findAll.map(dmi = { MenuItem(Text(dmi.label.is), Text(dmi.link.is), Nil, false, false, Nil) }) } That is, a Menu can generate 0 or more MenuItems when the menu is being generated. The disadvantage I see is similar to the one with supplimentalKidMenuItems -- that is, you have to manually compute the attributes of MenuItem such as current. However, it does give you the full power to make whatever kind of menu items you want. I looked briefly at seeing if it would be feasible to use a function Box[Req] = SiteMap on LiftRules, but I think the RewritePF auto detection thing in LiftRules.setSiteMap prevents this from being the right thing. The change to lift-webkit: diff --git a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala index d33d1dc..79194f5 100644 --- a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala +++ b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala @@ -61,8 +61,10 @@ case class Menu(loc: Loc[_], kids: Menu*) extends HasKids { } // def buildChildLine: List[MenuItem] = kids.toList.flatMap(m = m.loc.buildItem(Nil, false, false)) + def makeMenuItems(path: List[Loc[_]]): Iterable[MenuItem] = makeMenuItem(path) + def makeMenuItem(path: List[Loc[_]]): Box[MenuItem] = - loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath(path), _inPath(path)) +loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath(path), _inPath(path)) private def _inPath(in: List[Loc[_]]): Boolean = in match { case Nil = false diff --git a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala index 7939938..f8fa307 100644 --- a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala +++ b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala @@ -66,7 +66,7 @@ case class SiteMap(globalParamFuncs: List[PartialFunction[Box[Req], Loc.AnyLocPa case Full(loc) = loc.breadCrumbs case _ = Nil } -CompleteMenu(kids.flatMap(_.makeMenuItem(path))) +CompleteMenu(kids.flatMap(_.makeMenuItems(path))) } } Thoughts? -Ross -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
Re: [Lift] Re: Change to support dynamic top level menu items
On Mon, Nov 23, 2009 at 4:55 PM, Ross Mellgren dri...@gmail.com wrote: As much as I subscribe to the a lack of dissent is implicit assent policy, I'm hoping somebody deeply familiar with SiteMap can comment on whether this change seems like a bad idea? I guess if I don't hear anything I'll create an issue and submit the patch for review, but I'd feel better with a bit more discussion. Give me a few days to respond please. -Ross On Nov 22, 2009, at 9:28 PM, philip wrote: Essential for the CMS I am programming as the user needs to be able to define the menu structure. On 11月22日, 上午4時46分, Ross Mellgren dri...@gmail.com wrote: In the recent thread, a couple people asked for the ability to create dynamic menu items per request from the database. David suggested Loc.supplimentalKidMenuItems which works fine for dynamic children of a static menu, but doesn't support the ability to make the top level menu dynamic. Menu has a method called makeMenuItem which gives a Box of MenuItem. What about a new method makeMenuItems that gives a possible plurality of MenuItems whose default implementation deferred to the existing makeMenuItem in the case where it's not overridden? I made this change to my local copy of lift and it seems to work alright. Example Menu: case class DynMenu() extends Menu(Loc(dynmenu, Link(List(dynmenu), true, /dynmenu), Dynamic Menu)) { override def makeMenuItems(path: List[Loc[_]]): Iterable[MenuItem] = DynMenuItem.findAll.map(dmi = { MenuItem(Text(dmi.label.is), Text(dmi.link.is), Nil, false, false, Nil) }) } That is, a Menu can generate 0 or more MenuItems when the menu is being generated. The disadvantage I see is similar to the one with supplimentalKidMenuItems -- that is, you have to manually compute the attributes of MenuItem such as current. However, it does give you the full power to make whatever kind of menu items you want. I looked briefly at seeing if it would be feasible to use a function Box[Req] = SiteMap on LiftRules, but I think the RewritePF auto detection thing in LiftRules.setSiteMap prevents this from being the right thing. The change to lift-webkit: diff --git a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala index d33d1dc..79194f5 100644 --- a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala +++ b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala @@ -61,8 +61,10 @@ case class Menu(loc: Loc[_], kids: Menu*) extends HasKids { } // def buildChildLine: List[MenuItem] = kids.toList.flatMap(m = m.loc.buildItem(Nil, false, false)) + def makeMenuItems(path: List[Loc[_]]): Iterable[MenuItem] = makeMenuItem(path) + def makeMenuItem(path: List[Loc[_]]): Box[MenuItem] = - loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath(path), _inPath(path)) +loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath(path), _inPath(path)) private def _inPath(in: List[Loc[_]]): Boolean = in match { case Nil = false diff --git a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala index 7939938..f8fa307 100644 --- a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala +++ b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala @@ -66,7 +66,7 @@ case class SiteMap(globalParamFuncs: List[PartialFunction[Box[Req], Loc.AnyLocPa case Full(loc) = loc.breadCrumbs case _ = Nil } -CompleteMenu(kids.flatMap(_.makeMenuItem(path))) +CompleteMenu(kids.flatMap(_.makeMenuItems(path))) } } Thoughts? -Ross -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl=. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl=en. -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Surf the harmonics -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to
[Lift] Re: Change to support dynamic top level menu items
Essential for the CMS I am programming as the user needs to be able to define the menu structure. On 11月22日, 上午4時46分, Ross Mellgren dri...@gmail.com wrote: In the recent thread, a couple people asked for the ability to create dynamic menu items per request from the database. David suggested Loc.supplimentalKidMenuItems which works fine for dynamic children of a static menu, but doesn't support the ability to make the top level menu dynamic. Menu has a method called makeMenuItem which gives a Box of MenuItem. What about a new method makeMenuItems that gives a possible plurality of MenuItems whose default implementation deferred to the existing makeMenuItem in the case where it's not overridden? I made this change to my local copy of lift and it seems to work alright. Example Menu: case class DynMenu() extends Menu(Loc(dynmenu, Link(List(dynmenu), true, /dynmenu), Dynamic Menu)) { override def makeMenuItems(path: List[Loc[_]]): Iterable[MenuItem] = DynMenuItem.findAll.map(dmi = { MenuItem(Text(dmi.label.is), Text(dmi.link.is), Nil, false, false, Nil) }) } That is, a Menu can generate 0 or more MenuItems when the menu is being generated. The disadvantage I see is similar to the one with supplimentalKidMenuItems -- that is, you have to manually compute the attributes of MenuItem such as current. However, it does give you the full power to make whatever kind of menu items you want. I looked briefly at seeing if it would be feasible to use a function Box[Req] = SiteMap on LiftRules, but I think the RewritePF auto detection thing in LiftRules.setSiteMap prevents this from being the right thing. The change to lift-webkit: diff --git a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala index d33d1dc..79194f5 100644 --- a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala +++ b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala @@ -61,8 +61,10 @@ case class Menu(loc: Loc[_], kids: Menu*) extends HasKids { } // def buildChildLine: List[MenuItem] = kids.toList.flatMap(m = m.loc.buildItem(Nil, false, false)) + def makeMenuItems(path: List[Loc[_]]): Iterable[MenuItem] = makeMenuItem(path) + def makeMenuItem(path: List[Loc[_]]): Box[MenuItem] = - loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath(path), _inPath(path)) + loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath(path), _inPath(path)) private def _inPath(in: List[Loc[_]]): Boolean = in match { case Nil = false diff --git a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala index 7939938..f8fa307 100644 --- a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala +++ b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala @@ -66,7 +66,7 @@ case class SiteMap(globalParamFuncs: List[PartialFunction[Box[Req], Loc.AnyLocPa case Full(loc) = loc.breadCrumbs case _ = Nil } - CompleteMenu(kids.flatMap(_.makeMenuItem(path))) + CompleteMenu(kids.flatMap(_.makeMenuItems(path))) } } Thoughts? -Ross -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=.