aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Home/Search
diff options
context:
space:
mode:
authorJoris2016-06-19 01:00:53 +0200
committerJoris2016-06-19 01:00:53 +0200
commitfb5629d7f705b7e80dcf1852da58d2864c2b0d25 (patch)
treee9e0d0db119b6f7c2b240226f03ff2d6218070ed /src/client/elm/LoggedIn/Home/Search
parent9716f77d14ef43f96a1534d97bb9d336df1882be (diff)
Show payment count and sum right after search
Diffstat (limited to 'src/client/elm/LoggedIn/Home/Search')
-rw-r--r--src/client/elm/LoggedIn/Home/Search/View.elm50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/client/elm/LoggedIn/Home/Search/View.elm b/src/client/elm/LoggedIn/Home/Search/View.elm
new file mode 100644
index 0000000..f06377d
--- /dev/null
+++ b/src/client/elm/LoggedIn/Home/Search/View.elm
@@ -0,0 +1,50 @@
+module LoggedIn.Home.Search.View exposing
+ ( view
+ )
+
+import Html exposing (..)
+import Html.Attributes exposing (..)
+import Html.Events exposing (..)
+import Html.App as Html
+
+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 HomeModel
+import Model.Translations exposing (getParamMessage)
+import Model.Conf exposing (Conf)
+import Model.Payment exposing (Payments)
+
+import LoggedIn.View.Format as Format
+import View.Plural exposing (plural)
+
+view : LoggedData -> HomeModel.Model -> Payments -> Html Msg
+view loggedData { search } payments =
+ Html.div
+ [ class "search" ]
+ [ searchForm loggedData search
+ , paymentsStat loggedData payments
+ ]
+
+searchForm : LoggedData -> Form String HomeModel.Search -> Html Msg
+searchForm loggedData search =
+ let htmlMap = Html.map (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.SearchMsg)
+ in Form.textInput loggedData.translations search htmlMap "searchText"
+
+paymentsStat : LoggedData -> Payments -> Html Msg
+paymentsStat loggedData payments =
+ let count = plural loggedData.translations (List.length payments) "Payment" "Payments"
+ sum = paymentsSum loggedData.conf payments
+ in text <| getParamMessage [ count, sum ] "Worth" loggedData.translations
+
+paymentsSum : Conf -> Payments -> String
+paymentsSum conf payments =
+ payments
+ |> List.map .cost
+ |> List.sum
+ |> Format.price conf