aboutsummaryrefslogtreecommitdiff
path: root/lib/Server/Frontend/Gtfs.hs
blob: bc21ab7d0fe1ddb65f75fde0174a59873a704c75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{-# LANGUAGE DataKinds       #-}
{-# LANGUAGE LambdaCase      #-}
{-# LANGUAGE QuasiQuotes     #-}
{-# LANGUAGE RecordWildCards #-}

module Server.Frontend.Gtfs (getGtfsTripViewR, getGtfsTripsViewR) where

import           Server.Frontend.Routes

import           Data.Functor           ((<&>))
import qualified Data.Map               as M
import           Data.Text              (Text)
import qualified Data.Vector            as V
import qualified GTFS
import           Text.Blaze.Html        (Html)
import           Yesod

getGtfsTripsViewR :: Handler Html
getGtfsTripsViewR = do
  GTFS.GTFS{..} <- getYesod <&> getGtfs
  defaultLayout $ do
    setTitle "List of Trips"
    [whamlet|
<h1>List of Trips
<section><ul>
  $forall trip@GTFS.Trip{..} <- trips
    <li><a href="@{GtfsTripViewR tripTripId}">#{GTFS.tripName trip}</a>
      : #{GTFS.stopDeparture (V.head tripStops)} #{GTFS.stationName (GTFS.stopStation (V.head tripStops))}
|]


getGtfsTripViewR :: GTFS.TripId -> Handler Html
getGtfsTripViewR tripId = do
  GTFS.GTFS{..} <- getYesod <&> getGtfs
  case M.lookup tripId trips of
    Nothing -> notFound
    Just trip@GTFS.Trip{..} -> defaultLayout [whamlet|
<h1>_{MsgTrip} #{GTFS.tripName trip}
<section>
  <h2>_{MsgInfo}
  <p><strong>_{MsgtripId}:</strong> #{tripTripId}
  <p><strong>_{MsgtripHeadsign}:</strong> #{mightbe tripHeadsign}
  <p><strong>_{MsgtripShortname}:</strong> #{mightbe tripShortName}
<section>
  <h2>_{MsgStops}
  <ol>
    $forall GTFS.Stop{..} <- tripStops
      <div>(#{stopSequence}) #{stopArrival} #{GTFS.stationName stopStation}
<section>
  <h2>Dates
  <ul>
    TODO!
|]

mightbe :: Maybe Text -> Text
mightbe (Just a) = a
mightbe Nothing  = ""