From 403c2c7ade31861c36334f0185b644e38d2dd71f Mon Sep 17 00:00:00 2001 From: stuebinm Date: Thu, 16 May 2024 22:07:35 +0200 Subject: new feature: Server.Frontend.Ticker A simple way to have "announcements" available via API, and otherwise distinct from the service announcements which show up in Gtfs Realtime. These are meant to go e.g. be embedded on the operator's website, or in other places where it's not as easy to display per-trip specific messages. --- lib/Server/Frontend/Routes.hs | 3 ++ lib/Server/Frontend/Ticker.hs | 63 ++++++++++++++++++++++++++++++++++++++++++ lib/Server/Frontend/Tickets.hs | 5 ++++ 3 files changed, 71 insertions(+) create mode 100644 lib/Server/Frontend/Ticker.hs (limited to 'lib/Server/Frontend') diff --git a/lib/Server/Frontend/Routes.hs b/lib/Server/Frontend/Routes.hs index 8dceda5..18cf0a1 100644 --- a/lib/Server/Frontend/Routes.hs +++ b/lib/Server/Frontend/Routes.hs @@ -45,6 +45,9 @@ mkYesodData "Frontend" [parseRoutes| /ticket/announce/#UUID AnnounceR POST /ticket/del-announce/#UUID DelAnnounceR GET +/ticker/announce TickerAnnounceR POST +/ticker/delete TickerDeleteR POST + /spacetime SpaceTimeDiagramR GET /token/block/#Token TokenBlock GET diff --git a/lib/Server/Frontend/Ticker.hs b/lib/Server/Frontend/Ticker.hs new file mode 100644 index 0000000..8861daa --- /dev/null +++ b/lib/Server/Frontend/Ticker.hs @@ -0,0 +1,63 @@ +{-# LANGUAGE QuasiQuotes #-} + +module Server.Frontend.Ticker (tickerWidget, postTickerAnnounceR, postTickerDeleteR) where +import Data.Functor ((<&>)) +import Data.Time (getCurrentTime) +import Persist (EntityField (TickerAnnouncementArchived), + TickerAnnouncement (..)) +import Server.Frontend.Routes (FrontendMessage (..), Handler, + Route (..), Widget) +import Yesod + + +tickerAnnounceForm + :: Maybe TickerAnnouncement + -> Html + -> MForm Handler (FormResult TickerAnnouncement, Widget) +tickerAnnounceForm maybeCurrent = renderDivs $ TickerAnnouncement + <$> areq textField (fieldSettingsLabel MsgHeader) + (maybeCurrent <&> tickerAnnouncementHeader) + <*> fmap unTextarea (areq textareaField (fieldSettingsLabel MsgText) + (maybeCurrent <&> (Textarea . tickerAnnouncementMessage))) + <*> pure False + <*> lift (liftIO getCurrentTime) + +tickerWidget :: Handler Html +tickerWidget = do + current <- runDB $ selectFirst [ TickerAnnouncementArchived ==. False ] [] + + (widget, enctype) <- + generateFormPost (tickerAnnounceForm (current <&> entityVal)) + + defaultLayout [whamlet| +