aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2016-03-30 14:17:59 +0200
committerJoris2016-03-30 14:17:59 +0200
commitc542551ad043260e6a4a6569b4af5c748f7b6001 (patch)
tree1b305d3d5c7280e34d19ef04365b47200e1bae9f
parentbaefda5a902a94cedf84cfcd2ae550267e5d932e (diff)
downloadbudget-c542551ad043260e6a4a6569b4af5c748f7b6001.tar.gz
budget-c542551ad043260e6a4a6569b4af5c748f7b6001.tar.bz2
budget-c542551ad043260e6a4a6569b4af5c748f7b6001.zip
Filter own monthly payments in view
-rw-r--r--src/client/elm/LoggedIn/Home/View/Monthly.elm45
-rw-r--r--src/client/elm/LoggedIn/Home/View/Paging.elm4
-rw-r--r--src/client/elm/LoggedIn/Home/View/Table.elm5
-rw-r--r--src/client/elm/Model/Payment.elm12
4 files changed, 33 insertions, 33 deletions
diff --git a/src/client/elm/LoggedIn/Home/View/Monthly.elm b/src/client/elm/LoggedIn/Home/View/Monthly.elm
index c1f3b51..aa0e3a5 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, monthlyPayments)
+import Model.Payment as Payment exposing (Payments, Payment, monthly)
import Model.Translations exposing (getMessage, getParamMessage)
import LoggedData exposing (LoggedData)
@@ -26,26 +26,27 @@ import View.Icon exposing (renderIcon)
view : LoggedData -> HomeModel.Model -> Html
view loggedData homeModel =
- if List.length (monthlyPayments loggedData.payments) == 0
- then
- text ""
- else
- div
- [ classList
- [ ("monthlyPayments", True)
- , ("detail", homeModel.monthlyDetail)
+ let monthlyPayments = Payment.monthly loggedData.me loggedData.payments
+ in if List.length monthlyPayments == 0
+ then
+ text ""
+ else
+ div
+ [ classList
+ [ ("monthlyPayments", True)
+ , ("detail", homeModel.monthlyDetail)
+ ]
+ ]
+ [ monthlyCount loggedData monthlyPayments homeModel
+ , if homeModel.monthlyDetail
+ then paymentsTable loggedData monthlyPayments homeModel
+ else text ""
]
- ]
- [ monthlyCount loggedData homeModel
- , if homeModel.monthlyDetail
- then paymentsTable loggedData homeModel
- else text ""
- ]
-monthlyCount : LoggedData -> HomeModel.Model -> Html
-monthlyCount loggedData homeModel =
- let count = List.length (monthlyPayments loggedData.payments)
- total = List.sum << List.map .cost <| (monthlyPayments loggedData.payments)
+monthlyCount : LoggedData -> Payments -> HomeModel.Model -> Html
+monthlyCount loggedData monthlyPayments homeModel =
+ let count = List.length monthlyPayments
+ total = List.sum << List.map .cost <| monthlyPayments
key = if count > 1 then "PluralMonthlyCount" else "SingularMonthlyCount"
in button
[ class "header"
@@ -55,11 +56,11 @@ monthlyCount loggedData homeModel =
, expand ExpandDown homeModel.monthlyDetail
]
-paymentsTable : LoggedData -> HomeModel.Model -> Html
-paymentsTable loggedData homeModel =
+paymentsTable : LoggedData -> Payments -> HomeModel.Model -> Html
+paymentsTable loggedData monthlyPayments homeModel =
div
[ class "table" ]
- ( (monthlyPayments loggedData.payments)
+ ( monthlyPayments
|> 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 8433494..0385941 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, punctualPayments)
+import Model.Payment as Payment exposing (Payments, perPage)
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 (punctualPayments payments)) / toFloat perPage)
+ let maxPage = ceiling (toFloat (List.length (Payment.punctual 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 c73b428..1d69fb9 100644
--- a/src/client/elm/LoggedIn/Home/View/Table.elm
+++ b/src/client/elm/LoggedIn/Home/View/Table.elm
@@ -20,7 +20,7 @@ import LoggedIn.Home.View.Date exposing (..)
import LoggedIn.Home.View.Price exposing (price)
import Model.User exposing (getUserName)
-import Model.Payment exposing (..)
+import Model.Payment as Payment exposing (..)
import Action
import Mailbox
@@ -45,8 +45,7 @@ headerLine loggedData =
paymentLines : LoggedData -> HomeModel.Model -> List Html
paymentLines loggedData homeModel =
- loggedData.payments
- |> punctualPayments
+ Payment.punctual loggedData.payments
|> List.sortBy (Date.toTime << .creation)
|> List.reverse
|> List.drop ((homeModel.currentPage - 1) * perPage)
diff --git a/src/client/elm/Model/Payment.elm b/src/client/elm/Model/Payment.elm
index e792c6c..27d5bed 100644
--- a/src/client/elm/Model/Payment.elm
+++ b/src/client/elm/Model/Payment.elm
@@ -8,8 +8,8 @@ module Model.Payment
, paymentIdDecoder
, deletePayment
, totalPayments
- , punctualPayments
- , monthlyPayments
+ , punctual
+ , monthly
) where
import Date exposing (..)
@@ -76,8 +76,8 @@ totalPayments paymentFilter userId payments =
|> List.map .cost
|> List.sum
-punctualPayments : Payments -> Payments
-punctualPayments = List.filter ((==) Punctual << .frequency)
+punctual : Payments -> Payments
+punctual = List.filter ((==) Punctual << .frequency)
-monthlyPayments : Payments -> Payments
-monthlyPayments = List.filter ((==) Monthly << .frequency)
+monthly : UserId -> Payments -> Payments
+monthly userId = List.filter (\p -> p.frequency == Monthly && p.userId == userId)