docspell/modules/webapp/src/main/elm/Data/Direction.elm

81 lines
1.3 KiB
Elm
Raw Normal View History

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
)
type Direction
= Incoming
| Outgoing
2019-12-29 20:55:12 +00:00
fromString : String -> Maybe Direction
fromString str =
case String.toLower str of
2019-12-29 20:55:12 +00:00
"outgoing" ->
Just Outgoing
"incoming" ->
Just Incoming
2019-12-29 20:55:12 +00:00
_ ->
Nothing
all : List Direction
all =
[ Incoming
, Outgoing
]
2019-12-29 20:55:12 +00:00
toString : Direction -> String
toString dir =
case dir of
2019-12-29 20:55:12 +00:00
Incoming ->
"Incoming"
2019-12-29 20:55:12 +00:00
Outgoing ->
"Outgoing"
icon : Direction -> String
icon dir =
case dir of
2019-12-29 20:55:12 +00:00
Incoming ->
"level down alternate icon"
Outgoing ->
"level up alternate icon"
2019-12-29 20:55:12 +00:00
unknownIcon : String
unknownIcon =
"question circle outline icon"
2019-12-29 20:55:12 +00:00
iconFromString : String -> String
iconFromString dir =
fromString dir
|> Maybe.map icon
|> Maybe.withDefault unknownIcon
2019-12-29 20:55:12 +00:00
iconFromMaybe : Maybe String -> String
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"