aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2016-06-19 01:00:53 +0200
committerJoris2016-06-19 01:00:53 +0200
commitfb5629d7f705b7e80dcf1852da58d2864c2b0d25 (patch)
treee9e0d0db119b6f7c2b240226f03ff2d6218070ed
parent9716f77d14ef43f96a1534d97bb9d336df1882be (diff)
downloadbudget-fb5629d7f705b7e80dcf1852da58d2864c2b0d25.tar.gz
budget-fb5629d7f705b7e80dcf1852da58d2864c2b0d25.tar.bz2
budget-fb5629d7f705b7e80dcf1852da58d2864c2b0d25.zip
Show payment count and sum right after search
-rw-r--r--src/client/elm/LoggedIn/Home/Model.elm1
-rw-r--r--src/client/elm/LoggedIn/Home/Search/View.elm50
-rw-r--r--src/client/elm/LoggedIn/Home/Update.elm5
-rw-r--r--src/client/elm/LoggedIn/Home/View.elm20
-rw-r--r--src/client/elm/LoggedIn/Home/View/Monthly.elm2
-rw-r--r--src/client/elm/LoggedIn/Home/View/Paging.elm4
-rw-r--r--src/client/elm/LoggedIn/Home/View/Search.elm26
-rw-r--r--src/client/elm/LoggedIn/Stat/Account/View.elm (renamed from src/client/elm/LoggedIn/Home/Account/View.elm)24
-rw-r--r--src/client/elm/LoggedIn/Stat/View.elm13
-rw-r--r--src/client/elm/Utils/Form.elm11
-rw-r--r--src/client/elm/View/Plural.elm10
-rw-r--r--src/server/Design/LoggedIn/Home.hs20
-rw-r--r--src/server/Design/LoggedIn/Home/Add.hs1
-rw-r--r--src/server/Design/LoggedIn/Home/Monthly.hs (renamed from src/server/Design/LoggedIn/Home/Expandables.hs)10
-rw-r--r--src/server/Design/LoggedIn/Home/Search.hs11
-rw-r--r--src/server/Design/LoggedIn/Stat.hs2
-rw-r--r--src/server/Model/Message/Key.hs2
-rw-r--r--src/server/Model/Message/Translations.hs32
18 files changed, 143 insertions, 101 deletions
diff --git a/src/client/elm/LoggedIn/Home/Model.elm b/src/client/elm/LoggedIn/Home/Model.elm
index a653995..6b29d8c 100644
--- a/src/client/elm/LoggedIn/Home/Model.elm
+++ b/src/client/elm/LoggedIn/Home/Model.elm
@@ -1,5 +1,6 @@
module LoggedIn.Home.Model exposing
( Model
+ , Search
, init
)
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
diff --git a/src/client/elm/LoggedIn/Home/Update.elm b/src/client/elm/LoggedIn/Home/Update.elm
index 302509f..078036d 100644
--- a/src/client/elm/LoggedIn/Home/Update.elm
+++ b/src/client/elm/LoggedIn/Home/Update.elm
@@ -45,7 +45,10 @@ update loggedData action homeModel =
HomeMsg.SearchMsg formMsg ->
( { homeModel
| search = Form.update formMsg homeModel.search
- , currentPage = 1
+ , currentPage =
+ case formMsg of
+ Form.Input "searchText" _ -> 1
+ _ -> homeModel.currentPage
}
, Cmd.none
)
diff --git a/src/client/elm/LoggedIn/Home/View.elm b/src/client/elm/LoggedIn/Home/View.elm
index 5ed54b9..82ec8a3 100644
--- a/src/client/elm/LoggedIn/Home/View.elm
+++ b/src/client/elm/LoggedIn/Home/View.elm
@@ -7,6 +7,7 @@ import Html.Attributes exposing (..)
import Date
import Form
+import Utils.Form as Form
import Msg exposing (Msg)
@@ -14,30 +15,21 @@ import LoggedData exposing (LoggedData)
import Model.Payment as Payment
import LoggedIn.Home.Model as LoggedInModel
-import LoggedIn.Home.Account.View as AccountView
+import LoggedIn.Home.Search.View as SearchView
import LoggedIn.Home.AddPayment.View as AddPaymentView
import LoggedIn.Home.View.Monthly as MonthlyView
-import LoggedIn.Home.View.Search exposing (paymentsSearch)
import LoggedIn.Home.View.Table exposing (paymentsTable)
import LoggedIn.Home.View.Paging exposing (paymentsPaging)
view : LoggedData -> LoggedInModel.Model -> Html Msg
view loggedData loggedIn =
- let searchText =
- Form.getFieldAsString "searchText" loggedIn.search
- |> .value
- |> Maybe.withDefault ""
- punctualPayments = Payment.sortedFiltredPunctual searchText loggedData.payments
+ let punctualPayments = Payment.sortedFiltredPunctual (Form.fieldAsText loggedIn.search "searchText") loggedData.payments
in div
[ class "home" ]
[ AddPaymentView.view loggedData loggedIn
- , div
- [ class "expandables" ]
- [ AccountView.view loggedData loggedIn
- , MonthlyView.view loggedData loggedIn
- ]
- , paymentsSearch loggedData loggedIn
+ , MonthlyView.view loggedData loggedIn
+ , SearchView.view loggedData loggedIn punctualPayments
, paymentsTable loggedData loggedIn punctualPayments
- , paymentsPaging punctualPayments loggedIn
+ , paymentsPaging loggedIn punctualPayments
]
diff --git a/src/client/elm/LoggedIn/Home/View/Monthly.elm b/src/client/elm/LoggedIn/Home/View/Monthly.elm
index 398059c..20dda19 100644
--- a/src/client/elm/LoggedIn/Home/View/Monthly.elm
+++ b/src/client/elm/LoggedIn/Home/View/Monthly.elm
@@ -33,7 +33,7 @@ view loggedData homeModel =
else
div
[ classList
- [ ("monthlyPayments", True)
+ [ ("monthly", True)
, ("detail", homeModel.monthlyDetail)
]
]
diff --git a/src/client/elm/LoggedIn/Home/View/Paging.elm b/src/client/elm/LoggedIn/Home/View/Paging.elm
index fb78810..da69232 100644
--- a/src/client/elm/LoggedIn/Home/View/Paging.elm
+++ b/src/client/elm/LoggedIn/Home/View/Paging.elm
@@ -22,8 +22,8 @@ import Model.Payment as Payment exposing (Payments, perPage)
showedPages : Int
showedPages = 5
-paymentsPaging : Payments -> HomeModel.Model -> Html Msg
-paymentsPaging payments homeModel =
+paymentsPaging : HomeModel.Model -> Payments -> Html Msg
+paymentsPaging homeModel payments =
let maxPage = ceiling (toFloat (List.length payments) / toFloat perPage)
pages = truncatePages homeModel.currentPage [1..maxPage]
in if maxPage == 1
diff --git a/src/client/elm/LoggedIn/Home/View/Search.elm b/src/client/elm/LoggedIn/Home/View/Search.elm
deleted file mode 100644
index 62db1b2..0000000
--- a/src/client/elm/LoggedIn/Home/View/Search.elm
+++ /dev/null
@@ -1,26 +0,0 @@
-module LoggedIn.Home.View.Search exposing
- ( paymentsSearch
- )
-
-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 (getMessage)
-
-paymentsSearch : LoggedData -> HomeModel.Model -> Html Msg
-paymentsSearch loggedData { search } =
- let htmlMap = Html.map (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.SearchMsg)
- in Html.div
- [ class "search" ]
- [ Form.textInput loggedData.translations search htmlMap "searchText" ]
diff --git a/src/client/elm/LoggedIn/Home/Account/View.elm b/src/client/elm/LoggedIn/Stat/Account/View.elm
index fdc1941..3eb5ef4 100644
--- a/src/client/elm/LoggedIn/Home/Account/View.elm
+++ b/src/client/elm/LoggedIn/Stat/Account/View.elm
@@ -1,4 +1,4 @@
-module LoggedIn.Home.Account.View exposing
+module LoggedIn.Stat.Account.View exposing
( view
)
@@ -9,26 +9,22 @@ import Msg exposing (Msg)
import LoggedData exposing (LoggedData)
-import LoggedIn.Home.Model as HomeModel
import LoggedIn.View.Format as Format
import Model exposing (Model)
import Model.User exposing (getUserName)
import Model.Payer exposing (..)
-view : LoggedData -> HomeModel.Model -> Html Msg
-view loggedData homeModel =
- div
- [ class "account" ]
- [ div
- [ class "header" ]
- (List.map (exceedingPayer loggedData homeModel) (getOrderedExceedingPayers loggedData.currentTime loggedData.users loggedData.incomes loggedData.payments))
- ]
+view : LoggedData -> Html Msg
+view loggedData =
+ ul
+ [ class "exceedingPayers" ]
+ (List.map (exceedingPayer loggedData) (getOrderedExceedingPayers loggedData.currentTime loggedData.users loggedData.incomes loggedData.payments))
-exceedingPayer : LoggedData -> HomeModel.Model -> ExceedingPayer -> Html Msg
-exceedingPayer loggedData homeModel payer =
- div
- [ class "exceedingPayer" ]
+exceedingPayer : LoggedData -> ExceedingPayer -> Html Msg
+exceedingPayer loggedData payer =
+ li
+ []
[ span
[ class "userName" ]
[ payer.userId
diff --git a/src/client/elm/LoggedIn/Stat/View.elm b/src/client/elm/LoggedIn/Stat/View.elm
index bb1ec84..f99ef0e 100644
--- a/src/client/elm/LoggedIn/Stat/View.elm
+++ b/src/client/elm/LoggedIn/Stat/View.elm
@@ -19,9 +19,9 @@ import Model.Translations exposing (getMessage, getParamMessage)
import LoggedIn.View.Format as Format
import LoggedIn.View.Date as Date
-
import View.Plural exposing (plural)
-import LoggedIn.View.Format as Format
+
+import LoggedIn.Stat.Account.View as AccountView
import Utils.Tuple as Tuple
import Utils.List as List
@@ -30,7 +30,9 @@ view : LoggedData -> Html Msg
view loggedData =
div
[ class "stat" ]
- [ h1 [] [ text (getMessage "Overall" loggedData.translations) ]
+ [ h1 [] [ text (getMessage "Balance" loggedData.translations) ]
+ , AccountView.view loggedData
+ , h1 [] [ text (getMessage "Overall" loggedData.translations) ]
, paymentsDetail loggedData (Payment.punctual loggedData.payments)
, h1 [] [ text (getMessage "ByMonths" loggedData.translations) ]
, monthsDetail loggedData
@@ -42,10 +44,7 @@ paymentsDetail loggedData payments =
[]
[ li
[]
- [ let single = getMessage "Payment" loggedData.translations
- multiple = getMessage "Payments" loggedData.translations
- in text <| plural (List.length payments) single multiple
- ]
+ [ text <| plural loggedData.translations (List.length payments) "Payment" "Payments" ]
, li
[]
[ text (paymentsSum loggedData.conf payments)
diff --git a/src/client/elm/Utils/Form.elm b/src/client/elm/Utils/Form.elm
new file mode 100644
index 0000000..6793222
--- /dev/null
+++ b/src/client/elm/Utils/Form.elm
@@ -0,0 +1,11 @@
+module Utils.Form exposing
+ ( fieldAsText
+ )
+
+import Form exposing (Form)
+
+fieldAsText : Form a b -> String -> String
+fieldAsText form field =
+ Form.getFieldAsString field form
+ |> .value
+ |> Maybe.withDefault ""
diff --git a/src/client/elm/View/Plural.elm b/src/client/elm/View/Plural.elm
index 727189c..ab91f06 100644
--- a/src/client/elm/View/Plural.elm
+++ b/src/client/elm/View/Plural.elm
@@ -2,6 +2,10 @@ module View.Plural exposing
( plural
)
-plural : Int -> String -> String -> String
-plural n single multiple =
- (toString n) ++ " " ++ if n <= 1 then single else multiple
+import Model.Translations exposing (Translations, getMessage)
+
+plural : Translations -> Int -> String -> String -> String
+plural translations n single multiple =
+ let singleMessage = getMessage single translations
+ multipleMessage = getMessage multiple translations
+ in (toString n) ++ " " ++ if n <= 1 then singleMessage else multipleMessage
diff --git a/src/server/Design/LoggedIn/Home.hs b/src/server/Design/LoggedIn/Home.hs
index c0a8566..47bfc84 100644
--- a/src/server/Design/LoggedIn/Home.hs
+++ b/src/server/Design/LoggedIn/Home.hs
@@ -6,16 +6,16 @@ module Design.LoggedIn.Home
import Clay
-import qualified Design.LoggedIn.Home.Add as AddDesign
-import qualified Design.LoggedIn.Home.Expandables as ExpandablesDesign
-import qualified Design.LoggedIn.Home.Search as SearchDesign
-import qualified Design.LoggedIn.Home.Table as TableDesign
-import qualified Design.LoggedIn.Home.Pages as PagesDesign
+import qualified Design.LoggedIn.Home.Add as Add
+import qualified Design.LoggedIn.Home.Monthly as Monthly
+import qualified Design.LoggedIn.Home.Search as Search
+import qualified Design.LoggedIn.Home.Table as Table
+import qualified Design.LoggedIn.Home.Pages as Pages
design :: Css
design = do
- form # ".addPayment" ? AddDesign.design
- ".expandables" ? ExpandablesDesign.design
- ".search" ? SearchDesign.design
- ".table" ? TableDesign.design
- ".pages" ? PagesDesign.design
+ form # ".addPayment" ? Add.design
+ ".monthly" ? Monthly.design
+ ".search" ? Search.design
+ ".table" ? Table.design
+ ".pages" ? Pages.design
diff --git a/src/server/Design/LoggedIn/Home/Add.hs b/src/server/Design/LoggedIn/Home/Add.hs
index 6856af9..ce64077 100644
--- a/src/server/Design/LoggedIn/Home/Add.hs
+++ b/src/server/Design/LoggedIn/Home/Add.hs
@@ -15,7 +15,6 @@ import Design.Constants
design :: Css
design = do
centeredWithMargin
- marginBottom blockMarginBottom
display flex
"justify-content" -: "center"
diff --git a/src/server/Design/LoggedIn/Home/Expandables.hs b/src/server/Design/LoggedIn/Home/Monthly.hs
index 36ba67d..5e976ef 100644
--- a/src/server/Design/LoggedIn/Home/Expandables.hs
+++ b/src/server/Design/LoggedIn/Home/Monthly.hs
@@ -1,6 +1,6 @@
{-# LANGUAGE OverloadedStrings #-}
-module Design.LoggedIn.Home.Expandables
+module Design.LoggedIn.Home.Monthly
( design
) where
@@ -13,15 +13,11 @@ import Design.Constants
design :: Css
design = do
+ expandBlock Color.gothic Color.white (px inputHeight)
+
".expand" ? do
position absolute
right blockPadding
bottom (px 0)
- ".monthlyPayments" ? expandBlock Color.gothic Color.white (px inputHeight)
-
- ".account" ? do
- expandBlock Color.mossGreen Color.white (px inputHeight)
- ".userName" ? marginRight (px 10)
-
".detail" |> ".header" ? borderRadius radius radius 0 0
diff --git a/src/server/Design/LoggedIn/Home/Search.hs b/src/server/Design/LoggedIn/Home/Search.hs
index 0292eaa..1bc91ef 100644
--- a/src/server/Design/LoggedIn/Home/Search.hs
+++ b/src/server/Design/LoggedIn/Home/Search.hs
@@ -6,11 +6,14 @@ module Design.LoggedIn.Home.Search
import Clay
-import Design.Color as Color
import Design.Constants
-import Design.Helper
design :: Css
design = do
- expandBlock Color.gothic Color.white (px inputHeight)
- ".label" ? marginRight (px 10)
+ marginBottom blockMarginBottom
+ marginLeft (pct blockPercentMargin)
+ marginRight (pct blockPercentMargin)
+
+ ".textInput" ? do
+ display inlineBlock
+ marginRight (px 30)
diff --git a/src/server/Design/LoggedIn/Stat.hs b/src/server/Design/LoggedIn/Stat.hs
index ff44a9d..62028cb 100644
--- a/src/server/Design/LoggedIn/Stat.hs
+++ b/src/server/Design/LoggedIn/Stat.hs
@@ -10,4 +10,6 @@ design :: Css
design = do
h1 ? paddingBottom (px 0)
+ ".exceedingPayers" ? ".userName" ? marginRight (px 5)
+
".mean" ? marginBottom (em 1.5)
diff --git a/src/server/Model/Message/Key.hs b/src/server/Model/Message/Key.hs
index 4ef8663..27a93dd 100644
--- a/src/server/Model/Message/Key.hs
+++ b/src/server/Model/Message/Key.hs
@@ -64,10 +64,12 @@ data Key =
| Payment
| Payments
| SearchText
+ | Worth
-- Statistics
| Statistics
+ | Balance
| Overall
| ByMonths
| By
diff --git a/src/server/Model/Message/Translations.hs b/src/server/Model/Message/Translations.hs
index c7a2043..55ef97b 100644
--- a/src/server/Model/Message/Translations.hs
+++ b/src/server/Model/Message/Translations.hs
@@ -240,15 +240,20 @@ m l Payment =
English -> "payment"
French -> "paiement"
+m l Payments =
+ case l of
+ English -> "payments"
+ French -> "paiements"
+
m l SearchText =
case l of
English -> "Search"
French -> "Recherche"
-m l Payments =
+m l Worth =
case l of
- English -> "payments"
- French -> "paiements"
+ English -> "{1} worth {2}"
+ French -> "{1} valant {2}"
-- Statistics
@@ -257,6 +262,11 @@ m l Statistics =
English -> "Statistics"
French -> "Statistiques"
+m l Balance =
+ case l of
+ English -> "Balance"
+ French -> "Équilibre"
+
m l Overall =
case l of
English -> "Overall"
@@ -274,15 +284,15 @@ m l By =
m l Mean =
case l of
- English -> "Mean: {0}"
- French -> "En moyenne : {0}"
+ English -> "Mean: {1}"
+ French -> "En moyenne : {1}"
-- Income
m l CumulativeIncomesSince =
case l of
- English -> "Cumulative incomes since {0}"
- French -> "Revenus nets cumulés depuis le {0}"
+ English -> "Cumulative incomes since {1}"
+ French -> "Revenus nets cumulés depuis le {1}"
m l Income =
case l of
@@ -338,13 +348,13 @@ m l InvalidInt =
m l SmallerIntThan =
case l of
- English -> "Integer bigger than {0} required"
- French -> "Entier supérieur à {0} requis"
+ English -> "Integer bigger than {1} required"
+ French -> "Entier supérieur à {1} requis"
m l GreaterIntThan =
case l of
- English -> "Integer smaller than {0} required"
- French -> "Entier inférieur à {0} requis"
+ English -> "Integer smaller than {1} required"
+ French -> "Entier inférieur à {1} requis"
-- Http error