aboutsummaryrefslogtreecommitdiff
path: root/src/client/View/LoggedIn/Account.elm
blob: e2b8e7edc5ae9444445f13b484f4a0fee49e4a86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module View.LoggedIn.Account
  ( account
  ) where

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import List

import Update exposing (..)
import Update.LoggedIn exposing (..)
import Update.LoggedIn.Account exposing (..)

import Model exposing (Model)
import Model.User exposing (getUserName)
import Model.Payers exposing (..)
import Model.View.LoggedInView exposing (LoggedInView)
import Model.Translations exposing (getParamMessage, getMessage)
import Model.View.LoggedIn.Account exposing (Account)

import View.Expand exposing (..)
import View.Price exposing (price)

account : Model -> LoggedInView -> Html
account model loggedInView =
  let account = loggedInView.account
  in  div
        [ classList
            [ ("account", True)
            , ("detail", account.visibleDetail)
            ]
        ]
        [ exceedingPayers model loggedInView
        , if account.visibleDetail
            then income model account
            else text ""
        ]

exceedingPayers : Model -> LoggedInView -> Html
exceedingPayers model loggedInView =
  button
    [ class "exceedingPayers"
    , onClick actions.address (UpdateLoggedIn << UpdateAccount <| ToggleDetail)
    ]
    (  (List.map (exceedingPayer model loggedInView) (getOrderedExceedingPayers loggedInView.account.payers))
    ++ [ expand ExpandDown loggedInView.account.visibleDetail ]
    )

exceedingPayer : Model -> LoggedInView -> ExceedingPayer -> Html
exceedingPayer model loggedInView payer =
  div
    [ class "exceedingPayer" ]
    [ span
        [ class "userName" ]
        [ payer.userId
            |> getUserName loggedInView.users
            |> Maybe.withDefault "−"
            |> text
        ]
    , span
        [ class "amount" ]
        [ text ("+ " ++ (price model payer.amount)) ]
    ]

income : Model -> Account -> Html
income model account =
  div
    [ class "income" ]
    ( case account.income of
        Nothing ->
          [ text (getMessage "NoIncome" model.translations) ]
        Just income ->
          [ text (getParamMessage [price model income] "Income" model.translations) ]
    )