[working on simplifying menu logic
thomashartman1@gmail.com**20080906084258] hunk ./src/Controller.hs 90
-loginPage (UserAuthInfo user pass) = [ ServerPartT $ \rq -> do
- allowed <- query $ AuthUser user pass
- if allowed
- then do key <- update $ NewSession (SessionData user)
- addCookie (3600) (mkCookie "sid" (show key))
- tutlayoutWeb [] "home" Nothing
- else tutlayoutWeb [] "badlogin" Nothing ]
+loginPage (UserAuthInfo user pass) = [
+ ServerPartT $ \rq -> do
+ allowed <- query $ AuthUser user pass
+ if allowed
+ then do res <- do key <- update $ NewSession (SessionData user)
+ addCookie (3600) (mkCookie "sid" (show key))
+ tutlayoutWeb [] "home" Nothing
+ seeOther "/" res
+ else tutlayoutWeb [] "badlogin" Nothing
+
+ ]
hunk ./src/Controller.hs 102
+-- redirectHome =
+
hunk ./src/View.hs 22
- let menuAttrs = getMenuAttrs contentTmpl
+ let kvMenustyleActivelink = getMenuCssStyles contentTmpl
hunk ./src/View.hs 27
- renderTemplateDir "templates" (menuAttrs ++ [("userMenu",userMenu)] ) "header"
+ renderTemplateDir "templates" (kvMenustyleActivelink ++ [("userMenu",userMenu)] ) "header"
hunk ./src/View.hs 31
-getMenuAttrs :: String -> [(String,String)]
-getMenuAttrs tmpl = ( M.toList . snd . M.updateLookupWithKey f menukey . M.fromList ) templateAttributes
- where f k v | k == menukey = Just "menuitemselected"
- | otherwise = Just v
- templateAttributes = [("menuHomeSelected","menuitem")
- , ("menuViewAllUsersSelected","menuitem")
+getMenuCssStyles :: String -> [(String,String)]
+getMenuCssStyles tmpl =
+ maybe
+ defaultMenuActivelinks
+ tweakCssStyles
+ mbMenuControlVar
+ where mbMenuControlVar = lookup tmpl kvTmplMenucontrol
+ tweakCssStyles menuControlVar = map highlightselected defaultMenuActivelinks
+ where highlightselected (mv,style) | mv == menuControlVar = (mv,"menuItemSelected")
+ highlightselected a | otherwise = a
+
+-- style "menuItemSelected" makes a colored link
+-- "menuItem" is default
+-- default for menu control is no menu item is highlighted
+defaultMenuActivelinks = zip ["menustyleHome", "menustyleViewAllUsers"]
+ $ repeat "menuitem"
+
+-- this should just be one data structure, otherwise we're repeating the variable
+-- Some templates trigger a menu link color change
+-- Some templates have no effect
+-- This controls the behavior
+kvTmplMenucontrol = [ ("home","menustyleHome")
+ , ("view-all-users","menustyleViewAllUsers")
+ {-, ("login","menuLoginSelected")
+ -} ]
hunk ./src/View.hs 57
- {-, ("menuLoggedInAsSelected","menuitem")
- , ("menuLoginSelected","menuitem")-} ]
-
- menukey = maybe ("error, bad tmpl: " ++ tmpl) id ( lookup tmpl menuValsTable )
- menuValsTable = [("home","menuHomeSelected")
- , ("view-all-users","menuViewAllUsersSelected")
- {-, ("login","menuLoginSelected")
- -} ]
hunk ./templates/menuNotLoggedIn.st 1
-
- |
- |logged in as Orig
+
+ |
hunk ./templates/menubar.st 7
-
- |
+
+ |