From e10531ba4e60c8709088798763ae3bae6608f9c9 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 6 Sep 2015 12:39:03 +0200 Subject: Show montly payments with an expandable mechanism --- src/client/Update/LoggedView.elm | 64 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/client/Update/LoggedView.elm (limited to 'src/client/Update/LoggedView.elm') diff --git a/src/client/Update/LoggedView.elm b/src/client/Update/LoggedView.elm new file mode 100644 index 0000000..4a53ac4 --- /dev/null +++ b/src/client/Update/LoggedView.elm @@ -0,0 +1,64 @@ +module Update.LoggedView + ( LoggedAction(..) + , updateLoggedView + ) where + +import Date +import Dict + +import Model exposing (Model) +import Model.User exposing (UserId) +import Model.Payment exposing (..) +import Model.Payers exposing (..) +import Model.View.LoggedView exposing (..) +import Model.View.Payment.Add exposing (..) + +import Update.LoggedView.Add exposing (..) +import Update.LoggedView.Monthly exposing (..) + +type LoggedAction = + UpdateAdd AddPaymentAction + | UpdatePayments Payments + | AddPayment UserId PaymentId String Int Frequency Payments + | ToggleEdit PaymentId + | Remove UserId Int Payments + | UpdatePage Int Payments + | UpdateMonthly MonthlyAction + +updateLoggedView : Model -> LoggedAction -> LoggedView -> LoggedView +updateLoggedView model action loggedView = + case action of + UpdateAdd addPaymentAction -> + { loggedView | add <- updateAddPayment addPaymentAction loggedView.add } + UpdatePayments payments -> + { loggedView | payments <- payments } + AddPayment userId paymentId name cost frequency payments -> + { loggedView + | payments <- payments + , currentPage <- 1 + , add <- initAddPayment loggedView.add.frequency + , payers <- updatePayers loggedView.payers userId cost + , paymentsCount <- loggedView.paymentsCount + 1 + , monthly <- + if frequency == Monthly + then + let payment = Payment paymentId (Date.fromTime model.currentTime) name cost userId + in updateMonthly (AddMonthlyPayment payment) loggedView.monthly + else + loggedView.monthly + } + ToggleEdit id -> + { loggedView | paymentEdition <- if loggedView.paymentEdition == Just id then Nothing else Just id } + Remove userId cost payments -> + { loggedView + | payments <- payments + , payers <- updatePayers loggedView.payers userId -cost + , paymentsCount <- loggedView.paymentsCount - 1 + } + UpdatePage page payments -> + { loggedView + | currentPage <- page + , payments <- payments + } + UpdateMonthly monthlyAction -> + { loggedView | monthly <- updateMonthly monthlyAction loggedView.monthly } -- cgit v1.2.3