Add check to only show secondary pageactions when needed

Rename pageactionprime.* -> pageaction.*
This commit is contained in:
Gregor Kleen 2019-01-28 13:26:46 +01:00
parent 4e17a36933
commit 8ee3d723c7
5 changed files with 19 additions and 14 deletions

View File

@ -253,6 +253,11 @@ uniworxMessages = UniWorXMessages . map SomeMessage
data MenuType = NavbarAside | NavbarRight | NavbarSecondary | PageActionPrime | PageActionSecondary | Footer data MenuType = NavbarAside | NavbarRight | NavbarSecondary | PageActionPrime | PageActionSecondary | Footer
deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic)
instance Universe MenuType
instance Finite MenuType
makePrisms ''MenuType
data MenuItem = MenuItem data MenuItem = MenuItem
{ menuItemLabel :: UniWorXMessage { menuItemLabel :: UniWorXMessage
, menuItemIcon :: Maybe Text -- currently from: https://fontawesome.com/icons?d=gallery , menuItemIcon :: Maybe Text -- currently from: https://fontawesome.com/icons?d=gallery
@ -262,6 +267,8 @@ data MenuItem = MenuItem
, menuItemType :: MenuType , menuItemType :: MenuType
} }
makeLenses_ ''MenuItem
instance RedirectUrl UniWorX MenuItem where instance RedirectUrl UniWorX MenuItem where
toTextUrl MenuItem{..} = toTextUrl menuItemRoute toTextUrl MenuItem{..} = toTextUrl menuItemRoute
instance HasRoute UniWorX MenuItem where instance HasRoute UniWorX MenuItem where
@ -932,15 +939,13 @@ siteLayout headingOverride widget = do
contentHeadline = (toWidget <$> headingOverride) <|> (pageHeading =<< mcurrentRoute) contentHeadline = (toWidget <$> headingOverride) <|> (pageHeading =<< mcurrentRoute)
breadcrumbsWgt :: Widget breadcrumbsWgt :: Widget
breadcrumbsWgt = $(widgetFile "widgets/breadcrumbs") breadcrumbsWgt = $(widgetFile "widgets/breadcrumbs")
pageactionprime :: Widget pageaction :: Widget
pageactionprime = $(widgetFile "widgets/pageactionprime") -- TODO: rename, since it also shows secondary pageActions now pageaction = $(widgetFile "widgets/pageaction")
-- functions to determine if there are page-actions (primary or secondary) -- functions to determine if there are page-actions (primary or secondary)
isPageAction :: MenuType -> Bool hasPageActions, hasSecondaryPageActions, hasPrimaryPageActions :: Bool
isPageAction PageActionPrime = True hasPageActions = hasPrimaryPageActions || hasSecondaryPageActions
isPageAction PageActionSecondary = True hasSecondaryPageActions = any (is _PageActionSecondary) $ toListOf (traverse . _1 . _menuItemType) menuTypes
isPageAction _ = False hasPrimaryPageActions = any (is _PageActionPrime) $ toListOf (traverse . _1 . _menuItemType) menuTypes
hasPageActions :: Bool
hasPageActions = any (isPageAction . menuItemType . view _1) menuTypes
pc <- widgetToPageContent $ do pc <- widgetToPageContent $ do
addStylesheetRemote "https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,800,900|Roboto:300,400,600" addStylesheetRemote "https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,800,900|Roboto:300,400,600"

View File

@ -22,9 +22,9 @@ $if not isModal
<a .breadcrumbs__link href="@{fst back}">#{snd back} --> <a .breadcrumbs__link href="@{fst back}">#{snd back} -->
^{headline} ^{headline}
$if not isModal $if not isModal && hasPageActions
<!-- prime page actions --> <!-- page actions -->
^{pageactionprime} ^{pageaction}
<!-- actual content --> <!-- actual content -->
^{widget} ^{widget}

View File

@ -1,6 +1,6 @@
$newline never $newline never
$if hasPageActions <div .pagenav>
<div .pagenav> $if hasPrimaryPageActions
<div .pagenav-prime> <div .pagenav-prime>
$forall (MenuItem{menuItemLabel, menuItemType, menuItemModal}, menuIdent, route) <- menuTypes $forall (MenuItem{menuItemLabel, menuItemType, menuItemModal}, menuIdent, route) <- menuTypes
$case menuItemType $case menuItemType
@ -10,7 +10,7 @@ $if hasPageActions
<div .modal.js-modal #modal-#{menuIdent} data-trigger=#{menuIdent} data-closeable data-dynamic> <div .modal.js-modal #modal-#{menuIdent} data-trigger=#{menuIdent} data-closeable data-dynamic>
<a .pagenav__link-wrapper href=#{route} ##{menuIdent}>_{SomeMessage menuItemLabel} <a .pagenav__link-wrapper href=#{route} ##{menuIdent}>_{SomeMessage menuItemLabel}
$of _ $of _
<!-- TODO: add check if there are any PageActionSecondarys --> $if hasSecondaryPageActions
<div .pagenav-secondary> <div .pagenav-secondary>
<div .pagenav-secondary__list> <div .pagenav-secondary__list>
$forall (MenuItem{menuItemLabel, menuItemType, menuItemModal}, menuIdent, route) <- menuTypes $forall (MenuItem{menuItemLabel, menuItemType, menuItemModal}, menuIdent, route) <- menuTypes