diff --git a/src/Foundation.hs b/src/Foundation.hs index 94287ba49..aa1c0657d 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -253,6 +253,11 @@ uniworxMessages = UniWorXMessages . map SomeMessage data MenuType = NavbarAside | NavbarRight | NavbarSecondary | PageActionPrime | PageActionSecondary | Footer deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) +instance Universe MenuType +instance Finite MenuType + +makePrisms ''MenuType + data MenuItem = MenuItem { menuItemLabel :: UniWorXMessage , menuItemIcon :: Maybe Text -- currently from: https://fontawesome.com/icons?d=gallery @@ -262,6 +267,8 @@ data MenuItem = MenuItem , menuItemType :: MenuType } +makeLenses_ ''MenuItem + instance RedirectUrl UniWorX MenuItem where toTextUrl MenuItem{..} = toTextUrl menuItemRoute instance HasRoute UniWorX MenuItem where @@ -932,15 +939,13 @@ siteLayout headingOverride widget = do contentHeadline = (toWidget <$> headingOverride) <|> (pageHeading =<< mcurrentRoute) breadcrumbsWgt :: Widget breadcrumbsWgt = $(widgetFile "widgets/breadcrumbs") - pageactionprime :: Widget - pageactionprime = $(widgetFile "widgets/pageactionprime") -- TODO: rename, since it also shows secondary pageActions now + pageaction :: Widget + pageaction = $(widgetFile "widgets/pageaction") -- functions to determine if there are page-actions (primary or secondary) - isPageAction :: MenuType -> Bool - isPageAction PageActionPrime = True - isPageAction PageActionSecondary = True - isPageAction _ = False - hasPageActions :: Bool - hasPageActions = any (isPageAction . menuItemType . view _1) menuTypes + hasPageActions, hasSecondaryPageActions, hasPrimaryPageActions :: Bool + hasPageActions = hasPrimaryPageActions || hasSecondaryPageActions + hasSecondaryPageActions = any (is _PageActionSecondary) $ toListOf (traverse . _1 . _menuItemType) menuTypes + hasPrimaryPageActions = any (is _PageActionPrime) $ toListOf (traverse . _1 . _menuItemType) menuTypes pc <- widgetToPageContent $ do addStylesheetRemote "https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,800,900|Roboto:300,400,600" diff --git a/templates/default-layout.hamlet b/templates/default-layout.hamlet index deed85785..bf936affd 100644 --- a/templates/default-layout.hamlet +++ b/templates/default-layout.hamlet @@ -22,9 +22,9 @@ $if not isModal #{snd back} --> ^{headline} - $if not isModal - - ^{pageactionprime} + $if not isModal && hasPageActions + + ^{pageaction} ^{widget} diff --git a/templates/widgets/pageactionprime.hamlet b/templates/widgets/pageaction.hamlet similarity index 91% rename from templates/widgets/pageactionprime.hamlet rename to templates/widgets/pageaction.hamlet index dc826db15..b7dcfc86e 100644 --- a/templates/widgets/pageactionprime.hamlet +++ b/templates/widgets/pageaction.hamlet @@ -1,6 +1,6 @@ $newline never -$if hasPageActions -
+
+ $if hasPrimaryPageActions
$forall (MenuItem{menuItemLabel, menuItemType, menuItemModal}, menuIdent, route) <- menuTypes $case menuItemType @@ -10,7 +10,7 @@ $if hasPageActions
_{SomeMessage menuItemLabel} $of _ - + $if hasSecondaryPageActions
$forall (MenuItem{menuItemLabel, menuItemType, menuItemModal}, menuIdent, route) <- menuTypes diff --git a/templates/widgets/pageactionprime.julius b/templates/widgets/pageaction.julius similarity index 100% rename from templates/widgets/pageactionprime.julius rename to templates/widgets/pageaction.julius diff --git a/templates/widgets/pageactionprime.lucius b/templates/widgets/pageaction.lucius similarity index 100% rename from templates/widgets/pageactionprime.lucius rename to templates/widgets/pageaction.lucius