[Lift] Re: Some questions about menu & MetaMegaProtoUser

2009-05-24 Thread Jeppe Nejsum Madsen

On Sun, May 24, 2009 at 12:45 AM, Jeppe Nejsum Madsen  wrote:
> On Sat, May 23, 2009 at 5:54 PM, Jeppe Nejsum Madsen  wrote:
>> On Sat, May 23, 2009 at 4:52 PM, David Pollak
>>  wrote:

 > Getting the secondary menu items:
 >   def secondaryMenuItems: Seq[MenuItem] =
 >   for {
 >     req <- S.request.toList
 >     line <- req.buildMenu.lines
 >     kid <- line.kids
 >   } yield kid

 While this does get all the current secondary menu items, I need all
 the current secondary menu items as well as their children (and their
 children) since I'll be handling the structure client side. I tried
 various combinations and hacking of the Menu snippet but can't seem to
 render all the children. Part of the problem is probably that I don't
 really know the Menu/MenuItem/Loc structure very well and the
 Scaladocs are.somewhat lacking :-)

 I'll keep trying to decipher the source to come up with something, but
 any further insights will be appreciated
>>>
>>> Each MenuItem has a kids property which is the submenus.  You can recurse
>>> into the kids on display.  The net.liftweb.http.snippet.Menu.scala code has
>>> examples of this.
>>
>> I'm on it already
>
> ..and seem stuck. I have the following menu structure
>
> M1
>  M1.1
>     M1.1.1
>     M1.1.2
>  M1.2
> M2
>  M2
>
> etc. I can't seem to get all the third level items (M1.1.1, M1.1.2)
> unless the active page is M1.1. Even if I put in  expandAll="true"/>, they're only shown if I select M1.1.
>
> The code above which yields kid, outputs M1.1 and M1.2 when M1 is
> selected. When looking at the data, at seems like the kid.kids for
> M1.1 is empty unless I'm on page M1.1.
>
> What am I missing?

Got some sleep and did a little more tinkering. The following seems to
give the expected results

 val theKids = for {
  req <- S.request.toList
  loc <- req.location.toList
  m <- loc.menu.kids.toList
  mi <- m.makeMenuItem(List(m.loc))
} yield mi

/Jeppe

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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
-~--~~~~--~~--~--~---



[Lift] Re: Some questions about menu & MetaMegaProtoUser

2009-05-23 Thread Jeppe Nejsum Madsen

On Sat, May 23, 2009 at 5:54 PM, Jeppe Nejsum Madsen  wrote:
> On Sat, May 23, 2009 at 4:52 PM, David Pollak
>  wrote:
>>>
>>> > Getting the secondary menu items:
>>> >   def secondaryMenuItems: Seq[MenuItem] =
>>> >   for {
>>> >     req <- S.request.toList
>>> >     line <- req.buildMenu.lines
>>> >     kid <- line.kids
>>> >   } yield kid
>>>
>>> While this does get all the current secondary menu items, I need all
>>> the current secondary menu items as well as their children (and their
>>> children) since I'll be handling the structure client side. I tried
>>> various combinations and hacking of the Menu snippet but can't seem to
>>> render all the children. Part of the problem is probably that I don't
>>> really know the Menu/MenuItem/Loc structure very well and the
>>> Scaladocs are.somewhat lacking :-)
>>>
>>> I'll keep trying to decipher the source to come up with something, but
>>> any further insights will be appreciated
>>
>> Each MenuItem has a kids property which is the submenus.  You can recurse
>> into the kids on display.  The net.liftweb.http.snippet.Menu.scala code has
>> examples of this.
>
> I'm on it already

..and seem stuck. I have the following menu structure

M1
  M1.1
 M1.1.1
 M1.1.2
  M1.2
M2
 M2

etc. I can't seem to get all the third level items (M1.1.1, M1.1.2)
unless the active page is M1.1. Even if I put in , they're only shown if I select M1.1.

The code above which yields kid, outputs M1.1 and M1.2 when M1 is
selected. When looking at the data, at seems like the kid.kids for
M1.1 is empty unless I'm on page M1.1.

What am I missing?

/Jeppe

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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
-~--~~~~--~~--~--~---



[Lift] Re: Some questions about menu & MetaMegaProtoUser

2009-05-23 Thread Jeppe Nejsum Madsen

On Sat, May 23, 2009 at 4:52 PM, David Pollak
 wrote:

[...]

>> > def onLoginPage: Boolean = S.request.flatMap(_.location.map(_.name ==
>> > "Login)) openOr false
>> >
>> > override def screenWrap: Box[NodeSeq] = Full(if (onLoginPage)
>> >     > > />
>> >         else > > />)
>>
>> Ahh didn't realize screenWrap was dynamically evaluated. Nice.
>>
>> Being new to Scala I spent some time trying to decode:
>>
>> def onLoginPage = S.request.flatMap(_.location.map(_.name == "Login"))
>> openOr false
>
> If you were writing code with a high McCabe number it would look like:
>
> def onLoginPage = {
>   val boolBox: Box[Boolean] = if (S.request.isDefined) {
>     val req = S.request.open_! // note never use open_! unless you know the
> Box is Full
>     if (req.location.isDefined) {
>   val loc = req.location.open_!
>   Full(loc.name == "Login")
>     } else Empty
>   } else Empty
>
>   if (boolBox.isDefined) boolBox.open_! else false
> }


Yeah. Definitely prefers the first option :-) I'm used to working with
map/flatMap on collections so using them to open boxes is a new idiom
I need to learn

>> Am I correct in that it basically evaluates S.request.location.name ==
>> "Login" with proper handling of Empty/Full boxes?
>> If yes, is there a good rule of thumb when to use flatMap/map or do I
>> just need more Scala time before this becomes natural?
>
> When you are dealing with Box/Option, its good to either use map/flatMap or
> the for comprehension (which is syntactic sugar for map/flatMap)
>
>>
>> > Getting the secondary menu items:
>> >   def secondaryMenuItems: Seq[MenuItem] =
>> >   for {
>> >     req <- S.request.toList
>> >     line <- req.buildMenu.lines
>> >     kid <- line.kids
>> >   } yield kid
>>
>> While this does get all the current secondary menu items, I need all
>> the current secondary menu items as well as their children (and their
>> children) since I'll be handling the structure client side. I tried
>> various combinations and hacking of the Menu snippet but can't seem to
>> render all the children. Part of the problem is probably that I don't
>> really know the Menu/MenuItem/Loc structure very well and the
>> Scaladocs are.somewhat lacking :-)
>>
>> I'll keep trying to decipher the source to come up with something, but
>> any further insights will be appreciated
>
> Each MenuItem has a kids property which is the submenus.  You can recurse
> into the kids on display.  The net.liftweb.http.snippet.Menu.scala code has
> examples of this.

I'm on it already

/Jeppe

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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
-~--~~~~--~~--~--~---



[Lift] Re: Some questions about menu & MetaMegaProtoUser

2009-05-23 Thread David Pollak
On Sat, May 23, 2009 at 4:20 AM, Jeppe Nejsum Madsen wrote:

>
> Thanks for the rapid feedback. A few comments below
>
> On Fri, May 22, 2009 at 6:12 PM, David Pollak
>  wrote:
>
> [...]
>
> > def onLoginPage: Boolean = S.request.flatMap(_.location.map(_.name ==
> > "Login)) openOr false
> >
> > override def screenWrap: Box[NodeSeq] = Full(if (onLoginPage)
> >  > />
> > else  > />)
>
> Ahh didn't realize screenWrap was dynamically evaluated. Nice.
>
> Being new to Scala I spent some time trying to decode:
>
> def onLoginPage = S.request.flatMap(_.location.map(_.name == "Login"))
> openOr false


If you were writing code with a high McCabe number it would look like:

def onLoginPage = {
  val boolBox: Box[Boolean] = if (S.request.isDefined) {
val req = S.request.open_! // note never use open_! unless you know the
Box is Full
if (req.location.isDefined) {
  val loc = req.location.open_!
  Full(loc.name == "Login")
} else Empty
  } else Empty

  if (boolBox.isDefined) boolBox.open_! else false
}


You can also write the code in a for comprehension:

def onLoginPage = {
  val bb =
for {
  req <- S.request
  loc <- req.location
} yield loc.name == "Login"

  bb openOr false
}



>
> Am I correct in that it basically evaluates S.request.location.name ==
> "Login" with proper handling of Empty/Full boxes?
> If yes, is there a good rule of thumb when to use flatMap/map or do I
> just need more Scala time before this becomes natural?


When you are dealing with Box/Option, its good to either use map/flatMap or
the for comprehension (which is syntactic sugar for map/flatMap)


>
>
> > Getting the secondary menu items:
> >   def secondaryMenuItems: Seq[MenuItem] =
> >   for {
> > req <- S.request.toList
> > line <- req.buildMenu.lines
> > kid <- line.kids
> >   } yield kid
>
> While this does get all the current secondary menu items, I need all
> the current secondary menu items as well as their children (and their
> children) since I'll be handling the structure client side. I tried
> various combinations and hacking of the Menu snippet but can't seem to
> render all the children. Part of the problem is probably that I don't
> really know the Menu/MenuItem/Loc structure very well and the
> Scaladocs are.somewhat lacking :-)
>
> I'll keep trying to decipher the source to come up with something, but
> any further insights will be appreciated


Each MenuItem has a kids property which is the submenus.  You can recurse
into the kids on display.  The net.liftweb.http.snippet.Menu.scala code has
examples of this.

Thanks,

David


>
>
> /Jeppe
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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
-~--~~~~--~~--~--~---



[Lift] Re: Some questions about menu & MetaMegaProtoUser

2009-05-23 Thread Jeppe Nejsum Madsen

Thanks for the rapid feedback. A few comments below

On Fri, May 22, 2009 at 6:12 PM, David Pollak
 wrote:

[...]

> def onLoginPage: Boolean = S.request.flatMap(_.location.map(_.name ==
> "Login)) openOr false
>
> override def screenWrap: Box[NodeSeq] = Full(if (onLoginPage)
>      />
>         else  />)

Ahh didn't realize screenWrap was dynamically evaluated. Nice.

Being new to Scala I spent some time trying to decode:

def onLoginPage = S.request.flatMap(_.location.map(_.name == "Login"))
openOr false

Am I correct in that it basically evaluates S.request.location.name ==
"Login" with proper handling of Empty/Full boxes?
If yes, is there a good rule of thumb when to use flatMap/map or do I
just need more Scala time before this becomes natural?

>> 2) I would like to have a primary navigation menu at the top, and each
>> primary menu item should have some secondary and tertiary menu items
>> shown at the left. Only the secondary/tertiary items for the currently
>> selected primary menu item should be visible. I believe I can render
>> the primary menu items using a LocGroup, but how do I render the
>> current subitems on the left sidebar?
>
> Getting the top level menu items:
>
> def topMenuItems: List[MenuItem] =
> S.request.toList.flatMap(_.buildMenu.lines)

Works like a charm.

> Getting the secondary menu items:
>   def secondaryMenuItems: Seq[MenuItem] =
>   for {
>     req <- S.request.toList
>     line <- req.buildMenu.lines
>     kid <- line.kids
>   } yield kid

While this does get all the current secondary menu items, I need all
the current secondary menu items as well as their children (and their
children) since I'll be handling the structure client side. I tried
various combinations and hacking of the Menu snippet but can't seem to
render all the children. Part of the problem is probably that I don't
really know the Menu/MenuItem/Loc structure very well and the
Scaladocs are.somewhat lacking :-)

I'll keep trying to decipher the source to come up with something, but
any further insights will be appreciated

/Jeppe

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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
-~--~~~~--~~--~--~---



[Lift] Re: Some questions about menu & MetaMegaProtoUser

2009-05-22 Thread David Pollak
On Fri, May 22, 2009 at 7:49 AM, Jeppe Nejsum Madsen wrote:

>
> Hi,
>
> A newbie running 1-1-SNAPSHOT with a few questions:
>
> 1) The entire app should be protected, so any unauthenticated access
> should show the login page. But I don't want the login page to use the
> same template as the other user pages. I guess I could override
> loginMenuLoc, but it would be nice if screenWrap could somehow be
> specified by Loc. Is this possible?


Sure...

def onLoginPage: Boolean = S.request.flatMap(_.location.map(_.name ==
"Login)) openOr false

override def screenWrap: Box[NodeSeq] = Full(if (onLoginPage)

else )


>
>
> 2) I would like to have a primary navigation menu at the top, and each
> primary menu item should have some secondary and tertiary menu items
> shown at the left. Only the secondary/tertiary items for the currently
> selected primary menu item should be visible. I believe I can render
> the primary menu items using a LocGroup, but how do I render the
> current subitems on the left sidebar?


Getting the top level menu items:

def topMenuItems: List[MenuItem] =
S.request.toList.flatMap(_.buildMenu.lines)

Getting the secondary menu items:
  def secondaryMenuItems: Seq[MenuItem] =
  for {
req <- S.request.toList
line <- req.buildMenu.lines
kid <- line.kids
  } yield kid


>
>
> /Jeppe
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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
-~--~~~~--~~--~--~---



[Lift] Re: Some questions about menu & MetaMegaProtoUser

2009-05-22 Thread Charles F. Munat

Jeppe Nejsum Madsen wrote:
> 1) The entire app should be protected, so any unauthenticated access
> should show the login page. But I don't want the login page to use the
> same template as the other user pages. I guess I could override
> loginMenuLoc, but it would be nice if screenWrap could somehow be
> specified by Loc. Is this possible?

I never use the built-in User (or Mapper), but this is easy to do if 
you're rolling your own. Just create a login page without the 
surrounding template (make it a full page) and point to it.

> 2) I would like to have a primary navigation menu at the top, and each
> primary menu item should have some secondary and tertiary menu items
> shown at the left. Only the secondary/tertiary items for the currently
> selected primary menu item should be visible. I believe I can render
> the primary menu items using a LocGroup, but how do I render the
> current subitems on the left sidebar?

IIRC, the builder does this. I think you can add Hidden to any location 
you don't want to show in the menu. The output is just the top 
navigation plus any subnavigation for the current page. You don't need 
the LocGroup for this.

I'm sure others who are more current on this will chip in.

Chas.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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
-~--~~~~--~~--~--~---