From 4307e3aa7c42b7d28c552439e2d7fce232fe2598 Mon Sep 17 00:00:00 2001
From: stuebinm
Date: Sun, 14 Aug 2022 23:52:37 +0200
Subject: ControlRoom: default layout
---
lib/Server/ControlRoom.hs | 48 +++++++++++++++++++++++++++++------------------
tracktrain.cabal | 1 +
2 files changed, 31 insertions(+), 18 deletions(-)
diff --git a/lib/Server/ControlRoom.hs b/lib/Server/ControlRoom.hs
index 0e3f01e..e3af33f 100644
--- a/lib/Server/ControlRoom.hs
+++ b/lib/Server/ControlRoom.hs
@@ -14,7 +14,6 @@
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
-{-# LANGUAGE ViewPatterns #-}
module Server.ControlRoom (ControlRoom(..)) where
@@ -76,18 +75,34 @@ mkYesod "ControlRoom" [parseRoutes|
instance Yesod ControlRoom where
approot = ApprootMaster (\cr -> getBaseurl cr)
+ defaultLayout w = do
+ p <- widgetToPageContent w
+ msgs <- getMessages
+ withUrlRenderer [hamlet|
+ $newline never
+ $doctype 5
+
+
+ Tracktrain #{pageTitle p}
+ $maybe description <- pageDescription p
+
+ ^{pageHead p}
+
+ $forall (status, msg) <- msgs
+ #{msg}
+ ^{pageBody p}
+ |]
+
+
instance RenderMessage ControlRoom FormMessage where
renderMessage _ _ = defaultFormMessage
--- which backend we're using and how to run an action.
instance YesodPersist ControlRoom where
type YesodPersistBackend ControlRoom = SqlBackend
runDB action = do
pool <- getYesod <&> getPool
runSqlPool action pool
-
-
getRootR :: Handler Html
getRootR = redirect (TrainsR)
@@ -99,8 +114,9 @@ getTrainsR = do
day <- liftIO $ maybeM (getCurrentTime <&> utctDay) pure (pure maybeDay)
gtfs <- getYesod <&> getGtfs
let trips = tripsOnDay gtfs day
- defaultLayout [whamlet|
-
Trains on #{iso8601Show day}
+ defaultLayout $ do
+ [whamlet|
+Trains on #{day}
$forall Trip{..} <- trips
- #{tripTripID}
@@ -116,7 +132,7 @@ getTrainViewR trip day = do
Just res@Trip{..} -> do
anns <- runDB $ selectList [ AnnouncementTrip ==. trip, AnnouncementDay ==. day ] []
defaultLayout [whamlet|
-
#{tripTripID} _{Msgon} #{iso8601Show day}
+#{tripTripID} _{Msgon} #{day}
_{MsgAnnouncements}
$forall Entity (AnnouncementKey uuid) Announcement{..} <- anns
@@ -192,17 +208,6 @@ getDelAnnounceR uuid = do
Just Announcement{..} ->
redirect (TrainViewR announcementTrip announcementDay)
-instance ToMarkup Time where
- toMarkup time =
- toMarkup (show time)
-
-data TrainAnnounceF = TrainAnnounceF
- { taHeader :: Text
- , taMsg :: Text
- , taLogTime :: Bool
- } deriving (Show)
-
-
announceForm :: Day -> TripID -> Html -> MForm Handler (FormResult Announcement, Widget)
announceForm day tripId = renderDivs $ Announcement
@@ -215,3 +220,10 @@ announceForm day tripId = renderDivs $ Announcement
+--- some orphans to make hamlet easier to deal with
+instance ToMarkup Time where
+ toMarkup time =
+ toMarkup (show time)
+
+instance ToMarkup Day where
+ toMarkup day = toMarkup (iso8601Show day)
diff --git a/tracktrain.cabal b/tracktrain.cabal
index 4484247..b02e9a5 100644
--- a/tracktrain.cabal
+++ b/tracktrain.cabal
@@ -107,6 +107,7 @@ library
default-language: Haskell2010
default-extensions: OverloadedStrings
, ScopedTypeVariables
+ , ViewPatterns
library gtfs
build-depends: base ^>=4.14.3.0
--
cgit v1.2.3