diff options
author | Joris | 2016-01-02 22:45:20 +0100 |
---|---|---|
committer | Joris | 2016-01-02 22:45:20 +0100 |
commit | fc9a3ca6a5226f78a3a0ec51af3d8d287ccb2e1b (patch) | |
tree | e05a710b30f749048bb668db1501d2369fa4e666 /src | |
parent | 25d15aacb940c2a19cae3b2e3d8d3ebd1972be02 (diff) |
Merge deletePayment with deleteMonthlyPayment
Diffstat (limited to 'src')
-rw-r--r-- | src/client/elm/Model/Action/LoggedInAction.elm | 7 | ||||
-rw-r--r-- | src/client/elm/Model/Action/MonthlyAction.elm | 4 | ||||
-rw-r--r-- | src/client/elm/Model/Communication.elm | 6 | ||||
-rw-r--r-- | src/client/elm/Model/Payment.elm | 3 | ||||
-rw-r--r-- | src/client/elm/Model/View/LoggedIn/AddPayment.elm | 8 | ||||
-rw-r--r-- | src/client/elm/Model/View/LoggedInView.elm | 2 | ||||
-rw-r--r-- | src/client/elm/ServerCommunication.elm | 13 | ||||
-rw-r--r-- | src/client/elm/Update/LoggedIn.elm | 18 | ||||
-rw-r--r-- | src/client/elm/Update/LoggedIn/AddPayment.elm | 1 | ||||
-rw-r--r-- | src/client/elm/Update/LoggedIn/Monthly.elm | 4 | ||||
-rw-r--r-- | src/client/elm/View/LoggedIn/AddPayment.elm | 1 | ||||
-rw-r--r-- | src/client/elm/View/LoggedIn/Monthly.elm | 4 | ||||
-rw-r--r-- | src/client/elm/View/LoggedIn/Table.elm | 2 |
13 files changed, 37 insertions, 36 deletions
diff --git a/src/client/elm/Model/Action/LoggedInAction.elm b/src/client/elm/Model/Action/LoggedInAction.elm index 00e0a3e..aaf3c7f 100644 --- a/src/client/elm/Model/Action/LoggedInAction.elm +++ b/src/client/elm/Model/Action/LoggedInAction.elm @@ -2,18 +2,17 @@ module Model.Action.LoggedInAction ( LoggedInAction(..) ) where -import Model.Payment exposing (Payments, Payment, PaymentId) +import Model.Payment exposing (Payments, Payment, PaymentId, PaymentFrequency) import Model.Action.MonthlyAction exposing (MonthlyAction) import Model.Action.AccountAction exposing (AccountAction) import Model.Action.AddPaymentAction exposing (AddPaymentAction) -import Model.View.LoggedIn.AddPayment exposing (Frequency) type LoggedInAction = UpdateAdd AddPaymentAction | UpdatePayments Payments - | AddPayment PaymentId String Int Frequency + | AddPayment PaymentId String Int PaymentFrequency + | DeletePayment Payment PaymentFrequency | ToggleEdit PaymentId - | DeletePayment Payment | UpdatePage Int | UpdateMonthly MonthlyAction | UpdateAccount AccountAction diff --git a/src/client/elm/Model/Action/MonthlyAction.elm b/src/client/elm/Model/Action/MonthlyAction.elm index d985ccc..c2de3e5 100644 --- a/src/client/elm/Model/Action/MonthlyAction.elm +++ b/src/client/elm/Model/Action/MonthlyAction.elm @@ -2,9 +2,9 @@ module Model.Action.MonthlyAction ( MonthlyAction(..) ) where -import Model.Payment exposing (Payment, PaymentId) +import Model.Payment exposing (Payment) type MonthlyAction = ToggleDetail | AddPayment Payment - | DeletePayment PaymentId + | DeletePayment Payment diff --git a/src/client/elm/Model/Communication.elm b/src/client/elm/Model/Communication.elm index 616d78f..b8da175 100644 --- a/src/client/elm/Model/Communication.elm +++ b/src/client/elm/Model/Communication.elm @@ -6,12 +6,10 @@ import Time exposing (Time) import Model.User exposing (UserId) import Model.Payment exposing (..) -import Model.View.LoggedIn.AddPayment exposing (Frequency) type Communication = SignIn String - | AddPayment String Int Frequency | SetIncome Time Int - | DeletePayment Payment Int - | DeleteMonthlyPayment PaymentId + | AddPayment String Int PaymentFrequency + | DeletePayment Payment PaymentFrequency | SignOut diff --git a/src/client/elm/Model/Payment.elm b/src/client/elm/Model/Payment.elm index cabdd43..31aba1d 100644 --- a/src/client/elm/Model/Payment.elm +++ b/src/client/elm/Model/Payment.elm @@ -6,6 +6,7 @@ module Model.Payment , paymentsDecoder , paymentIdDecoder , deletePayment + , PaymentFrequency(..) ) where import Date exposing (..) @@ -29,6 +30,8 @@ type alias Payment = type alias PaymentId = Int +type PaymentFrequency = Punctual | Monthly + paymentsDecoder : Json.Decoder Payments paymentsDecoder = Json.list paymentDecoder diff --git a/src/client/elm/Model/View/LoggedIn/AddPayment.elm b/src/client/elm/Model/View/LoggedIn/AddPayment.elm index b70b0c6..fc4d3a0 100644 --- a/src/client/elm/Model/View/LoggedIn/AddPayment.elm +++ b/src/client/elm/Model/View/LoggedIn/AddPayment.elm @@ -1,6 +1,5 @@ module Model.View.LoggedIn.AddPayment ( AddPayment - , Frequency(..) , initAddPayment , validateName , validateCost @@ -11,16 +10,17 @@ import Result as Result exposing (Result(..)) import Utils.Validation exposing (..) import Model.Translations exposing (..) +import Model.Payment exposing (PaymentFrequency(..)) type alias AddPayment = { name : String , nameError : Maybe String , cost : String , costError : Maybe String - , frequency : Frequency + , frequency : PaymentFrequency } -initAddPayment : Frequency -> AddPayment +initAddPayment : PaymentFrequency -> AddPayment initAddPayment frequency = { name = "" , nameError = Nothing @@ -39,5 +39,3 @@ validateCost cost translations = cost |> validateNonEmpty (getMessage "CostRequired" translations) |> flip Result.andThen (validateNumber (getMessage "CostRequired" translations) ((/=) 0)) - -type Frequency = Punctual | Monthly diff --git a/src/client/elm/Model/View/LoggedInView.elm b/src/client/elm/Model/View/LoggedInView.elm index 712ce2d..75285b1 100644 --- a/src/client/elm/Model/View/LoggedInView.elm +++ b/src/client/elm/Model/View/LoggedInView.elm @@ -4,7 +4,7 @@ module Model.View.LoggedInView ) where import Model.User exposing (Users, UserId) -import Model.Payment exposing (Payments) +import Model.Payment exposing (Payments, PaymentFrequency(..)) import Model.Payer exposing (Payers) import Model.View.LoggedIn.AddPayment exposing (..) import Model.View.LoggedIn.Edition exposing (..) diff --git a/src/client/elm/ServerCommunication.elm b/src/client/elm/ServerCommunication.elm index 1cabda5..53612d8 100644 --- a/src/client/elm/ServerCommunication.elm +++ b/src/client/elm/ServerCommunication.elm @@ -18,8 +18,7 @@ import Model.Action as U exposing (Action) import Model.Action.LoggedInAction as UL import Model.Action.MonthlyAction as UM import Model.Action.AccountAction as UA -import Model.View.LoggedIn.AddPayment exposing (Frequency(..)) -import Model.Payment exposing (PaymentId, paymentIdDecoder, Payments, paymentsDecoder) +import Model.Payment exposing (..) import Model.Payer exposing (Payers, payersDecoder) import Model.User exposing (Users, usersDecoder, UserId, userIdDecoder) @@ -38,13 +37,9 @@ sendRequest communication = |> flip Task.andThen (decodeHttpValue <| "id" := paymentIdDecoder) |> Task.map (\paymentId -> (U.UpdateLoggedIn (UL.AddPayment paymentId name cost frequency))) - DeletePayment payment currentPage -> + DeletePayment payment frequency -> post (deletePaymentURL payment.id) - |> Task.map (always (U.UpdateLoggedIn (UL.DeletePayment payment))) - - DeleteMonthlyPayment id -> - post (deletePaymentURL id) - |> Task.map (always (U.UpdateLoggedIn (UL.UpdateMonthly (UM.DeletePayment id)))) + |> Task.map (always (U.UpdateLoggedIn (UL.DeletePayment payment frequency))) SetIncome currentTime amount -> post ("/income?amount=" ++ (toString amount)) @@ -54,7 +49,7 @@ sendRequest communication = post "/signOut" |> Task.map (always U.GoSignInView) -addPaymentURL : String -> Int -> Frequency -> String +addPaymentURL : String -> Int -> PaymentFrequency -> String addPaymentURL name cost frequency = "/payment/add?name=" ++ name ++ "&cost=" ++ (toString cost) ++ "&frequency=" ++ (toString frequency) diff --git a/src/client/elm/Update/LoggedIn.elm b/src/client/elm/Update/LoggedIn.elm index ca4690b..704dd7f 100644 --- a/src/client/elm/Update/LoggedIn.elm +++ b/src/client/elm/Update/LoggedIn.elm @@ -44,12 +44,18 @@ updateLoggedIn model action loggedInView = } ToggleEdit id -> { loggedInView | paymentEdition = if loggedInView.paymentEdition == Just id then Nothing else Just id } - DeletePayment payment -> - { loggedInView - | account = updateAccount (UpdatePayer payment.userId (Date.toTime payment.creation) -payment.cost) loggedInView.account - , payments = deletePayment payment.id loggedInView.payments - , paymentsCount = loggedInView.paymentsCount - 1 - } + DeletePayment payment frequency -> + case frequency of + Monthly -> + { loggedInView + | monthly = updateMonthly (Monthly.DeletePayment payment) loggedInView.monthly + } + Punctual -> + { loggedInView + | account = updateAccount (UpdatePayer payment.userId (Date.toTime payment.creation) -payment.cost) loggedInView.account + , payments = deletePayment payment.id loggedInView.payments + , paymentsCount = loggedInView.paymentsCount - 1 + } UpdatePage page -> { loggedInView | currentPage = page diff --git a/src/client/elm/Update/LoggedIn/AddPayment.elm b/src/client/elm/Update/LoggedIn/AddPayment.elm index 62eda85..978980d 100644 --- a/src/client/elm/Update/LoggedIn/AddPayment.elm +++ b/src/client/elm/Update/LoggedIn/AddPayment.elm @@ -4,6 +4,7 @@ module Update.LoggedIn.AddPayment import Model.Action.AddPaymentAction exposing (..) import Model.View.LoggedIn.AddPayment exposing (..) +import Model.Payment exposing (PaymentFrequency(..)) updateAddPayment : AddPaymentAction -> AddPayment -> AddPayment updateAddPayment action addPayment = diff --git a/src/client/elm/Update/LoggedIn/Monthly.elm b/src/client/elm/Update/LoggedIn/Monthly.elm index 2505091..3741e1f 100644 --- a/src/client/elm/Update/LoggedIn/Monthly.elm +++ b/src/client/elm/Update/LoggedIn/Monthly.elm @@ -15,7 +15,7 @@ updateMonthly action monthly = | payments = payment :: monthly.payments , visibleDetail = True } - DeletePayment id -> + DeletePayment payment -> { monthly - | payments = List.filter (\payment -> payment.id /= id) monthly.payments + | payments = List.filter (((/=) payment.id) << .id) monthly.payments } diff --git a/src/client/elm/View/LoggedIn/AddPayment.elm b/src/client/elm/View/LoggedIn/AddPayment.elm index cbc93a1..5739a95 100644 --- a/src/client/elm/View/LoggedIn/AddPayment.elm +++ b/src/client/elm/View/LoggedIn/AddPayment.elm @@ -11,6 +11,7 @@ import Html.Attributes exposing (..) import Html.Events exposing (..) import Model exposing (Model) +import Model.Payment exposing (PaymentFrequency(..)) import Model.Translations exposing (getMessage) import Model.Action exposing (..) import Model.Action.LoggedInAction exposing (..) diff --git a/src/client/elm/View/LoggedIn/Monthly.elm b/src/client/elm/View/LoggedIn/Monthly.elm index 2c11993..c0294d7 100644 --- a/src/client/elm/View/LoggedIn/Monthly.elm +++ b/src/client/elm/View/LoggedIn/Monthly.elm @@ -10,7 +10,7 @@ import Html.Attributes exposing (..) import Html.Events exposing (..) import Model exposing (Model) -import Model.Payment exposing (Payments, Payment) +import Model.Payment as Payment exposing (Payments, Payment) import Model.Translations exposing (getMessage, getParamMessage) import Model.Action exposing (..) import Model.Action.LoggedInAction exposing (..) @@ -81,7 +81,7 @@ paymentLine address model loggedInView payment = [ text (price model payment.cost) ] , div [ class "cell delete" - , onClick address (ServerCommunication <| Communication.DeleteMonthlyPayment payment.id) + , onClick address (ServerCommunication <| Communication.DeletePayment payment Payment.Monthly) ] [ button [] [ renderIcon "times" ] ] diff --git a/src/client/elm/View/LoggedIn/Table.elm b/src/client/elm/View/LoggedIn/Table.elm index 8590dc5..cb3969b 100644 --- a/src/client/elm/View/LoggedIn/Table.elm +++ b/src/client/elm/View/LoggedIn/Table.elm @@ -88,7 +88,7 @@ paymentLine address model loggedInView payment = div [ class "cell delete" ] [ button - [ onClick address (ServerCommunication <| Communication.DeletePayment payment loggedInView.currentPage) ] + [ onClick address (ServerCommunication <| Communication.DeletePayment payment Punctual)] [ renderIcon "times" ] ] else |