76 lines
1.9 KiB
Haskell
76 lines
1.9 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
module View.Scaffold where
|
|
|
|
import Servant.Links
|
|
|
|
import qualified Text.Blaze.Html5 as H
|
|
import qualified Text.Blaze.Html5.Attributes as HA
|
|
|
|
import qualified Data.Text as T
|
|
|
|
import Data.String (fromString)
|
|
|
|
import Data.Text.I18n
|
|
|
|
import Data.Maybe (fromJust, isJust)
|
|
|
|
import Control.Monad (when)
|
|
|
|
-- internal imports
|
|
|
|
import Types.Page
|
|
import API
|
|
import Util
|
|
|
|
scaffold
|
|
:: L10n
|
|
-> Locale
|
|
-> T.Text
|
|
-> Maybe T.Text
|
|
-> Page H.Html T.Text
|
|
-> H.Html
|
|
-> H.Html
|
|
scaffold l10n locale version mcookie page content = template page $ do
|
|
H.header $ H.nav $ H.ul $ do
|
|
H.li $ H.a H.! HA.href ("/" <> fromString (show $ linkURI userSelectLink)) $
|
|
H.toHtml $ translate "Home"
|
|
maybe
|
|
(return ())
|
|
(\uid ->
|
|
H.li $ H.a H.! HA.href ("/" <>
|
|
(fromString $ show $ linkURI $ userOverviewLink (read uid) Nothing)) $
|
|
H.toHtml $ translate "User Page"
|
|
)
|
|
(getLogin mcookie)
|
|
H.hr
|
|
when (isJust message)
|
|
(H.div H.! HA.id "message" H.! HA.class_ "message" $
|
|
H.toHtml (fromJust message)
|
|
)
|
|
H.div H.! HA.id "main" H.! HA.role "main" $
|
|
content
|
|
H.hr
|
|
H.footer $ H.form $ do
|
|
H.button
|
|
H.! HA.formmethod "get"
|
|
H.! HA.formaction ("/" <>
|
|
(fromString $ show $ linkURI $ productGetPriceListLink Nothing))
|
|
$ H.toHtml $ translate "Price List"
|
|
maybe
|
|
(return ())
|
|
(\_ ->
|
|
H.button
|
|
H.! HA.formmethod "get"
|
|
H.! HA.formaction ("/" <>
|
|
(fromString $ show $ linkURI $ productGetRefillLink))
|
|
$ H.toHtml $ translate "Refill stock"
|
|
)
|
|
(getLogin mcookie)
|
|
H.div
|
|
H.! HA.class_ "backend-version"
|
|
$ H.toHtml $ (translate "Powered by mateamt version") <> " " <> version
|
|
where
|
|
message = lookup "message" =<< fmap parseCookieText mcookie
|
|
translate = localize l10n locale . gettext
|
|
getLogin = snd . parseTokenAndUser
|