2020-11-23 15:44:45 +03:00
|
|
|
module Route exposing (..)
|
|
|
|
|
2020-12-04 12:21:09 +03:00
|
|
|
import AirScripts.GetAll as GetAll
|
2020-12-01 17:47:52 +03:00
|
|
|
import BlueprintPage.View as BlueprintPage
|
2020-11-30 16:33:24 +03:00
|
|
|
import Html exposing (Html, text)
|
2020-11-25 05:20:20 +03:00
|
|
|
import HubPage.View as HubPage
|
2020-11-23 16:31:31 +03:00
|
|
|
import Model exposing (Model, Route(..))
|
2020-12-01 15:43:06 +03:00
|
|
|
import ModulePage.View as ModulePage
|
2020-12-01 18:16:56 +03:00
|
|
|
import Msg exposing (Msg)
|
2020-12-10 13:45:04 +03:00
|
|
|
import NodePage.View as NodePage
|
2020-11-23 15:44:45 +03:00
|
|
|
import Port exposing (sendAir)
|
|
|
|
import Url.Parser exposing ((</>), Parser, map, oneOf, s, string)
|
|
|
|
|
|
|
|
|
|
|
|
routeParser : Parser (Route -> a) a
|
|
|
|
routeParser =
|
|
|
|
oneOf
|
|
|
|
[ map Peer (s "peer" </> string)
|
2020-11-28 18:16:57 +03:00
|
|
|
, map Module (s "module" </> string)
|
2020-12-01 17:47:52 +03:00
|
|
|
, map Blueprint (s "blueprint" </> string)
|
2020-11-23 15:44:45 +03:00
|
|
|
, map Page string
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-11-23 16:31:31 +03:00
|
|
|
parse url =
|
|
|
|
Maybe.withDefault (Page "") <| Url.Parser.parse routeParser url
|
|
|
|
|
2020-11-25 19:51:53 +03:00
|
|
|
|
2020-12-01 18:16:56 +03:00
|
|
|
routeView : Model -> Route -> Html Msg
|
2020-11-25 22:11:11 +03:00
|
|
|
routeView model route =
|
2020-11-25 05:20:20 +03:00
|
|
|
case route of
|
|
|
|
Page page ->
|
|
|
|
case page of
|
2020-11-26 21:47:37 +03:00
|
|
|
"" ->
|
2020-11-28 16:50:40 +03:00
|
|
|
HubPage.view model
|
2020-11-30 14:31:03 +03:00
|
|
|
|
2020-11-25 05:20:20 +03:00
|
|
|
"hub" ->
|
2020-11-28 16:50:40 +03:00
|
|
|
HubPage.view model
|
2020-11-25 19:51:53 +03:00
|
|
|
|
2020-12-10 13:45:04 +03:00
|
|
|
"nodes" ->
|
|
|
|
NodePage.view model
|
|
|
|
|
2020-11-25 05:20:20 +03:00
|
|
|
_ ->
|
2020-11-30 16:33:24 +03:00
|
|
|
text ("undefined page: " ++ page)
|
2020-11-25 05:20:20 +03:00
|
|
|
|
|
|
|
Peer peer ->
|
2020-11-30 16:33:24 +03:00
|
|
|
text peer
|
2020-11-23 16:31:31 +03:00
|
|
|
|
2020-12-01 17:47:52 +03:00
|
|
|
Blueprint id ->
|
|
|
|
BlueprintPage.view model id
|
2020-11-28 18:16:57 +03:00
|
|
|
|
|
|
|
Module moduleName ->
|
2020-12-01 15:43:06 +03:00
|
|
|
ModulePage.view model moduleName
|
|
|
|
|
2020-12-09 10:20:08 +03:00
|
|
|
|
2020-12-07 14:31:02 +03:00
|
|
|
getAllCmd : String -> String -> List String -> Cmd msg
|
|
|
|
getAllCmd peerId relayId knownPeers =
|
|
|
|
Cmd.batch
|
2020-12-10 16:37:53 +03:00
|
|
|
[ sendAir (GetAll.air peerId relayId knownPeers)
|
2020-12-07 14:31:02 +03:00
|
|
|
]
|
2020-11-28 18:16:57 +03:00
|
|
|
|
2020-12-09 10:20:08 +03:00
|
|
|
|
2020-11-23 15:44:45 +03:00
|
|
|
routeCommand : Model -> Route -> Cmd msg
|
2020-12-10 16:37:53 +03:00
|
|
|
routeCommand m _ =
|
2020-12-09 16:29:28 +03:00
|
|
|
if m.isInitialized then
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
else
|
|
|
|
getAllCmd m.peerId m.relayId m.knownPeers
|