aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Income
diff options
context:
space:
mode:
authorJoris2016-06-26 12:31:24 +0200
committerJoris2016-06-26 12:31:24 +0200
commit9ec84e3a20c767f6525639f58cd22715e302b88d (patch)
treea080552859180707472c1a289080857c0a54fc06 /src/client/elm/LoggedIn/Income
parent5cb36652ccf07c9e0995ebc421a837ad7d258469 (diff)
Add an editable date field for punctual payment creation
Diffstat (limited to 'src/client/elm/LoggedIn/Income')
-rw-r--r--src/client/elm/LoggedIn/Income/Model.elm25
-rw-r--r--src/client/elm/LoggedIn/Income/View.elm13
2 files changed, 11 insertions, 27 deletions
diff --git a/src/client/elm/LoggedIn/Income/Model.elm b/src/client/elm/LoggedIn/Income/Model.elm
index e56e290..d6e5e7a 100644
--- a/src/client/elm/LoggedIn/Income/Model.elm
+++ b/src/client/elm/LoggedIn/Income/Model.elm
@@ -5,14 +5,11 @@ module LoggedIn.Income.Model exposing
, initForm
)
-import String exposing (toInt, split)
-import Date
-import Time exposing (Time)
-import Date.Extra.Create exposing (dateFromFields)
-import Date.Extra.Core exposing (intToMonth)
+import Date exposing (Date)
import Form exposing (Form)
import Form.Validate as Validate exposing (..)
+import Validation
type alias Model =
{ addIncome : Form String AddIncome
@@ -20,8 +17,8 @@ type alias Model =
}
type alias AddIncome =
- { time : Time
- , amount : Int
+ { amount : Int
+ , date : Date
}
init : Model
@@ -36,17 +33,5 @@ initForm = Form.initial [] validate
validate : Validation String AddIncome
validate =
form2 AddIncome
- (get "creation" timeValidation)
(get "amount" (int `andThen` (minInt 1)))
-
-timeValidation : Validation String Time
-timeValidation =
- customValidation string (\str ->
- case split "/" str of
- [day, month, year] ->
- case (toInt day, toInt month, toInt year) of
- (Ok dayNum, Ok monthNum, Ok yearNum) ->
- Ok (Date.toTime (dateFromFields yearNum (intToMonth monthNum) dayNum 0 0 0 0))
- _ -> Err (customError "InvalidDate")
- _ -> Err (customError "InvalidDate")
- )
+ (get "date" Validation.date)
diff --git a/src/client/elm/LoggedIn/Income/View.elm b/src/client/elm/LoggedIn/Income/View.elm
index 3019fea..02e4467 100644
--- a/src/client/elm/LoggedIn/Income/View.elm
+++ b/src/client/elm/LoggedIn/Income/View.elm
@@ -34,10 +34,9 @@ import LoggedIn.Income.Model as IncomeModel
import LoggedIn.Msg as LoggedInMsg
import LoggedIn.Income.Msg as IncomeMsg
-import LoggedIn.View.Date exposing (renderShortDate)
+import View.Date as Date
import LoggedIn.View.Format as Format
-import LoggedIn.View.Date exposing (renderLongDate)
import View.Color as Color
view : LoggedData -> IncomeModel.Model -> Html Msg
@@ -54,7 +53,7 @@ view loggedData incomeModel =
cumulativeIncomesView : LoggedData -> Time -> Html Msg
cumulativeIncomesView loggedData since =
- let longDate = renderLongDate (Date.fromTime since) loggedData.translations
+ let longDate = Date.longView (Date.fromTime since) loggedData.translations
in div
[]
[ h1 [] [ text <| getParamMessage [longDate] "CumulativeIncomesSince" loggedData.translations ]
@@ -81,13 +80,13 @@ addIncomeView loggedData addIncome =
let htmlMap = Html.map (Msg.UpdateLoggedIn << LoggedInMsg.IncomeMsg << IncomeMsg.AddIncomeMsg)
in Html.form
[ onSubmitPrevDefault Msg.NoOp ]
- [ htmlMap <| Form.textInput loggedData.translations addIncome "income" "creation"
- , htmlMap <| Form.textInput loggedData.translations addIncome "income" "amount"
+ [ htmlMap <| Form.textInput loggedData.translations addIncome "income" "amount"
+ , htmlMap <| Form.textInput loggedData.translations addIncome "income" "date"
, button
[ class "add"
, case Form.getOutput addIncome of
Just data ->
- onClick (Msg.UpdateLoggedIn <| LoggedInMsg.AddIncome data.time data.amount)
+ onClick (Msg.UpdateLoggedIn <| LoggedInMsg.AddIncome data.amount data.date)
Nothing ->
onClick (Msg.UpdateLoggedIn <| LoggedInMsg.IncomeMsg <| IncomeMsg.AddIncomeMsg <| Form.Submit)
]
@@ -110,7 +109,7 @@ incomeView : LoggedData -> (IncomeId, Income) -> Html Msg
incomeView loggedData (incomeId, income) =
li
[]
- [ text <| renderShortDate (Date.fromTime income.time) loggedData.translations
+ [ text <| Date.shortView (Date.fromTime income.time) loggedData.translations
, text " − "
, text <| Format.price loggedData.conf income.amount
, let dialogConfig =