2019-12-29 20:55:12 +00:00
|
|
|
module Data.Direction exposing
|
|
|
|
( Direction(..)
|
|
|
|
, all
|
|
|
|
, fromString
|
|
|
|
, icon
|
|
|
|
, iconFromMaybe
|
|
|
|
, iconFromString
|
2020-05-17 16:14:54 +00:00
|
|
|
, labelFromMaybe
|
2019-12-29 20:55:12 +00:00
|
|
|
, toString
|
|
|
|
)
|
|
|
|
|
2019-07-22 22:53:30 +00:00
|
|
|
|
|
|
|
type Direction
|
|
|
|
= Incoming
|
|
|
|
| Outgoing
|
|
|
|
|
2019-12-29 20:55:12 +00:00
|
|
|
|
|
|
|
fromString : String -> Maybe Direction
|
2019-07-22 22:53:30 +00:00
|
|
|
fromString str =
|
|
|
|
case String.toLower str of
|
2019-12-29 20:55:12 +00:00
|
|
|
"outgoing" ->
|
|
|
|
Just Outgoing
|
|
|
|
|
|
|
|
"incoming" ->
|
|
|
|
Just Incoming
|
2019-07-22 22:53:30 +00:00
|
|
|
|
2019-12-29 20:55:12 +00:00
|
|
|
_ ->
|
|
|
|
Nothing
|
|
|
|
|
|
|
|
|
|
|
|
all : List Direction
|
2019-07-22 22:53:30 +00:00
|
|
|
all =
|
|
|
|
[ Incoming
|
|
|
|
, Outgoing
|
|
|
|
]
|
|
|
|
|
2019-12-29 20:55:12 +00:00
|
|
|
|
|
|
|
toString : Direction -> String
|
2019-07-22 22:53:30 +00:00
|
|
|
toString dir =
|
|
|
|
case dir of
|
2019-12-29 20:55:12 +00:00
|
|
|
Incoming ->
|
|
|
|
"Incoming"
|
2019-07-22 22:53:30 +00:00
|
|
|
|
2019-12-29 20:55:12 +00:00
|
|
|
Outgoing ->
|
|
|
|
"Outgoing"
|
|
|
|
|
|
|
|
|
|
|
|
icon : Direction -> String
|
2019-07-22 22:53:30 +00:00
|
|
|
icon dir =
|
|
|
|
case dir of
|
2019-12-29 20:55:12 +00:00
|
|
|
Incoming ->
|
|
|
|
"level down alternate icon"
|
|
|
|
|
|
|
|
Outgoing ->
|
|
|
|
"level up alternate icon"
|
2019-07-22 22:53:30 +00:00
|
|
|
|
2019-12-29 20:55:12 +00:00
|
|
|
|
|
|
|
unknownIcon : String
|
2019-07-22 22:53:30 +00:00
|
|
|
unknownIcon =
|
|
|
|
"question circle outline icon"
|
|
|
|
|
2019-12-29 20:55:12 +00:00
|
|
|
|
|
|
|
iconFromString : String -> String
|
2019-07-22 22:53:30 +00:00
|
|
|
iconFromString dir =
|
|
|
|
fromString dir
|
|
|
|
|> Maybe.map icon
|
|
|
|
|> Maybe.withDefault unknownIcon
|
|
|
|
|
2019-12-29 20:55:12 +00:00
|
|
|
|
|
|
|
iconFromMaybe : Maybe String -> String
|
2019-07-22 22:53:30 +00:00
|
|
|
iconFromMaybe ms =
|
|
|
|
Maybe.map iconFromString ms
|
|
|
|
|> Maybe.withDefault unknownIcon
|
2020-05-17 16:14:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
labelFromMaybe : Maybe String -> String
|
|
|
|
labelFromMaybe ms =
|
|
|
|
Maybe.andThen fromString ms
|
|
|
|
|> Maybe.map toString
|
|
|
|
|> Maybe.withDefault "Direction"
|