Cleanup
This commit is contained in:
parent
0c9533ccd1
commit
c09b0d8619
@ -61,16 +61,6 @@ data UniWorX = UniWorX
|
|||||||
, appCryptoIDKey :: CryptoIDKey
|
, appCryptoIDKey :: CryptoIDKey
|
||||||
}
|
}
|
||||||
|
|
||||||
data MenuItem = MenuItem
|
|
||||||
{ menuItemLabel :: Text
|
|
||||||
, menuItemRoute :: Route UniWorX
|
|
||||||
, menuItemAccessCallback :: Bool
|
|
||||||
}
|
|
||||||
|
|
||||||
data MenuTypes
|
|
||||||
= NavbarLeft MenuItem
|
|
||||||
| NavbarRight MenuItem
|
|
||||||
|
|
||||||
-- This is where we define all of the routes in our application. For a full
|
-- This is where we define all of the routes in our application. For a full
|
||||||
-- explanation of the syntax, please see:
|
-- explanation of the syntax, please see:
|
||||||
-- http://www.yesodweb.com/book/routing-and-handlers
|
-- http://www.yesodweb.com/book/routing-and-handlers
|
||||||
@ -85,6 +75,17 @@ data MenuTypes
|
|||||||
-- type Widget = WidgetT UniWorX IO ()
|
-- type Widget = WidgetT UniWorX IO ()
|
||||||
mkYesodData "UniWorX" $(parseRoutesFile "routes")
|
mkYesodData "UniWorX" $(parseRoutesFile "routes")
|
||||||
|
|
||||||
|
data MenuItem = MenuItem
|
||||||
|
{ menuItemLabel :: Text
|
||||||
|
, menuItemRoute :: Route UniWorX
|
||||||
|
, menuItemAccessCallback :: Handler Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
data MenuTypes
|
||||||
|
= NavbarLeft { menuItem :: MenuItem }
|
||||||
|
| NavbarRight { menuItem :: MenuItem }
|
||||||
|
| NavbarExtra { menuItem :: MenuItem }
|
||||||
|
|
||||||
-- | A convenient synonym for creating forms.
|
-- | A convenient synonym for creating forms.
|
||||||
type Form x = Html -> MForm (HandlerT UniWorX IO) (FormResult x, Widget)
|
type Form x = Html -> MForm (HandlerT UniWorX IO) (FormResult x, Widget)
|
||||||
|
|
||||||
@ -113,7 +114,7 @@ instance Yesod UniWorX where
|
|||||||
-- For details, see the CSRF documentation in the Yesod.Core.Handler module of the yesod-core package.
|
-- For details, see the CSRF documentation in the Yesod.Core.Handler module of the yesod-core package.
|
||||||
yesodMiddleware = defaultYesodMiddleware
|
yesodMiddleware = defaultYesodMiddleware
|
||||||
|
|
||||||
defaultLayout = defaultMenuLayout defaultLinks
|
defaultLayout = defaultLinkLayout []
|
||||||
|
|
||||||
-- The page to be redirected to when authentication is required.
|
-- The page to be redirected to when authentication is required.
|
||||||
authRoute _ = Just $ AuthR LoginR
|
authRoute _ = Just $ AuthR LoginR
|
||||||
@ -206,57 +207,49 @@ instance YesodBreadcrumbs UniWorX where
|
|||||||
breadcrumb _ = return ("home", Nothing)
|
breadcrumb _ = return ("home", Nothing)
|
||||||
|
|
||||||
|
|
||||||
defaultLinks :: Maybe (UserId, User) -> [MenuTypes]
|
defaultLinks :: [MenuTypes]
|
||||||
defaultLinks muser = -- Define the menu items of the header.
|
defaultLinks = -- Define the menu items of the header.
|
||||||
[ NavbarLeft $ MenuItem
|
[ NavbarLeft $ MenuItem
|
||||||
{ menuItemLabel = "Home"
|
{ menuItemLabel = "Home"
|
||||||
, menuItemRoute = HomeR
|
, menuItemRoute = HomeR
|
||||||
, menuItemAccessCallback = True
|
, menuItemAccessCallback = return True
|
||||||
}
|
}
|
||||||
, NavbarLeft $ MenuItem
|
, NavbarLeft $ MenuItem
|
||||||
{ menuItemLabel = "Kurse"
|
{ menuItemLabel = "Kurse"
|
||||||
, menuItemRoute = CourseListR
|
, menuItemRoute = CourseListR
|
||||||
, menuItemAccessCallback = True
|
, menuItemAccessCallback = return True
|
||||||
}
|
}
|
||||||
, NavbarRight $ MenuItem
|
, NavbarRight $ MenuItem
|
||||||
{ menuItemLabel = "Profile"
|
{ menuItemLabel = "Profile"
|
||||||
, menuItemRoute = ProfileR
|
, menuItemRoute = ProfileR
|
||||||
, menuItemAccessCallback = isJust muser
|
, menuItemAccessCallback = isJust <$> maybeAuthPair
|
||||||
}
|
}
|
||||||
, NavbarRight $ MenuItem
|
, NavbarRight $ MenuItem
|
||||||
{ menuItemLabel = "Login"
|
{ menuItemLabel = "Login"
|
||||||
, menuItemRoute = AuthR LoginR
|
, menuItemRoute = AuthR LoginR
|
||||||
, menuItemAccessCallback = isNothing muser
|
, menuItemAccessCallback = isNothing <$> maybeAuthPair
|
||||||
}
|
}
|
||||||
, NavbarRight $ MenuItem
|
, NavbarRight $ MenuItem
|
||||||
{ menuItemLabel = "Logout"
|
{ menuItemLabel = "Logout"
|
||||||
, menuItemRoute = AuthR LogoutR
|
, menuItemRoute = AuthR LogoutR
|
||||||
, menuItemAccessCallback = isJust muser
|
, menuItemAccessCallback = isJust <$> maybeAuthPair
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
defaultLinkLayout :: (Maybe (UserId, User) -> [MenuTypes]) -> Widget -> Handler Html
|
defaultLinkLayout :: [MenuTypes] -> Widget -> Handler Html
|
||||||
defaultLinkLayout menu = defaultMenuLayout defaultsPlusMenu
|
defaultLinkLayout = defaultMenuLayout . (defaultLinks ++)
|
||||||
where
|
|
||||||
defaultsPlusMenu = (++) <$> defaultLinks <*> menu
|
|
||||||
|
|
||||||
defaultMenuLayout :: (Maybe (UserId, User) -> [MenuTypes])
|
defaultMenuLayout :: [MenuTypes] -> Widget -> Handler Html
|
||||||
-> Widget -> Handler Html
|
|
||||||
defaultMenuLayout menu widget = do
|
defaultMenuLayout menu widget = do
|
||||||
master <- getYesod
|
master <- getYesod
|
||||||
mmsgs <- getMessages
|
mmsgs <- getMessages
|
||||||
|
|
||||||
muser <- maybeAuthPair
|
|
||||||
mcurrentRoute <- getCurrentRoute
|
mcurrentRoute <- getCurrentRoute
|
||||||
|
|
||||||
-- Get the breadcrumbs, as defined in the YesodBreadcrumbs instance.
|
-- Get the breadcrumbs, as defined in the YesodBreadcrumbs instance.
|
||||||
(title, parents) <- breadcrumbs
|
(title, parents) <- breadcrumbs
|
||||||
|
|
||||||
let menuItems = menu muser
|
menuTypes <- filterM (menuItemAccessCallback . menuItem) menu
|
||||||
let navbarLeftMenuItems = [x | NavbarLeft x <- menuItems]
|
|
||||||
let navbarRightMenuItems = [x | NavbarRight x <- menuItems]
|
|
||||||
let navbarLeftFilteredMenuItems = [x | x <- navbarLeftMenuItems , menuItemAccessCallback x]
|
|
||||||
let navbarRightFilteredMenuItems = [x | x <- navbarRightMenuItems, menuItemAccessCallback x]
|
|
||||||
|
|
||||||
-- We break up the default layout into two components:
|
-- We break up the default layout into two components:
|
||||||
-- default-layout is the contents of the body tag, and
|
-- default-layout is the contents of the body tag, and
|
||||||
|
|||||||
@ -60,12 +60,11 @@ getCourseListTermR tidini = do
|
|||||||
|]
|
|]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
allowedNew <- isAuthorized CourseEditR False
|
let pageLinks =
|
||||||
let pageLinks muser =
|
|
||||||
[ NavbarLeft $ MenuItem
|
[ NavbarLeft $ MenuItem
|
||||||
{ menuItemLabel = "Neuer Kurs"
|
{ menuItemLabel = "Neuer Kurs"
|
||||||
, menuItemRoute = CourseEditR
|
, menuItemRoute = CourseEditR
|
||||||
, menuItemAccessCallback = Authorized == allowedNew
|
, menuItemAccessCallback = (== Authorized) <$> isAuthorized CourseEditR False
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
defaultLinkLayout pageLinks $ do
|
defaultLinkLayout pageLinks $ do
|
||||||
|
|||||||
@ -8,8 +8,6 @@ module Handler.Utils.StudyFeatures
|
|||||||
|
|
||||||
import Import.NoFoundation hiding (try, (<|>))
|
import Import.NoFoundation hiding (try, (<|>))
|
||||||
|
|
||||||
import Data.Bifunctor
|
|
||||||
|
|
||||||
import Text.Parsec
|
import Text.Parsec
|
||||||
import Text.Parsec.Text
|
import Text.Parsec.Text
|
||||||
|
|
||||||
|
|||||||
@ -11,14 +11,23 @@
|
|||||||
|
|
||||||
<div #navbar .collapse.navbar-collapse>
|
<div #navbar .collapse.navbar-collapse>
|
||||||
<ul .nav.navbar-nav>
|
<ul .nav.navbar-nav>
|
||||||
$forall MenuItem label route _ <- navbarLeftFilteredMenuItems
|
$forall menuType <- menuTypes
|
||||||
<li :Just route == mcurrentRoute:.active>
|
$case menuType
|
||||||
<a href="@{route}">#{label}
|
$of NavbarLeft (MenuItem label route _)
|
||||||
|
<li :Just route == mcurrentRoute:.active>
|
||||||
|
<a href=@{route}>#{label}
|
||||||
|
$of NavbarExtra (MenuItem label route _)
|
||||||
|
<li :Just route == mcurrentRoute:.active>
|
||||||
|
<a href=@{route}>#{label}
|
||||||
|
$of _
|
||||||
|
|
||||||
<ul .nav.navbar-nav.navbar-right>
|
<ul .nav.navbar-nav.navbar-right>
|
||||||
$forall MenuItem label route _ <- navbarRightFilteredMenuItems
|
$forall menuType <- menuTypes
|
||||||
<li :Just route == mcurrentRoute:.active>
|
$case menuType
|
||||||
<a href="@{route}">#{label}
|
$of NavbarRight (MenuItem label route _)
|
||||||
|
<li :Just route == mcurrentRoute:.active>
|
||||||
|
<a href=@{route}>#{label}
|
||||||
|
$of _
|
||||||
|
|
||||||
<!-- Page Contents -->
|
<!-- Page Contents -->
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user