aboutsummaryrefslogtreecommitdiff
path: root/lib/Server/ControlRoom.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Server/ControlRoom.hs')
-rw-r--r--lib/Server/ControlRoom.hs84
1 files changed, 64 insertions, 20 deletions
diff --git a/lib/Server/ControlRoom.hs b/lib/Server/ControlRoom.hs
index f08abcb..2be0b3e 100644
--- a/lib/Server/ControlRoom.hs
+++ b/lib/Server/ControlRoom.hs
@@ -32,7 +32,7 @@ import Data.Pool (Pool)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Time (UTCTime (..), getCurrentTime,
- utctDay)
+ utctDay, addDays)
import Data.Time.Calendar (Day)
import Data.Time.Format.ISO8601 (iso8601Show)
import Data.UUID (UUID)
@@ -125,10 +125,14 @@ instance Yesod ControlRoom where
<meta name="description" content="#{description}">
^{pageHead}
<style>
+ html {
+ overflow-x: hidden
+ }
section {
- border: 1px solid black;
+ border: 0.1rem solid black;
padding: 1rem;
- margin: 2rem;
+ margin: 2vw;
+ margin-top: 0;
padding-top: 0;
}
body {
@@ -158,9 +162,34 @@ instance Yesod ControlRoom where
width: 100%;
height: 50vh;
}
+ nav {
+ padding: 0.5em;
+ position: relative;
+ text-align: center;
+ margin-left: 2vw;
+ margin-right: 2vw;
+ margin-top: 2rem;
+ }
+ .nav-left {
+ position: absolute;
+ left: 0;
+ }
+ .nav-right {
+ position: absolute;
+ right: 0;
+ }
+ ol {
+ padding: 0
+ }
+ li {
+ list-style: none;
+ margin: 0.5vw;
+ border-bottom: 0.1rem black dashed;
+ padding-bottom: 0.5rem;
+ }
<body>
$forall (status, msg) <- msgs
- <p class="message #{status}">#{msg}
+ <!-- <p class="message #{status}">#{msg} -->
^{pageBody}
|]
@@ -193,8 +222,7 @@ instance YesodAuth ControlRoom where
Just extra -> A.decode (LB.fromStrict $ C8.pack $ T.unpack extra)
authenticate creds = do
- forM_ (credsExtra creds) $ \(key, val) ->
- setSession key val
+ forM_ (credsExtra creds) (uncurry setSession)
-- extra <- lookupSession "extra"
-- pure (Authenticated ( undefined))
e <- lookupSession "json"
@@ -225,18 +253,34 @@ getTrainsR = do
let maybeDay = lookup "day" (reqGetParams req) >>= (readMaybe . T.unpack)
mdisplayname <- maybeAuthId <&> fmap uffdDisplayName
- day <- liftIO $ maybeM (getCurrentTime <&> utctDay) pure (pure maybeDay)
+ (day, isToday) <- liftIO $ getCurrentTime <&> utctDay <&> \today ->
+ case maybeDay of
+ Just day -> (day, day == today)
+ Nothing -> (today, True)
+
+ let prevday = (T.pack . iso8601Show . addDays (-1)) day
+ let nextday = (T.pack . iso8601Show . addDays 1) day
gtfs <- getYesod <&> getGtfs
let trips = tripsOnDay gtfs day
defaultLayout $ do
[whamlet|
-<h1>Trains on #{day}
+<h1> _{MsgTrainsOnDay (iso8601Show day)}
$maybe name <- mdisplayname
<p>_{MsgLoggedInAs name} - <a href="@{AuthR LogoutR}">_{MsgLogout}</a>
-<section><ol>
- $forall trip@Trip{..} <- trips
- <li><a href="@{TrainViewR tripTripID day}">#{tripName trip}</a>
- : #{stopDeparture (V.head tripStops)} #{stationName (stopStation (V.head tripStops))}
+<nav>
+ <a class="nav-left" href="@?{(TrainsR, [("day", prevday)])}">← #{prevday}
+ $if isToday
+ _{Msgtoday}
+ $else
+ <a href="@{TrainsR}">_{Msgtoday}
+ <a class="nav-right" href="@?{(TrainsR, [("day", nextday)])}">#{nextday} →
+<section>
+ <ol>
+ $forall trip@Trip{..} <- trips
+ <li><a href="@{TrainViewR tripTripID day}">_{MsgTrip} #{tripName trip}</a>
+ : _{Msgdep} #{stopDeparture (V.head tripStops)} #{stationName (stopStation (V.head tripStops))}
+ $if null trips
+ <li style="text-align: center"><em>(_{MsgNone})
|]
getTrainViewR :: TripID -> Day -> Handler Html
@@ -284,13 +328,13 @@ getTrainViewR trip day = do
<h2>_{MsgAnnouncements}
<ul>
$forall Entity (AnnouncementKey uuid) Announcement{..} <- anns
- <li><em>#{announcementHeader}: #{announcementMessage}</em> <a href="@{DelAnnounceR uuid}">delete</a>
+ <li><em>#{announcementHeader}: #{announcementMessage}</em> <a href="@{DelAnnounceR uuid}">_{Msgdelete}</a>
$if null anns
<li><em>(_{MsgNone})</em>
<h3>_{MsgNewAnnouncement}
<form method=post action=@{AnnounceR trip day} enctype=#{enctype}>
^{widget}
- <button>Submit
+ <button>_{MsgSubmit}
<section>
<h2>_{MsgTokens}
<table>
@@ -317,7 +361,7 @@ getTrainMapViewR tripId day = do
(widget, enctype) <- generateFormPost (announceForm day tripId)
case M.lookup tripId trips of
Nothing -> notFound
- Just res@Trip{..} -> do defaultLayout $ [whamlet|
+ Just res@Trip{..} -> do defaultLayout [whamlet|
<h1>_{MsgTrip} <a href="@{TrainViewR tripTripID day}">#{tripName res} _{Msgon} #{day}</a>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css"
integrity="sha256-kLaT2GOSpHechhsozzB+flnD+zUyjE2LlfWPgU04xyI="
@@ -373,14 +417,14 @@ getTripViewR tripId = do
case M.lookup tripId trips of
Nothing -> notFound
Just trip@Trip{..} -> defaultLayout [whamlet|
-<h1>Trip #{tripName trip}
+<h1>_{MsgTrip} #{tripName trip}
<section>
- <h2>Info
+ <h2>_{MsgInfo}
<p><strong>_{MsgtripId}:</strong> #{tripTripID}
<p><strong>_{MsgtripHeadsign}:</strong> #{mightbe tripHeadsign}
<p><strong>_{MsgtripShortname}:</strong> #{mightbe tripShortName}
<section>
- <h2>Stops
+ <h2>_{MsgStops}
<ol>
$forall Stop{..} <- tripStops
<div>(#{stopSequence}) #{stopArrival} #{stationName stopStation}
@@ -400,10 +444,10 @@ postAnnounceR trip day = do
redirect (TrainViewR trip day)
_ -> defaultLayout
[whamlet|
- <p>Invalid input, let's try again.
+ <p>_{MsgInvalidInput}.
<form method=post action=@{AnnounceR trip day} enctype=#{enctype}>
^{widget}
- <button>Submit
+ <button>_{MsgSubmit}
|]
getDelAnnounceR :: UUID -> Handler Html