From c542551ad043260e6a4a6569b4af5c748f7b6001 Mon Sep 17 00:00:00 2001 From: Joris Date: Wed, 30 Mar 2016 14:17:59 +0200 Subject: Filter own monthly payments in view --- src/client/elm/LoggedIn/Home/View/Monthly.elm | 45 ++++++++++++++------------- src/client/elm/LoggedIn/Home/View/Paging.elm | 4 +-- src/client/elm/LoggedIn/Home/View/Table.elm | 5 ++- 3 files changed, 27 insertions(+), 27 deletions(-) (limited to 'src/client/elm/LoggedIn/Home') 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) -- cgit v1.2.3