From 24633871359ec9fbd63fdfebf79a6351b2792f77 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 6 Sep 2015 00:05:50 +0200 Subject: Can add monthly payments, not visible at the moment though, just the count is printed --- src/client/View/Payments/Add.elm | 2 +- src/client/View/Payments/Monthly.elm | 24 ++++++++++++++++++++++++ src/client/View/Payments/Table.elm | 13 ++++++------- 3 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 src/client/View/Payments/Monthly.elm (limited to 'src/client/View/Payments') diff --git a/src/client/View/Payments/Add.elm b/src/client/View/Payments/Add.elm index 085b16d..a22c1f1 100644 --- a/src/client/View/Payments/Add.elm +++ b/src/client/View/Payments/Add.elm @@ -31,7 +31,7 @@ addPayment model loggedView = [ class "add" , case (validateName loggedView.add.name model.translations, validateCost loggedView.add.cost model.translations) of (Ok name, Ok cost) -> - onSubmitPrevDefault serverCommunications.address (SC.AddPayment loggedView.me name cost) + onSubmitPrevDefault serverCommunications.address (SC.AddPayment loggedView.me name cost loggedView.add.frequency) (resName, resCost) -> onSubmitPrevDefault actions.address (UpdatePayment <| UpdateAdd <| AddError (toMaybeError resName) (toMaybeError resCost)) ] diff --git a/src/client/View/Payments/Monthly.elm b/src/client/View/Payments/Monthly.elm new file mode 100644 index 0000000..366af92 --- /dev/null +++ b/src/client/View/Payments/Monthly.elm @@ -0,0 +1,24 @@ +module View.Payments.Monthly + ( monthlyPayments + ) where + +import Html exposing (..) +import Html.Attributes exposing (..) +import Html.Events exposing (..) + +import Model exposing (Model) +import Model.Payment exposing (Payments) +import Model.View.LoggedView exposing (LoggedView) +import Model.Translations exposing (getVarMessage) + +monthlyPayments : Model -> LoggedView -> Html +monthlyPayments model loggedView = + div + [ class "monthlyPayments" ] + [ monthlyCount model loggedView.monthlyPayments ] + +monthlyCount : Model -> Payments -> Html +monthlyCount model monthlyPayments = + let count = List.length monthlyPayments + key = if count > 1 then "PluralMonthlyCount" else "SingularMonthlyCount" + in text (getVarMessage [toString count] key model.translations) diff --git a/src/client/View/Payments/Table.elm b/src/client/View/Payments/Table.elm index 5374c44..4a1ed50 100644 --- a/src/client/View/Payments/Table.elm +++ b/src/client/View/Payments/Table.elm @@ -43,16 +43,15 @@ paymentsTable model loggedView = paymentLines : Model -> LoggedView -> List Html paymentLines model loggedView = loggedView.payments - |> Dict.toList - |> List.sortBy (\(_, payment) -> Date.toTime payment.creation) + |> List.sortBy (Date.toTime << .creation) |> List.reverse |> List.map (paymentLine model loggedView) -paymentLine : Model -> LoggedView -> PaymentWithId -> Html -paymentLine model loggedView (id, payment) = +paymentLine : Model -> LoggedView -> Payment -> Html +paymentLine model loggedView payment = a - [ class ("row " ++ (if loggedView.edition == Just id then "edition" else "")) - , onClick actions.address (UpdatePayment (ToggleEdit id)) + [ class ("row " ++ (if loggedView.edition == Just payment.id then "edition" else "")) + , onClick actions.address (UpdatePayment (ToggleEdit payment.id)) ] [ div [ class "cell category" ] [ text payment.name ] , div [ class "cell cost" ] [ text ((toString payment.cost) ++ " " ++ (getMessage "MoneySymbol" model.translations)) ] @@ -76,7 +75,7 @@ paymentLine model loggedView (id, payment) = then div [ class "cell remove" - , onClick serverCommunications.address (SC.DeletePayment id payment.userId payment.cost loggedView.currentPage) + , onClick serverCommunications.address (SC.DeletePayment payment.id payment.userId payment.cost loggedView.currentPage) ] [ renderIcon "times" ] else -- cgit v1.2.3