aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn
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
parent5cb36652ccf07c9e0995ebc421a837ad7d258469 (diff)
downloadbudget-9ec84e3a20c767f6525639f58cd22715e302b88d.tar.gz
budget-9ec84e3a20c767f6525639f58cd22715e302b88d.tar.bz2
budget-9ec84e3a20c767f6525639f58cd22715e302b88d.zip
Add an editable date field for punctual payment creation
Diffstat (limited to 'src/client/elm/LoggedIn')
-rw-r--r--src/client/elm/LoggedIn/Home/View/Table.elm6
-rw-r--r--src/client/elm/LoggedIn/Income/Model.elm25
-rw-r--r--src/client/elm/LoggedIn/Income/View.elm13
-rw-r--r--src/client/elm/LoggedIn/Msg.elm10
-rw-r--r--src/client/elm/LoggedIn/Stat/View.elm4
-rw-r--r--src/client/elm/LoggedIn/Update.elm20
-rw-r--r--src/client/elm/LoggedIn/View/Date.elm48
7 files changed, 31 insertions, 95 deletions
diff --git a/src/client/elm/LoggedIn/Home/View/Table.elm b/src/client/elm/LoggedIn/Home/View/Table.elm
index 323a45d..fa0a93d 100644
--- a/src/client/elm/LoggedIn/Home/View/Table.elm
+++ b/src/client/elm/LoggedIn/Home/View/Table.elm
@@ -21,7 +21,7 @@ import LoggedIn.Msg as LoggedInMsg
import LoggedIn.Home.Msg as HomeMsg
import LoggedIn.Home.Model as HomeModel
-import LoggedIn.View.Date exposing (..)
+import View.Date as Date
import LoggedIn.View.Format as Format
import Model.User exposing (getUserName)
@@ -91,10 +91,10 @@ paymentLine loggedData homeModel frequency payment =
[ class "cell date" ]
[ span
[ class "shortDate" ]
- [ text (renderShortDate payment.creation loggedData.translations) ]
+ [ text (Date.shortView payment.date loggedData.translations) ]
, span
[ class "longDate" ]
- [ text (renderLongDate payment.creation loggedData.translations) ]
+ [ text (Date.longView payment.date loggedData.translations) ]
]
Monthly ->
text ""
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 =
diff --git a/src/client/elm/LoggedIn/Msg.elm b/src/client/elm/LoggedIn/Msg.elm
index c09655f..cbae67f 100644
--- a/src/client/elm/LoggedIn/Msg.elm
+++ b/src/client/elm/LoggedIn/Msg.elm
@@ -2,7 +2,7 @@ module LoggedIn.Msg exposing
( Msg(..)
)
-import Time exposing (Time)
+import Date exposing (Date)
import Model.Payment exposing (Payment, PaymentId, Frequency)
import Model.Income exposing (IncomeId)
@@ -15,14 +15,14 @@ type Msg =
| HomeMsg HomeMsg.Msg
| IncomeMsg IncomeMsg.Msg
- | AddPayment String Int Frequency
- | ValidateAddPayment PaymentId String Int Frequency
+ | AddPayment String Int Date Frequency
+ | ValidateAddPayment PaymentId String Int Date Frequency
| DeletePayment PaymentId
| ValidateDeletePayment PaymentId
- | AddIncome Time Int
- | ValidateAddIncome IncomeId Time Int
+ | AddIncome Int Date
+ | ValidateAddIncome IncomeId Int Date
| DeleteIncome IncomeId
| ValidateDeleteIncome IncomeId
diff --git a/src/client/elm/LoggedIn/Stat/View.elm b/src/client/elm/LoggedIn/Stat/View.elm
index 72e1f34..636312d 100644
--- a/src/client/elm/LoggedIn/Stat/View.elm
+++ b/src/client/elm/LoggedIn/Stat/View.elm
@@ -16,7 +16,7 @@ import Model.Conf exposing (Conf)
import Model.Translations exposing (getMessage, getParamMessage)
import LoggedIn.View.Format as Format
-import LoggedIn.View.Date as Date
+import View.Date as Date
import View.Plural exposing (plural)
import Utils.List as List
@@ -47,7 +47,7 @@ monthDetail : LoggedData -> ((Month, Int), Payments) -> Html Msg
monthDetail loggedData ((month, year), payments) =
li
[]
- [ text (Date.renderMonth loggedData.translations month)
+ [ text (Date.monthView loggedData.translations month)
, text " "
, text (toString year)
, text " − "
diff --git a/src/client/elm/LoggedIn/Update.elm b/src/client/elm/LoggedIn/Update.elm
index 48d87f7..1f09271 100644
--- a/src/client/elm/LoggedIn/Update.elm
+++ b/src/client/elm/LoggedIn/Update.elm
@@ -58,9 +58,9 @@ update model msg loggedIn =
, Cmd.map LoggedInMsg.IncomeMsg cmd
)
- LoggedInMsg.AddPayment name cost frequency ->
+ LoggedInMsg.AddPayment name cost date frequency ->
( loggedIn
- , Server.addPayment name cost frequency
+ , Server.createPayment name cost date frequency
|> Task.perform
(\err ->
case err of
@@ -69,15 +69,15 @@ update model msg loggedIn =
_ ->
LoggedInMsg.NoOp
)
- (\paymentId -> LoggedInMsg.ValidateAddPayment paymentId name cost frequency)
+ (\paymentId -> LoggedInMsg.ValidateAddPayment paymentId name cost date frequency)
)
- LoggedInMsg.ValidateAddPayment paymentId name cost frequency ->
+ LoggedInMsg.ValidateAddPayment paymentId name cost date frequency ->
update model (LoggedInMsg.HomeMsg <| HomeMsg.SearchMsg (Form.Reset (HomeModel.searchInitial frequency))) loggedIn
:> update model (LoggedInMsg.HomeMsg <| HomeMsg.SearchMsg Form.Submit)
:> update model (LoggedInMsg.HomeMsg <| HomeMsg.UpdatePage 1)
:> (\loggedIn ->
- let newPayment = Payment paymentId (Date.fromTime model.currentTime) name cost loggedIn.me frequency
+ let newPayment = Payment paymentId name cost date loggedIn.me frequency
in ( { loggedIn | payments = newPayment :: loggedIn.payments }
, Cmd.none
)
@@ -115,16 +115,16 @@ update model msg loggedIn =
, Cmd.none
)
- LoggedInMsg.AddIncome time amount ->
+ LoggedInMsg.AddIncome amount date ->
( loggedIn
- , Server.addIncome time amount
+ , Server.createIncome amount date
|> Task.perform
(always LoggedInMsg.NoOp)
- (\incomeId -> (LoggedInMsg.ValidateAddIncome incomeId time amount))
+ (\incomeId -> (LoggedInMsg.ValidateAddIncome incomeId amount date))
)
- LoggedInMsg.ValidateAddIncome incomeId time amount ->
- let newIncome = { userId = loggedIn.me, time = time, amount = amount }
+ LoggedInMsg.ValidateAddIncome incomeId amount date ->
+ let newIncome = { userId = loggedIn.me, amount = amount, time = Date.toTime date }
loggedInIncome = loggedIn.income
in ( { loggedIn
| incomes = Dict.insert incomeId newIncome loggedIn.incomes
diff --git a/src/client/elm/LoggedIn/View/Date.elm b/src/client/elm/LoggedIn/View/Date.elm
deleted file mode 100644
index 8e4e872..0000000
--- a/src/client/elm/LoggedIn/View/Date.elm
+++ /dev/null
@@ -1,48 +0,0 @@
-module LoggedIn.View.Date exposing
- ( renderShortDate
- , renderLongDate
- , renderMonth
- )
-
-import Date exposing (..)
-import Date.Extra.Core as Date
-import String
-
-import Model.Translations exposing (..)
-
-renderShortDate : Date -> Translations -> String
-renderShortDate date translations =
- let params =
- [ String.pad 2 '0' (toString (Date.day date))
- , String.pad 2 '0' (toString (Date.monthToInt (Date.month date)))
- , toString (Date.year date)
- ]
- in getParamMessage params "ShortDate" translations
-
-renderLongDate : Date -> Translations -> String
-renderLongDate date translations =
- let params =
- [ toString (Date.day date)
- , (getMessage (getMonthKey (Date.month date)) translations)
- , toString (Date.year date)
- ]
- in getParamMessage params "LongDate" translations
-
-renderMonth : Translations -> Month -> String
-renderMonth translations month = getMessage (getMonthKey month) translations
-
-getMonthKey : Month -> String
-getMonthKey month =
- case month of
- Jan -> "January"
- Feb -> "February"
- Mar -> "March"
- Apr -> "April"
- May -> "May"
- Jun -> "June"
- Jul -> "July"
- Aug -> "August"
- Sep -> "September"
- Oct -> "October"
- Nov -> "November"
- Dec -> "December"