2017-07-17 09:25:57 +00:00
|
|
|
module Routing exposing (..)
|
|
|
|
|
|
|
|
-- Local modules
|
|
|
|
|
2017-07-17 14:05:38 +00:00
|
|
|
import Models exposing (Route(..))
|
2017-07-17 09:25:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- External modules
|
|
|
|
|
|
|
|
import Navigation exposing (Location)
|
2017-07-17 14:05:38 +00:00
|
|
|
import UrlParser exposing (Parser, (</>), oneOf, map, top, s, string, parseHash)
|
2017-07-17 09:25:57 +00:00
|
|
|
|
|
|
|
|
2017-07-23 00:51:39 +00:00
|
|
|
{--
|
|
|
|
URLs to support:
|
|
|
|
|
2017-08-02 20:20:38 +00:00
|
|
|
- #/
|
2017-07-23 00:51:39 +00:00
|
|
|
This show the overview of the schedule
|
|
|
|
|
2017-08-02 20:20:38 +00:00
|
|
|
- #/?type={types},location={locations},video={not-to-be-recorded,to-be-recorded,has-recording}
|
2017-07-23 00:51:39 +00:00
|
|
|
This is the overview, just with filters enable
|
|
|
|
|
2017-08-02 20:20:38 +00:00
|
|
|
- #/day/{year}-{month}-{day}
|
2017-07-23 00:51:39 +00:00
|
|
|
Show a particular day
|
|
|
|
|
2017-08-02 20:20:38 +00:00
|
|
|
- #/event/{slug}
|
2017-07-23 00:51:39 +00:00
|
|
|
Show a particular event
|
|
|
|
|
|
|
|
--}
|
|
|
|
|
|
|
|
|
2017-07-17 14:05:38 +00:00
|
|
|
matchers : Parser (Route -> a) a
|
2017-07-17 09:25:57 +00:00
|
|
|
matchers =
|
2017-07-17 14:05:38 +00:00
|
|
|
oneOf
|
|
|
|
[ map OverviewRoute top
|
2017-07-23 00:51:39 +00:00
|
|
|
, map OverviewFilteredRoute (top </> string)
|
2017-07-17 14:05:38 +00:00
|
|
|
, map DayRoute (s "day" </> string)
|
|
|
|
, map EventRoute (s "event" </> string)
|
2017-08-02 20:20:38 +00:00
|
|
|
, map SpeakerRoute (s "speaker" </> string)
|
2017-07-17 09:25:57 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
parseLocation : Location -> Route
|
|
|
|
parseLocation location =
|
2017-07-23 16:30:27 +00:00
|
|
|
parseHash matchers location
|
|
|
|
|> Maybe.withDefault NotFoundRoute
|
2017-08-02 20:20:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
routeToString : Route -> String
|
|
|
|
routeToString route =
|
|
|
|
let
|
|
|
|
parts =
|
|
|
|
case route of
|
|
|
|
OverviewRoute ->
|
|
|
|
[]
|
|
|
|
|
|
|
|
OverviewFilteredRoute query ->
|
|
|
|
[ query ]
|
|
|
|
|
|
|
|
DayRoute iso ->
|
|
|
|
[ "day", iso ]
|
|
|
|
|
|
|
|
EventRoute slug ->
|
|
|
|
[ "event", slug ]
|
|
|
|
|
|
|
|
SpeakerRoute slug ->
|
|
|
|
[ "speaker", slug ]
|
|
|
|
|
|
|
|
NotFoundRoute ->
|
|
|
|
[]
|
|
|
|
in
|
|
|
|
"#/" ++ String.join "/" parts
|