From d45d7fdbff7b0adcda9ce1064745af69e8a66a5a Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 27 Mar 2019 20:29:08 +0100 Subject: [PATCH] Fix modals --- messages/uniworx/de.msg | 2 ++ src/Foundation.hs | 16 ++++++++-- src/Handler/Utils.hs | 3 +- src/Handler/Utils/Templates.hs | 30 ------------------ src/Import/NoFoundation.hs | 1 + src/Utils/Modal.hs | 42 ++++++++++++++++++++++++++ src/index.md | 2 +- templates/default-layout.lucius | 10 +++--- templates/widgets/modal/modal.hamlet | 3 +- templates/widgets/modal/modal.julius | 6 +--- templates/widgets/modal/trigger.hamlet | 7 +++++ templates/widgets/navbar/item.hamlet | 3 ++ templates/widgets/navbar/navbar.hamlet | 27 ++++++++--------- 13 files changed, 90 insertions(+), 62 deletions(-) delete mode 100644 src/Handler/Utils/Templates.hs create mode 100644 src/Utils/Modal.hs create mode 100644 templates/widgets/modal/trigger.hamlet create mode 100644 templates/widgets/navbar/item.hamlet diff --git a/messages/uniworx/de.msg b/messages/uniworx/de.msg index 1f343a7cb..463937f70 100644 --- a/messages/uniworx/de.msg +++ b/messages/uniworx/de.msg @@ -702,3 +702,5 @@ DBTIRowsMissing n@Int: #{pluralDE n "Eine Zeile ist" "Einige Zeile sind"} aus de MassInputAddDimension: Hinzufügen MassInputDeleteCell: Entfernen + +NavigationFavourites: Favoriten \ No newline at end of file diff --git a/src/Foundation.hs b/src/Foundation.hs index 2ddbc118b..6ca7c5128 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -62,7 +62,6 @@ import Control.Monad.Memo (MemoT, startEvalMemoT, MonadMemo(..)) import qualified Control.Monad.Catch as C import Handler.Utils.StudyFeatures -import Handler.Utils.Templates import Utils.Lens import Utils.Form import Utils.Sheet @@ -1007,8 +1006,8 @@ siteLayout' headingOverride widget = do let highlight :: Route UniWorX -> Bool -- highlight last route in breadcrumbs, favorites taking priority highlight = let crumbs = mcons mcurrentRoute $ fst <$> reverse parents - navItems = map snd3 favourites ++ map (urlRoute . menuItemRoute . view _1) menuTypes - highR = find (`elem` navItems) . uncurry (++) $ partition (`elem` map snd3 favourites) crumbs + navItems = map (view _2) favourites ++ map (urlRoute . menuItemRoute . view _1) menuTypes + highR = find (`elem` navItems) . uncurry (++) $ partition (`elem` map (view _2) favourites) crumbs in \r -> Just r == highR favouriteTerms :: [TermIdentifier] favouriteTerms = Set.toDescList $ foldMap (\(Course{..}, _, _) -> Set.singleton $ unTermKey courseTerm) favourites @@ -1021,6 +1020,17 @@ siteLayout' headingOverride widget = do -- value passed to hamletToRepHtml cannot be a widget, this allows -- you to use normal widget features in default-layout. + navbarModal (MenuItem{..}, menuIdent') = customModal Modal + { modalTriggerId = Just menuIdent' + , modalId = Nothing + , modalTrigger = \(Just route) menuIdent -> $(widgetFile "widgets/navbar/item") + , modalContent = Left menuItemRoute + } + + navbarItem (MenuItem{..}, menuIdent) = do + route <- toTextUrl menuItemRoute + $(widgetFile "widgets/navbar/item") + navbar :: Widget navbar = $(widgetFile "widgets/navbar/navbar") asidenav :: Widget diff --git a/src/Handler/Utils.hs b/src/Handler/Utils.hs index e232261fb..f795bb5eb 100644 --- a/src/Handler/Utils.hs +++ b/src/Handler/Utils.hs @@ -24,7 +24,6 @@ import Handler.Utils.Zip as Handler.Utils import Handler.Utils.Rating as Handler.Utils hiding (extractRatings) -- import Handler.Utils.Submission as Handler.Utils import Handler.Utils.Sheet as Handler.Utils -import Handler.Utils.Templates as Handler.Utils import Handler.Utils.Mail as Handler.Utils @@ -139,4 +138,4 @@ warnTermDays tid times = do i18nWidgetFile :: FilePath -> Q Exp i18nWidgetFile = -- TODO write code to distinguish languages here - widgetFile . ( "de") \ No newline at end of file + widgetFile . ( "de") diff --git a/src/Handler/Utils/Templates.hs b/src/Handler/Utils/Templates.hs deleted file mode 100644 index 44be14620..000000000 --- a/src/Handler/Utils/Templates.hs +++ /dev/null @@ -1,30 +0,0 @@ -module Handler.Utils.Templates where - -import Data.Either (isLeft) - -import Import.NoFoundation - - --- | Create a link to a modal -modal :: WidgetT site IO () -- ^ Widget that represents the link - -> Either (SomeRoute site) (WidgetT site IO ()) -- ^ Modal contant: either dynamic link or static widget - -> WidgetT site IO () -- ^ result widget -modal modalTrigger modalContent = do - let modalDynamic = isLeft modalContent - modalId <- newIdent - triggerId <- newIdent - $(widgetFile "widgets/modal/modal") - case modalContent of - Left route -> do - route' <- toTextUrl route - [whamlet| - $newline never - - ^{modalTrigger} - |] - Right _ -> - [whamlet| - $newline never -
- ^{modalTrigger} - |] diff --git a/src/Import/NoFoundation.hs b/src/Import/NoFoundation.hs index 39de96dd7..dd0861ab9 100644 --- a/src/Import/NoFoundation.hs +++ b/src/Import/NoFoundation.hs @@ -15,6 +15,7 @@ import Yesod.Auth as Import import Yesod.Core.Types as Import (loggerSet) import Yesod.Default.Config2 as Import import Utils as Import +import Utils.Modal as Import import Yesod.Core.Json as Import (provideJson) import Yesod.Core.Types.Instances as Import () diff --git a/src/Utils/Modal.hs b/src/Utils/Modal.hs new file mode 100644 index 000000000..5dd4ccd3e --- /dev/null +++ b/src/Utils/Modal.hs @@ -0,0 +1,42 @@ +module Utils.Modal + ( Modal(..) + , customModal + , modal + ) where + +import ClassyPrelude.Yesod + +import Control.Lens +import Control.Lens.Extras (is) +import Utils.Route + +import Settings (widgetFile) + + +data Modal site = Modal + { modalTriggerId + , modalId :: Maybe Text + , modalTrigger :: Maybe Text {- Dynamic URL -} -> Text {- TriggerId -} -> WidgetT site IO () + , modalContent :: Either (SomeRoute site) (WidgetT site IO ()) + } + +customModal :: Modal site -> WidgetT site IO () +customModal Modal{..} = do + let isDynamic = is _Left modalContent + modalId' <- maybe newIdent return modalId + triggerId' <- maybe newIdent return modalTriggerId + + $(widgetFile "widgets/modal/modal") + + route <- for (modalContent ^? _Left) toTextUrl + modalTrigger route triggerId' + +-- | Create a link to a modal +modal :: WidgetT site IO () -- ^ Widget that represents the link + -> Either (SomeRoute site) (WidgetT site IO ()) -- ^ Modal contant: either dynamic link or static widget + -> WidgetT site IO () -- ^ result widget +modal modalTrigger' modalContent = customModal Modal{..} + where + modalTriggerId = Nothing + modalId = Nothing + modalTrigger mRoute triggerId = $(widgetFile "widgets/modal/trigger") diff --git a/src/index.md b/src/index.md index 17798d0df..d90c78eb2 100644 --- a/src/index.md +++ b/src/index.md @@ -86,7 +86,7 @@ Handler.Utils.Table.Pagination.Types Handler.Utils.Table.Cells : extends dbTable with UniWorX specific functions, such as special courseCell -Handler.Utils.Templates +Utils.Modal : Modals Handler.Utils.Zip diff --git a/templates/default-layout.lucius b/templates/default-layout.lucius index 1824b6d93..60cf591d7 100644 --- a/templates/default-layout.lucius +++ b/templates/default-layout.lucius @@ -532,13 +532,13 @@ section { border-bottom: 1px solid #d3d3d3; + section { - margin-top: 20px; - padding-top: 20px; + margin-top: 20px; + padding-top: 20px; } +} - section { - border-bottom: none; - } +section:last-of-type { + border-bottom: none; } .pseudonym { diff --git a/templates/widgets/modal/modal.hamlet b/templates/widgets/modal/modal.hamlet index 767fde13b..6381305e7 100644 --- a/templates/widgets/modal/modal.hamlet +++ b/templates/widgets/modal/modal.hamlet @@ -1,4 +1,5 @@ -
+$newline never +
$case modalContent $of Right content
diff --git a/templates/widgets/modal/modal.julius b/templates/widgets/modal/modal.julius index c4db5c2ef..0910a34a4 100644 --- a/templates/widgets/modal/modal.julius +++ b/templates/widgets/modal/modal.julius @@ -1,9 +1,5 @@ document.addEventListener('DOMContentLoaded', function() { - var modalIdent = #{String modalId}; - var selector = '#modal-' + modalIdent; - var modal = document.querySelector(selector); - - if (modal) { + if (modal = document.querySelector('#modal-' + #{String modalId'})) { window.utils.setup('modal', modal); } }); diff --git a/templates/widgets/modal/trigger.hamlet b/templates/widgets/modal/trigger.hamlet new file mode 100644 index 000000000..7d92fcece --- /dev/null +++ b/templates/widgets/modal/trigger.hamlet @@ -0,0 +1,7 @@ +$newline never +$maybe route <- mRoute + + ^{modalTrigger'} +$nothing +
+ ^{modalTrigger'} diff --git a/templates/widgets/navbar/item.hamlet b/templates/widgets/navbar/item.hamlet new file mode 100644 index 000000000..470ea054f --- /dev/null +++ b/templates/widgets/navbar/item.hamlet @@ -0,0 +1,3 @@ + + +
_{SomeMessage menuItemLabel} diff --git a/templates/widgets/navbar/navbar.hamlet b/templates/widgets/navbar/navbar.hamlet index 8d687034a..966223643 100644 --- a/templates/widgets/navbar/navbar.hamlet +++ b/templates/widgets/navbar/navbar.hamlet @@ -8,34 +8,31 @@ $newline never
  • -
    Favorites +
    _{MsgNavigationFavourites} - $forall (MenuItem{menuItemType, menuItemRoute, menuItemIcon, menuItemLabel, menuItemModal}, menuIdent, route) <- menuTypes + $forall (menuItem@MenuItem{menuItemType, menuItemRoute, menuItemModal}, menuIdent, _) <- menuTypes $case menuItemType $of NavbarAside
  • $if menuItemModal -