aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Home/Header
diff options
context:
space:
mode:
authorJoris2016-06-25 15:10:03 +0200
committerJoris2016-06-25 22:09:04 +0200
commit70720548c9af024dbb6080638ac8e5470c2213eb (patch)
treea149bd6d8f1448de11ac4b0b41c52bc82052035a /src/client/elm/LoggedIn/Home/Header
parent4ce4de89a5400b0d8b9cddaa2922901a081fdaaa (diff)
Use the search to view either punctual or monthly payments
Diffstat (limited to 'src/client/elm/LoggedIn/Home/Header')
-rw-r--r--src/client/elm/LoggedIn/Home/Header/View.elm97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/client/elm/LoggedIn/Home/Header/View.elm b/src/client/elm/LoggedIn/Home/Header/View.elm
new file mode 100644
index 0000000..f9fbb6a
--- /dev/null
+++ b/src/client/elm/LoggedIn/Home/Header/View.elm
@@ -0,0 +1,97 @@
+module LoggedIn.Home.Header.View exposing
+ ( view
+ )
+
+import Html exposing (..)
+import Html.Attributes exposing (..)
+import Html.Events exposing (..)
+import Html.App as Html
+import String
+import Dict
+
+import Form exposing (Form)
+import View.Form as Form
+
+import Msg exposing (Msg)
+import LoggedIn.Msg as LoggedInMsg
+import LoggedIn.Home.Msg as HomeMsg
+
+import LoggedData exposing (LoggedData)
+import LoggedIn.Home.Model as Home
+import Model.Translations exposing (getParamMessage)
+import Model.Conf exposing (Conf)
+import Model.Payment as Payment exposing (Payments, Frequency(..))
+import Model.Translations exposing (getMessage)
+
+import Dialog.AddPayment.View as AddPayment
+
+import LoggedIn.Home.View.ExceedingPayers as ExceedingPayers
+import LoggedIn.View.Format as Format
+import View.Plural exposing (plural)
+
+import Utils.Tuple as Tuple
+
+view : LoggedData -> Home.Model -> Payments -> Frequency -> Html Msg
+view loggedData { search } payments frequency =
+ Html.div
+ [ class "header" ]
+ [ ExceedingPayers.view loggedData
+ , searchLine loggedData search frequency
+ , infos loggedData payments
+ ]
+
+searchLine : LoggedData -> Form String Home.Search -> Frequency -> Html Msg
+searchLine loggedData search frequency =
+ Html.div
+ [ class "searchLine" ]
+ [ searchForm loggedData search
+ , AddPayment.view loggedData frequency
+ ]
+
+searchForm : LoggedData -> Form String Home.Search -> Html Msg
+searchForm loggedData search =
+ let htmlMap = Html.map (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.SearchMsg)
+ in Html.form
+ []
+ [ Form.textInput loggedData.translations search htmlMap "search" "name"
+ , if List.isEmpty (Payment.monthly loggedData.payments)
+ then text ""
+ else Form.radioInputs loggedData.translations search htmlMap "search" "frequency" [ toString Punctual, toString Monthly ]
+ ]
+
+infos : LoggedData -> Payments -> Html Msg
+infos loggedData payments =
+ let paymentsCount = List.length payments
+ in if paymentsCount == 0
+ then text ""
+ else
+ let count = plural loggedData.translations (List.length payments) "Payment" "Payments"
+ sum = paymentsSum loggedData.conf payments
+ in div
+ [ class "infos" ]
+ [ text <| getParamMessage [ count, sum ] "Worth" loggedData.translations
+ , span
+ [ class "partition" ]
+ [ text <| paymentsPartition loggedData payments ]
+ ]
+
+paymentsPartition : LoggedData -> Payments -> String
+paymentsPartition loggedData payments =
+ String.join
+ ", "
+ ( loggedData.users
+ |> Dict.toList
+ |> List.map (Tuple.mapFst (\userId -> Payment.totalPayments (always True) userId payments))
+ |> List.sortBy fst
+ |> List.reverse
+ |> List.map (\(sum, user) ->
+ getParamMessage [ user.name, Format.price loggedData.conf sum ] "By" loggedData.translations
+ )
+ )
+
+paymentsSum : Conf -> Payments -> String
+paymentsSum conf payments =
+ payments
+ |> List.map .cost
+ |> List.sum
+ |> Format.price conf