aboutsummaryrefslogtreecommitdiff
path: root/src/client/Update
diff options
context:
space:
mode:
authorJoris2015-09-06 12:39:03 +0200
committerJoris2015-09-06 12:39:03 +0200
commite10531ba4e60c8709088798763ae3bae6608f9c9 (patch)
treef1550fab8833f0b31831ebb2e943a51eeaa41ee2 /src/client/Update
parent24633871359ec9fbd63fdfebf79a6351b2792f77 (diff)
Show montly payments with an expandable mechanism
Diffstat (limited to 'src/client/Update')
-rw-r--r--src/client/Update/LoggedView.elm (renamed from src/client/Update/Payment.elm)31
-rw-r--r--src/client/Update/LoggedView/Add.elm (renamed from src/client/Update/Payment/Add.elm)2
-rw-r--r--src/client/Update/LoggedView/Monthly.elm19
3 files changed, 41 insertions, 11 deletions
diff --git a/src/client/Update/Payment.elm b/src/client/Update/LoggedView.elm
index 2cae679..4a53ac4 100644
--- a/src/client/Update/Payment.elm
+++ b/src/client/Update/LoggedView.elm
@@ -1,6 +1,6 @@
-module Update.Payment
- ( PaymentAction(..)
- , updatePayment
+module Update.LoggedView
+ ( LoggedAction(..)
+ , updateLoggedView
) where
import Date
@@ -13,33 +13,42 @@ import Model.Payers exposing (..)
import Model.View.LoggedView exposing (..)
import Model.View.Payment.Add exposing (..)
-import Update.Payment.Add exposing (..)
+import Update.LoggedView.Add exposing (..)
+import Update.LoggedView.Monthly exposing (..)
-type PaymentAction =
+type LoggedAction =
UpdateAdd AddPaymentAction
| UpdatePayments Payments
- | AddPayment UserId Int Payments
+ | AddPayment UserId PaymentId String Int Frequency Payments
| ToggleEdit PaymentId
| Remove UserId Int Payments
| UpdatePage Int Payments
+ | UpdateMonthly MonthlyAction
-updatePayment : Model -> PaymentAction -> LoggedView -> LoggedView
-updatePayment model action loggedView =
+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 cost 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 | edition <- if loggedView.edition == Just id then Nothing else Just id }
+ { loggedView | paymentEdition <- if loggedView.paymentEdition == Just id then Nothing else Just id }
Remove userId cost payments ->
{ loggedView
| payments <- payments
@@ -51,3 +60,5 @@ updatePayment model action loggedView =
| currentPage <- page
, payments <- payments
}
+ UpdateMonthly monthlyAction ->
+ { loggedView | monthly <- updateMonthly monthlyAction loggedView.monthly }
diff --git a/src/client/Update/Payment/Add.elm b/src/client/Update/LoggedView/Add.elm
index 27f2af0..05c2c30 100644
--- a/src/client/Update/Payment/Add.elm
+++ b/src/client/Update/LoggedView/Add.elm
@@ -1,4 +1,4 @@
-module Update.Payment.Add
+module Update.LoggedView.Add
( AddPaymentAction(..)
, updateAddPayment
) where
diff --git a/src/client/Update/LoggedView/Monthly.elm b/src/client/Update/LoggedView/Monthly.elm
new file mode 100644
index 0000000..8d02c5e
--- /dev/null
+++ b/src/client/Update/LoggedView/Monthly.elm
@@ -0,0 +1,19 @@
+module Update.LoggedView.Monthly
+ ( MonthlyAction(..)
+ , updateMonthly
+ ) where
+
+import Model.Payment exposing (Payment)
+import Model.View.Payment.Monthly exposing (..)
+
+type MonthlyAction =
+ ToggleDetail
+ | AddMonthlyPayment Payment
+
+updateMonthly : MonthlyAction -> Monthly -> Monthly
+updateMonthly action monthly =
+ case action of
+ ToggleDetail ->
+ { monthly | visibleDetail <- not monthly.visibleDetail }
+ AddMonthlyPayment payment ->
+ { monthly | payments <- payment :: monthly.payments }