-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectorUI.elm
More file actions
95 lines (81 loc) · 2.77 KB
/
ConnectorUI.elm
File metadata and controls
95 lines (81 loc) · 2.77 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
module ConnectorUI exposing (..)
import MapNode exposing (..)
import MapMsg exposing (..)
import MapModel exposing (..)
import Connectors exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
getNodeConnectionPanel : Model -> Html Msg
getNodeConnectionPanel model =
div [ class "divPropertyPanel" ] [ determineConnectorPanel model ]
determineConnectorPanel : Model -> Html Msg
determineConnectorPanel model =
case model.actionState of
ConnectingNodes x ->
case x of
Waiting -> waitingPanel
FirstSelected -> firstSelectedPanel
SecondSelected -> bothSelectedPanel model.connectorData.connector
_ -> waitingPanel
waitingPanel : Html Msg
waitingPanel =
div [] [ text "Select the start node for this connector" ]
firstSelectedPanel : Html Msg
firstSelectedPanel =
div [] [ text "Select the connecting node" ]
bothSelectedPanel : Connector -> Html Msg
bothSelectedPanel c =
div [ class "divConnectorCreation" ] [
div [] [ span [ class "propName" ] [ text "Exit: " ],
span [ class "propValue" ] [ select [ onInput (\x ->
(CreateConnector (ExitChanged (stringToSide x))))] (getSideOptions c.exitSide) ] ]
,div [] [ span [ class "propName" ] [ text "Enter: " ],
span [ class "propValue" ] [ select [ onInput (\x ->
(CreateConnector (EnterChanged (stringToSide x))))] (getSideOptions c.entrySide) ] ]
,div [] [ span [ class "propName" ] [ text "Cost: " ],
span [ class "propValue" ] [ input [ onInput getCostValue ] [] ] ]
,div [] [ button [ onClick (CreateConnector FinishConnector) ] [ text "Create Connector" ] ]
]
getCostValue : String -> Msg
getCostValue s =
case String.toInt s of
Ok i -> CreateConnector (CostChanged i)
Err e -> DoNothing
nodeConnectorList : MapNode -> List (Html Msg)
nodeConnectorList node =
node.connectors
|> List.map (\x -> li [] [
text node.displayText
,text (getSideText x.exitSide)
,text (" " ++ (getSideText x.entrySide) ++ " " )
,text (" C: " ++ (toString x.cost))
])
getSideOptions : Side -> List (Html Msg)
getSideOptions side =
[
option ((value "Top")::(getOptionAttrs side "Top")) [ text "Top" ]
,option [ value "Bottom" ] [ text "Bottom" ]
,option [ value "Left" ] [ text "Left" ]
,option [ value "Right" ] [ text "Right" ]
]
getOptionAttrs : Side -> String -> List (Attribute Msg)
getOptionAttrs side value =
case (toString side) == value of
True -> [ selected True ]
False -> []
stringToSide : String -> Side
stringToSide s =
case s of
"Top" -> Top
"Bottom" -> Bottom
"Left" -> Left
"Right" -> Right
_ -> Top
getSideText : Side -> String
getSideText side =
case side of
Top -> "^"
Bottom -> "v"
Left -> "->"
Right -> "<-"