diff options
author | Joris | 2016-06-04 11:02:43 +0200 |
---|---|---|
committer | Joris | 2016-06-04 11:02:43 +0200 |
commit | 38896af4281d2e191cbde15836a23e4c0274fff6 (patch) | |
tree | 0d7df152cc84beaa79cc9fa055db1e7992c4ac91 | |
parent | 9dfa7a7e2c6fac564a456b11623c04d0b26fbce5 (diff) |
Add mean payment by month
-rw-r--r-- | src/client/elm/LoggedIn/Home/View/Paging.elm | 13 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/View/Table.elm | 6 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Stat/View.elm | 34 | ||||
-rw-r--r-- | src/client/elm/Utils/List.elm | 4 | ||||
-rw-r--r-- | src/client/js/main.js | 4 | ||||
-rw-r--r-- | src/server/Design/LoggedIn/Home/Expandables.hs | 2 | ||||
-rw-r--r-- | src/server/Design/LoggedIn/Home/Table.hs | 6 | ||||
-rw-r--r-- | src/server/Design/LoggedIn/Stat.hs | 5 | ||||
-rw-r--r-- | src/server/Model/Message/Key.hs | 1 | ||||
-rw-r--r-- | src/server/Model/Message/Translations.hs | 5 |
10 files changed, 58 insertions, 22 deletions
diff --git a/src/client/elm/LoggedIn/Home/View/Paging.elm b/src/client/elm/LoggedIn/Home/View/Paging.elm index b8d7db9..9166d23 100644 --- a/src/client/elm/LoggedIn/Home/View/Paging.elm +++ b/src/client/elm/LoggedIn/Home/View/Paging.elm @@ -2,7 +2,7 @@ module LoggedIn.Home.View.Paging exposing ( paymentsPaging ) -import Color +import Color exposing (Color) import FontAwesome @@ -60,7 +60,7 @@ firstPage homeModel = ] , onClick (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.UpdatePage <| 1) ] - [ FontAwesome.fast_backward Color.darkGrey 20 ] + [ FontAwesome.fast_backward grey 20 ] previousPage : HomeModel.Model -> Html Msg previousPage homeModel = @@ -71,7 +71,7 @@ previousPage homeModel = then (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.UpdatePage <| homeModel.currentPage - 1) else Msg.NoOp ] - [ FontAwesome.backward Color.darkGrey 20 ] + [ FontAwesome.backward grey 20 ] nextPage : HomeModel.Model -> Int -> Html Msg nextPage homeModel maxPage = @@ -82,7 +82,7 @@ nextPage homeModel maxPage = then (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.UpdatePage <| homeModel.currentPage + 1) else Msg.NoOp ] - [ FontAwesome.forward Color.darkGrey 20 ] + [ FontAwesome.forward grey 20 ] lastPage : HomeModel.Model -> Int -> Html Msg lastPage homeModel maxPage = @@ -90,7 +90,7 @@ lastPage homeModel maxPage = [ class "page" , onClick (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.UpdatePage <| maxPage) ] - [ FontAwesome.fast_forward Color.darkGrey 20 ] + [ FontAwesome.fast_forward grey 20 ] paymentsPage : HomeModel.Model -> Int -> Html Msg paymentsPage homeModel page = @@ -106,3 +106,6 @@ paymentsPage homeModel page = else Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.UpdatePage <| page ] [ text (toString page) ] + +grey : Color +grey = Color.greyscale 0.35 diff --git a/src/client/elm/LoggedIn/Home/View/Table.elm b/src/client/elm/LoggedIn/Home/View/Table.elm index 7c8a800..a03faa2 100644 --- a/src/client/elm/LoggedIn/Home/View/Table.elm +++ b/src/client/elm/LoggedIn/Home/View/Table.elm @@ -37,10 +37,10 @@ headerLine : LoggedData -> Html Msg headerLine loggedData = div [ class "header" ] - [ div [ class "cell category" ] [ FontAwesome.shopping_cart Color.white 25 ] + [ div [ class "cell category" ] [ FontAwesome.shopping_cart Color.white 28 ] , div [ class "cell cost" ] [ text loggedData.conf.currency ] - , div [ class "cell user" ] [ FontAwesome.user Color.white 25 ] - , div [ class "cell date" ] [ FontAwesome.calendar Color.white 25 ] + , div [ class "cell user" ] [ FontAwesome.user Color.white 28 ] + , div [ class "cell date" ] [ FontAwesome.calendar Color.white 28 ] , div [ class "cell" ] [] ] diff --git a/src/client/elm/LoggedIn/Stat/View.elm b/src/client/elm/LoggedIn/Stat/View.elm index 77a32a0..bb1ec84 100644 --- a/src/client/elm/LoggedIn/Stat/View.elm +++ b/src/client/elm/LoggedIn/Stat/View.elm @@ -15,7 +15,7 @@ import Msg exposing (Msg) import Model.Payment as Payment exposing (Payments) import Model.Conf exposing (Conf) -import Model.Translations exposing (getMessage) +import Model.Translations exposing (getMessage, getParamMessage) import LoggedIn.View.Format as Format import LoggedIn.View.Date as Date @@ -24,6 +24,7 @@ import View.Plural exposing (plural) import LoggedIn.View.Format as Format import Utils.Tuple as Tuple +import Utils.List as List view : LoggedData -> Html Msg view loggedData = @@ -74,12 +75,31 @@ totalPayments loggedData = monthsDetail : LoggedData -> Html Msg monthsDetail loggedData = - ul - [] - ( Payment.punctual loggedData.payments - |> Payment.groupAndSortByMonth - |> List.map (monthDetail loggedData) - ) + let paymentsByMonth = + loggedData.payments + |> Payment.punctual + |> Payment.groupAndSortByMonth + monthPaymentMean = + paymentsByMonth + |> List.filter (\((month, year), _) -> + let currentDate = Date.fromTime loggedData.currentTime + in not (Date.month currentDate == month && Date.year currentDate == year) + ) + |> List.map (List.sum << List.map .cost << snd) + |> List.mean + in div + [] + [ div + [ class "mean" ] + [ text (getParamMessage [ Format.price loggedData.conf monthPaymentMean ] "Mean" loggedData.translations) + ] + , ul + [] + ( Payment.punctual loggedData.payments + |> Payment.groupAndSortByMonth + |> List.map (monthDetail loggedData) + ) + ] monthDetail : LoggedData -> ((Month, Int), Payments) -> Html Msg monthDetail loggedData ((month, year), payments) = diff --git a/src/client/elm/Utils/List.elm b/src/client/elm/Utils/List.elm index 4886418..cc57d9f 100644 --- a/src/client/elm/Utils/List.elm +++ b/src/client/elm/Utils/List.elm @@ -1,5 +1,6 @@ module Utils.List exposing ( groupBy + , mean ) import Dict @@ -11,3 +12,6 @@ groupBy f xs = in Dict.insert (f item) (item :: groupItems) dict in List.foldr addItem Dict.empty xs |> Dict.toList + +mean : List Int -> Int +mean xs = (List.sum xs) // (List.length xs) diff --git a/src/client/js/main.js b/src/client/js/main.js index 839c33a..04ccfd0 100644 --- a/src/client/js/main.js +++ b/src/client/js/main.js @@ -1,11 +1,11 @@ -// Remove query params +// Remove search query window.history.pushState( { html: document.documentElement.innerHTML, pageTitle: document.title }, '', - document.location.pathname + document.location.pathname + document.location.hash ); var app = Elm.Main.fullscreen({ diff --git a/src/server/Design/LoggedIn/Home/Expandables.hs b/src/server/Design/LoggedIn/Home/Expandables.hs index 635a4a7..36ba67d 100644 --- a/src/server/Design/LoggedIn/Home/Expandables.hs +++ b/src/server/Design/LoggedIn/Home/Expandables.hs @@ -16,7 +16,7 @@ design = do ".expand" ? do position absolute right blockPadding - bottom (px 2) + bottom (px 0) ".monthlyPayments" ? expandBlock Color.gothic Color.white (px inputHeight) diff --git a/src/server/Design/LoggedIn/Home/Table.hs b/src/server/Design/LoggedIn/Home/Table.hs index d13ab85..b68f48f 100644 --- a/src/server/Design/LoggedIn/Home/Table.hs +++ b/src/server/Design/LoggedIn/Home/Table.hs @@ -19,7 +19,6 @@ design = do display D.table width (pct 100) textAlign (alignSide (sideCenter)) - "border-spacing" -: "10 px" ".header" <> ".row" ? display tableRow let headerHeight = (px 70) @@ -29,11 +28,11 @@ design = do backgroundColor Color.gothic color Color.white fontSize iconFontSize - lineHeight headerHeight + height headerHeight ".row" ? do fontSize (px 18) - lineHeight (px rowHeightPx) + height (px rowHeightPx) hover & do let (borderW, triangleW, triangleH) = (4, 6, 8) @@ -70,6 +69,7 @@ design = do ".cell" ? do display tableCell position relative + verticalAlign middle ".category" & width (pct 40) ".cost" & do width (pct 17) diff --git a/src/server/Design/LoggedIn/Stat.hs b/src/server/Design/LoggedIn/Stat.hs index 42bcb71..ff44a9d 100644 --- a/src/server/Design/LoggedIn/Stat.hs +++ b/src/server/Design/LoggedIn/Stat.hs @@ -7,4 +7,7 @@ module Design.LoggedIn.Stat import Clay design :: Css -design = h1 ? paddingBottom (px 0) +design = do + h1 ? paddingBottom (px 0) + + ".mean" ? marginBottom (em 1.5) diff --git a/src/server/Model/Message/Key.hs b/src/server/Model/Message/Key.hs index 7c48e71..4a49900 100644 --- a/src/server/Model/Message/Key.hs +++ b/src/server/Model/Message/Key.hs @@ -72,6 +72,7 @@ data Key = | Overall | ByMonths | By + | Mean -- Income diff --git a/src/server/Model/Message/Translations.hs b/src/server/Model/Message/Translations.hs index f593c49..3ceb7a3 100644 --- a/src/server/Model/Message/Translations.hs +++ b/src/server/Model/Message/Translations.hs @@ -277,6 +277,11 @@ m l By = English -> "by" French -> "par" +m l Mean = + case l of + English -> "Mean: {0}" + French -> "En moyenne : {0}" + -- Income m l CumulativeIncomesSince = |