diff options
author | Joris | 2016-03-30 00:28:55 +0200 |
---|---|---|
committer | Joris | 2016-03-30 00:28:55 +0200 |
commit | baefda5a902a94cedf84cfcd2ae550267e5d932e (patch) | |
tree | 72fa7b4e6c49d025563e3d7cba1ec13af43aa1c2 /src/client/elm/LoggedIn | |
parent | 76f8b85eb9f796d6df861a04f702ef5f48630795 (diff) |
Merge punctual and monthly payments in client model
Diffstat (limited to 'src/client/elm/LoggedIn')
-rw-r--r-- | src/client/elm/LoggedIn/Action.elm | 10 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/AddPayment/Action.elm | 4 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/AddPayment/Model.elm | 6 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/AddPayment/Update.elm | 2 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/AddPayment/View.elm | 2 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/Model.elm | 2 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/View/Monthly.elm | 10 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/View/Paging.elm | 4 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/View/Table.elm | 1 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Model.elm | 2 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Update.elm | 26 |
11 files changed, 32 insertions, 37 deletions
diff --git a/src/client/elm/LoggedIn/Action.elm b/src/client/elm/LoggedIn/Action.elm index ae72dea..93bb04d 100644 --- a/src/client/elm/LoggedIn/Action.elm +++ b/src/client/elm/LoggedIn/Action.elm @@ -2,7 +2,7 @@ module LoggedIn.Action ( Action(..) ) where -import Model.Payment exposing (Payment, PaymentId, PaymentFrequency) +import Model.Payment exposing (Payment, PaymentId, Frequency) import Model.Income exposing (IncomeId) import LoggedIn.Home.Action as HomeAction @@ -10,9 +10,9 @@ import LoggedIn.Home.Action as HomeAction type Action = NoOp | HomeAction HomeAction.Action - | AddPayment String String PaymentFrequency - | ValidateAddPayment PaymentId String Int PaymentFrequency - | DeletePayment Payment PaymentFrequency - | ValidateDeletePayment Payment PaymentFrequency + | AddPayment String String Frequency + | ValidateAddPayment PaymentId String Int Frequency + | DeletePayment Payment Frequency + | ValidateDeletePayment Payment Frequency | UpdateIncome Int | ValidateUpdateIncome IncomeId Int diff --git a/src/client/elm/LoggedIn/Home/AddPayment/Action.elm b/src/client/elm/LoggedIn/Home/AddPayment/Action.elm index 81c32e2..a692b15 100644 --- a/src/client/elm/LoggedIn/Home/AddPayment/Action.elm +++ b/src/client/elm/LoggedIn/Home/AddPayment/Action.elm @@ -2,11 +2,11 @@ module LoggedIn.Home.AddPayment.Action ( Action(..) ) where -import Model.Payment exposing (PaymentFrequency) +import Model.Payment exposing (Frequency) type Action = NoOp - | Init PaymentFrequency + | Init Frequency | UpdateName String | UpdateCost String | AddError (Maybe String) (Maybe String) diff --git a/src/client/elm/LoggedIn/Home/AddPayment/Model.elm b/src/client/elm/LoggedIn/Home/AddPayment/Model.elm index 22b6883..19933fd 100644 --- a/src/client/elm/LoggedIn/Home/AddPayment/Model.elm +++ b/src/client/elm/LoggedIn/Home/AddPayment/Model.elm @@ -7,18 +7,18 @@ import Result as Result exposing (Result(..)) import Json.Decode exposing ((:=)) import Model.Translations exposing (..) -import Model.Payment exposing (PaymentFrequency(..)) +import Model.Payment exposing (Frequency(..)) type alias Model = { name : String , nameError : Maybe String , cost : String , costError : Maybe String - , frequency : PaymentFrequency + , frequency : Frequency , waitingServer : Bool } -init : PaymentFrequency -> Model +init : Frequency -> Model init frequency = { name = "" , nameError = Nothing diff --git a/src/client/elm/LoggedIn/Home/AddPayment/Update.elm b/src/client/elm/LoggedIn/Home/AddPayment/Update.elm index 473e998..7f5fb0a 100644 --- a/src/client/elm/LoggedIn/Home/AddPayment/Update.elm +++ b/src/client/elm/LoggedIn/Home/AddPayment/Update.elm @@ -10,7 +10,7 @@ import LoggedIn.Home.AddPayment.Action as AddPaymentAction import LoggedIn.Home.AddPayment.Model as AddPaymentModel import Model.Translations exposing (Translations, getMessage) -import Model.Payment exposing (PaymentFrequency(..)) +import Model.Payment exposing (Frequency(..)) update : AddPaymentAction.Action -> AddPaymentModel.Model -> AddPaymentModel.Model update action addPayment = diff --git a/src/client/elm/LoggedIn/Home/AddPayment/View.elm b/src/client/elm/LoggedIn/Home/AddPayment/View.elm index 47dd6e8..562f69b 100644 --- a/src/client/elm/LoggedIn/Home/AddPayment/View.elm +++ b/src/client/elm/LoggedIn/Home/AddPayment/View.elm @@ -16,7 +16,7 @@ import LoggedIn.Home.Model as HomeModel import LoggedIn.Home.AddPayment.Action as AddPaymentAction import LoggedIn.Home.AddPayment.Model as AddPaymentModel -import Model.Payment exposing (PaymentFrequency(..)) +import Model.Payment exposing (Frequency(..)) import Model.Translations exposing (getMessage) import LoggedData exposing (LoggedData) diff --git a/src/client/elm/LoggedIn/Home/Model.elm b/src/client/elm/LoggedIn/Home/Model.elm index 2bcbe9a..cd8b4d0 100644 --- a/src/client/elm/LoggedIn/Home/Model.elm +++ b/src/client/elm/LoggedIn/Home/Model.elm @@ -6,7 +6,7 @@ module LoggedIn.Home.Model import LoggedIn.Home.Model.Payer exposing (Payers) import Model.User exposing (Users, UserId) -import Model.Payment exposing (PaymentId, Payments, PaymentFrequency(..)) +import Model.Payment exposing (PaymentId, Payments, Frequency(..)) import LoggedIn.Home.Account.Model as AccountModel import LoggedIn.Home.AddPayment.Model as AddPaymentModel diff --git a/src/client/elm/LoggedIn/Home/View/Monthly.elm b/src/client/elm/LoggedIn/Home/View/Monthly.elm index 487c05d..c1f3b51 100644 --- a/src/client/elm/LoggedIn/Home/View/Monthly.elm +++ b/src/client/elm/LoggedIn/Home/View/Monthly.elm @@ -15,7 +15,7 @@ import LoggedIn.Home.Model as HomeModel import LoggedIn.Home.View.Price exposing (price) import LoggedIn.Home.View.Expand exposing (..) -import Model.Payment as Payment exposing (Payment) +import Model.Payment as Payment exposing (Payment, monthlyPayments) import Model.Translations exposing (getMessage, getParamMessage) import LoggedData exposing (LoggedData) @@ -26,7 +26,7 @@ import View.Icon exposing (renderIcon) view : LoggedData -> HomeModel.Model -> Html view loggedData homeModel = - if List.length loggedData.monthlyPayments == 0 + if List.length (monthlyPayments loggedData.payments) == 0 then text "" else @@ -44,8 +44,8 @@ view loggedData homeModel = monthlyCount : LoggedData -> HomeModel.Model -> Html monthlyCount loggedData homeModel = - let count = List.length loggedData.monthlyPayments - total = List.sum << List.map .cost <| loggedData.monthlyPayments + let count = List.length (monthlyPayments loggedData.payments) + total = List.sum << List.map .cost <| (monthlyPayments loggedData.payments) key = if count > 1 then "PluralMonthlyCount" else "SingularMonthlyCount" in button [ class "header" @@ -59,7 +59,7 @@ paymentsTable : LoggedData -> HomeModel.Model -> Html paymentsTable loggedData homeModel = div [ class "table" ] - ( loggedData.monthlyPayments + ( (monthlyPayments loggedData.payments) |> List.sortBy (String.toLower << .name) |> List.map (paymentLine loggedData homeModel) ) diff --git a/src/client/elm/LoggedIn/Home/View/Paging.elm b/src/client/elm/LoggedIn/Home/View/Paging.elm index 09a5b62..8433494 100644 --- a/src/client/elm/LoggedIn/Home/View/Paging.elm +++ b/src/client/elm/LoggedIn/Home/View/Paging.elm @@ -15,7 +15,7 @@ import LoggedIn.Home.Model as HomeModel import Action exposing (Action) import LoggedData exposing (LoggedData) -import Model.Payment exposing (Payments, perPage) +import Model.Payment exposing (Payments, perPage, punctualPayments) import View.Icon exposing (renderIcon) @@ -24,7 +24,7 @@ showedPages = 5 paymentsPaging : Address Action -> Payments -> HomeModel.Model -> Html paymentsPaging address payments homeModel = - let maxPage = ceiling (toFloat (List.length payments) / toFloat perPage) + let maxPage = ceiling (toFloat (List.length (punctualPayments payments)) / toFloat perPage) pages = truncatePages homeModel.currentPage [1..maxPage] in if maxPage == 1 then diff --git a/src/client/elm/LoggedIn/Home/View/Table.elm b/src/client/elm/LoggedIn/Home/View/Table.elm index 58f2d0b..c73b428 100644 --- a/src/client/elm/LoggedIn/Home/View/Table.elm +++ b/src/client/elm/LoggedIn/Home/View/Table.elm @@ -46,6 +46,7 @@ headerLine loggedData = paymentLines : LoggedData -> HomeModel.Model -> List Html paymentLines loggedData homeModel = loggedData.payments + |> punctualPayments |> List.sortBy (Date.toTime << .creation) |> List.reverse |> List.drop ((homeModel.currentPage - 1) * perPage) diff --git a/src/client/elm/LoggedIn/Model.elm b/src/client/elm/LoggedIn/Model.elm index 90f1b2b..cc1ade7 100644 --- a/src/client/elm/LoggedIn/Model.elm +++ b/src/client/elm/LoggedIn/Model.elm @@ -17,7 +17,6 @@ type alias Model = , users : Users , me : UserId , payments : Payments - , monthlyPayments : Payments , incomes : Incomes } @@ -27,6 +26,5 @@ init initData = , users = initData.users , me = initData.me , payments = initData.payments - , monthlyPayments = initData.monthlyPayments , incomes = initData.incomes } diff --git a/src/client/elm/LoggedIn/Update.elm b/src/client/elm/LoggedIn/Update.elm index 8fe8d4c..fd141c8 100644 --- a/src/client/elm/LoggedIn/Update.elm +++ b/src/client/elm/LoggedIn/Update.elm @@ -12,7 +12,7 @@ import Date import Model exposing (Model) import Model.Translations exposing (getMessage) -import Model.Payment exposing (Payment, PaymentFrequency(..), deletePayment) +import Model.Payment exposing (Payment, Frequency(..), deletePayment) import Server import LoggedData @@ -74,14 +74,15 @@ update model action loggedIn = LoggedInAction.ValidateAddPayment paymentId name cost frequency -> update model (LoggedInAction.HomeAction <| HomeAction.UpdateAdd <| AddPaymentAction.Init frequency) loggedIn |> flip Effects.andThen (\loggedIn -> - let newPayment = Payment paymentId (Date.fromTime model.currentTime) name cost loggedIn.me - in case frequency of - Punctual -> - update model (LoggedInAction.HomeAction <| HomeAction.UpdatePage 1) loggedIn - |> Tuple.mapFst (\loggedIn -> { loggedIn | payments = newPayment :: loggedIn.payments }) - Monthly -> - update model (LoggedInAction.HomeAction <| HomeAction.ShowMonthlyDetail) loggedIn - |> Tuple.mapFst (\loggedIn -> { loggedIn | monthlyPayments = newPayment :: loggedIn.monthlyPayments }) + case frequency of + Punctual -> + update model (LoggedInAction.HomeAction <| HomeAction.UpdatePage 1) loggedIn + Monthly -> + update model (LoggedInAction.HomeAction <| HomeAction.ShowMonthlyDetail) loggedIn + ) + |> Tuple.mapFst (\loggedIn -> + let newPayment = Payment paymentId (Date.fromTime model.currentTime) name cost loggedIn.me frequency + in { loggedIn | payments = newPayment :: loggedIn.payments } ) LoggedInAction.DeletePayment payment frequency -> @@ -93,15 +94,10 @@ update model action loggedIn = ) LoggedInAction.ValidateDeletePayment payment frequency -> - ( case frequency of - Monthly -> - { loggedIn | monthlyPayments = deletePayment payment.id loggedIn.monthlyPayments } - Punctual -> - { loggedIn | payments = deletePayment payment.id loggedIn.payments } + ( { loggedIn | payments = deletePayment payment.id loggedIn.payments } , Effects.none ) - LoggedInAction.UpdateIncome amount -> ( loggedIn , Server.setIncome amount |