From 6541fa5316816d6f97a87a370775cfe278e7eeb8 Mon Sep 17 00:00:00 2001 From: Joris Date: Thu, 7 Apr 2016 23:58:23 +0200 Subject: Add cumulative incomes by user --- src/client/elm/LoggedIn/Income/View.elm | 43 +++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'src/client/elm/LoggedIn/Income') diff --git a/src/client/elm/LoggedIn/Income/View.elm b/src/client/elm/LoggedIn/Income/View.elm index f62902a..9e77fde 100644 --- a/src/client/elm/LoggedIn/Income/View.elm +++ b/src/client/elm/LoggedIn/Income/View.elm @@ -4,6 +4,7 @@ module LoggedIn.Income.View import Dict import Date +import Time exposing (Time) import Html exposing (..) import Html.Events exposing (..) @@ -13,8 +14,10 @@ import Form.Input as Input import LoggedData exposing (LoggedData) -import Model.Income exposing (IncomeId, Income) -import Model.Translations exposing (getMessage) +import Model.Income exposing (IncomeId, Income, userCumulativeIncomeSince) +import Model.Translations exposing (getMessage, getParamMessage) +import Model.Payer exposing (useIncomesFrom) +import Model.User exposing (UserId, User) import LoggedIn.Income.Model as IncomeModel import Mailbox @@ -28,16 +31,46 @@ import LoggedIn.View.Format as Format import Utils.Maybe exposing (isJust) +import LoggedIn.View.Date exposing (renderLongDate) +import View.Events exposing (onSubmitPrevDefault) + view : LoggedData -> IncomeModel.Model -> Html view loggedData incomeModel = div [ class "income" ] - [ h1 [] [ text <| getMessage "AddIncome" loggedData.translations ] + [ case useIncomesFrom loggedData.users loggedData.incomes loggedData.payments of + Just since -> cumulativeIncomesView loggedData since + Nothing -> text "" + , h1 [] [ text <| getMessage "AddIncome" loggedData.translations ] , addIncomeView loggedData incomeModel.addIncome , h1 [] [ text <| getMessage "MonthlyNetIncomes" loggedData.translations ] , incomesView loggedData ] +cumulativeIncomesView : LoggedData -> Time -> Html +cumulativeIncomesView loggedData since = + let longDate = renderLongDate (Date.fromTime since) loggedData.translations + in div + [] + [ h1 [] [ text <| getParamMessage [longDate] "CumulativeIncomesSince" loggedData.translations ] + , ul + [] + ( Dict.toList loggedData.users + |> List.map (\(userId, user) -> + (user.name, userCumulativeIncomeSince loggedData.currentTime since loggedData.incomes userId) + ) + |> List.sortBy snd + |> List.map (\(userName, cumulativeIncome) -> + li + [] + [ text userName + , text ": " + , text <| Format.price loggedData.conf cumulativeIncome + ] + ) + ) + ] + addIncomeView : LoggedData -> Form () IncomeModel.AddIncome -> Html addIncomeView loggedData addIncome = let @@ -49,8 +82,8 @@ addIncomeView loggedData addIncome = creation = Form.getFieldAsString "creation" addIncome amount = Form.getFieldAsString "amount" addIncome in - div - [] + Html.form + [ onSubmitPrevDefault Mailbox.address Action.NoOp ] [ label [] [ text "Creation" ] , Input.textInput creation formAddress [] , errorFor "DateValidationError" creation -- cgit v1.2.3