mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 10:58:26 +00:00
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:
43
modules/webapp/src/main/elm/Data/Money.elm
Normal file
43
modules/webapp/src/main/elm/Data/Money.elm
Normal 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
|
Reference in New Issue
Block a user