Ui improvements

- don't show custom fields in edit menu if there are none. This
reduces load of ui elements. The first custom field must be created in
manage-data page.

- Add more validation to the money type
This commit is contained in:
Eike Kettner
2020-11-22 13:25:24 +01:00
parent ff30ed5558
commit bb19e02c66
4 changed files with 85 additions and 26 deletions

View File

@ -0,0 +1,43 @@
module Data.Money exposing
( Money
, format
, fromString
, roundMoney
)
type alias Money =
Float
fromString : String -> Result String Money
fromString str =
let
points =
String.indexes "." str
len =
String.length str
in
case points of
index :: [] ->
if index == (len - 3) then
String.toFloat str
|> Maybe.map Ok
|> Maybe.withDefault (Err "Two digits required after the dot.")
else
Err ("Two digits required after the dot: " ++ str)
_ ->
Err "One single dot + digits required for money."
format : Float -> String
format money =
String.fromFloat (roundMoney money)
roundMoney : Float -> Float
roundMoney input =
(round (input * 100) |> toFloat) / 100