From fe50c4042848681833d15fab27466d1d2d4bda45 Mon Sep 17 00:00:00 2001 From: Joris Date: Tue, 5 Apr 2016 23:52:13 +0200 Subject: Ameliore design in income page and stat page --- src/client/elm/LoggedIn/Home/Account/View.elm | 4 +-- src/client/elm/LoggedIn/Home/View.elm | 2 +- src/client/elm/LoggedIn/Home/View/Monthly.elm | 6 ++-- src/client/elm/LoggedIn/Home/View/Table.elm | 4 +-- src/client/elm/LoggedIn/Income/View.elm | 8 ++--- src/client/elm/LoggedIn/Stat/View.elm | 45 +++++++++++++++++++-------- src/client/elm/LoggedIn/View.elm | 16 ++++++---- src/client/elm/LoggedIn/View/Format.elm | 37 ++++++++++++++++++++++ src/client/elm/LoggedIn/View/Price.elm | 37 ---------------------- src/client/elm/View/Plural.elm | 7 +++++ 10 files changed, 98 insertions(+), 68 deletions(-) create mode 100644 src/client/elm/LoggedIn/View/Format.elm delete mode 100644 src/client/elm/LoggedIn/View/Price.elm create mode 100644 src/client/elm/View/Plural.elm (limited to 'src/client') diff --git a/src/client/elm/LoggedIn/Home/Account/View.elm b/src/client/elm/LoggedIn/Home/Account/View.elm index 63fb997..bec75d5 100644 --- a/src/client/elm/LoggedIn/Home/Account/View.elm +++ b/src/client/elm/LoggedIn/Home/Account/View.elm @@ -9,7 +9,7 @@ import LoggedData exposing (LoggedData) import LoggedIn.Home.Model as HomeModel import LoggedIn.Home.Model.Payer exposing (..) -import LoggedIn.View.Price exposing (price) +import LoggedIn.View.Format as Format import Model exposing (Model) import Model.User exposing (getUserName) @@ -36,5 +36,5 @@ exceedingPayer loggedData homeModel payer = ] , span [ class "amount" ] - [ text ("+ " ++ (price loggedData.conf payer.amount)) ] + [ text ("+ " ++ (Format.price loggedData.conf payer.amount)) ] ] diff --git a/src/client/elm/LoggedIn/Home/View.elm b/src/client/elm/LoggedIn/Home/View.elm index 7e6ba40..43cc9cf 100644 --- a/src/client/elm/LoggedIn/Home/View.elm +++ b/src/client/elm/LoggedIn/Home/View.elm @@ -20,7 +20,7 @@ import Mailbox view : LoggedData -> LoggedInModel.Model -> Html view loggedData loggedIn = div - [ class "loggedIn" ] + [ class "home" ] [ AddPaymentView.view loggedData loggedIn , div [ class "expandables" ] diff --git a/src/client/elm/LoggedIn/Home/View/Monthly.elm b/src/client/elm/LoggedIn/Home/View/Monthly.elm index c001331..237b551 100644 --- a/src/client/elm/LoggedIn/Home/View/Monthly.elm +++ b/src/client/elm/LoggedIn/Home/View/Monthly.elm @@ -12,7 +12,7 @@ import LoggedIn.Action as LoggedInAction import LoggedIn.Home.Action as HomeAction import LoggedIn.Home.Model as HomeModel -import LoggedIn.View.Price exposing (price) +import LoggedIn.View.Format as Format import LoggedIn.Home.View.Expand exposing (..) import Model.Payment as Payment exposing (Payments, Payment, monthly) @@ -52,7 +52,7 @@ monthlyCount loggedData monthlyPayments homeModel = [ class "header" , onClick Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction <| HomeAction.ToggleMonthlyDetail) ] - [ text (getParamMessage [toString count, price loggedData.conf total] key loggedData.translations) + [ text (getParamMessage [toString count, Format.price loggedData.conf total] key loggedData.translations) , expand ExpandDown homeModel.monthlyDetail ] @@ -81,7 +81,7 @@ paymentLine loggedData homeModel payment = , ("refund", payment.cost < 0) ] ] - [ text (price loggedData.conf payment.cost) ] + [ text (Format.price loggedData.conf payment.cost) ] , div [ class "cell delete" , onClick Mailbox.address (Action.UpdateLoggedIn <| LoggedInAction.DeletePayment payment.id) diff --git a/src/client/elm/LoggedIn/Home/View/Table.elm b/src/client/elm/LoggedIn/Home/View/Table.elm index 71aa4e5..5ac740c 100644 --- a/src/client/elm/LoggedIn/Home/View/Table.elm +++ b/src/client/elm/LoggedIn/Home/View/Table.elm @@ -17,7 +17,7 @@ import LoggedIn.Action as LoggedInAction import LoggedIn.Home.Action as HomeAction import LoggedIn.Home.Model as HomeModel import LoggedIn.View.Date exposing (..) -import LoggedIn.View.Price exposing (price) +import LoggedIn.View.Format as Format import Model.User exposing (getUserName) import Model.Payment as Payment exposing (..) @@ -68,7 +68,7 @@ paymentLine loggedData homeModel payment = , ("refund", payment.cost < 0) ] ] - [ text (price loggedData.conf payment.cost) ] + [ text (Format.price loggedData.conf payment.cost) ] , div [ class "cell user" ] [ payment.userId diff --git a/src/client/elm/LoggedIn/Income/View.elm b/src/client/elm/LoggedIn/Income/View.elm index 010b503..f62902a 100644 --- a/src/client/elm/LoggedIn/Income/View.elm +++ b/src/client/elm/LoggedIn/Income/View.elm @@ -24,14 +24,14 @@ import LoggedIn.Action as LoggedInAction import LoggedIn.Income.Action as IncomeAction import LoggedIn.View.Date exposing (renderShortDate) -import LoggedIn.View.Price exposing (price) +import LoggedIn.View.Format as Format import Utils.Maybe exposing (isJust) view : LoggedData -> IncomeModel.Model -> Html view loggedData incomeModel = div - [] + [ class "income" ] [ h1 [] [ text <| getMessage "AddIncome" loggedData.translations ] , addIncomeView loggedData incomeModel.addIncome , h1 [] [ text <| getMessage "MonthlyNetIncomes" loggedData.translations ] @@ -71,7 +71,7 @@ addIncomeView loggedData addIncome = incomesView : LoggedData -> Html incomesView loggedData = - ol + ul [] ( loggedData.incomes |> Dict.toList @@ -87,7 +87,7 @@ incomeView loggedData (incomeId, income) = [] [ text <| renderShortDate (Date.fromTime income.creation) loggedData.translations , text " − " - , text <| price loggedData.conf income.amount + , text <| Format.price loggedData.conf income.amount , text " − " , button [ onClick Mailbox.address (Action.UpdateLoggedIn <| LoggedInAction.DeleteIncome incomeId) ] diff --git a/src/client/elm/LoggedIn/Stat/View.elm b/src/client/elm/LoggedIn/Stat/View.elm index 76acd8f..3fe9d1f 100644 --- a/src/client/elm/LoggedIn/Stat/View.elm +++ b/src/client/elm/LoggedIn/Stat/View.elm @@ -3,40 +3,59 @@ module LoggedIn.Stat.View ) where import Html exposing (..) +import Html.Attributes exposing (..) import LoggedData exposing (LoggedData) -import Model.Payment exposing (Payments) +import Model.Payment as Payment exposing (Payments) import Model.Conf exposing (Conf) +import Model.Translations exposing (getMessage) -import LoggedIn.View.Price exposing (price) +import LoggedIn.View.Format as Format + +import View.Plural exposing (plural) view : LoggedData -> Html view loggedData = div - [] - [ h1 [] [ text "Total" ] - , paymentDetail loggedData.conf loggedData.payments + [ class "stat" ] + [ h1 [] [ text (getMessage "Overall" loggedData.translations) ] + , paymentsDetail loggedData (Payment.punctual loggedData.payments) + , h1 [] [ text (getMessage "ByMonths" loggedData.translations) ] + , monthsDetail loggedData ] -paymentDetail : Conf -> Payments -> Html -paymentDetail conf payments = +paymentsDetail : LoggedData -> Payments -> Html +paymentsDetail loggedData payments = ul [] [ li [] - [ payments - |> List.length - |> toString - |> text - , text " payments" + [ let single = getMessage "Payment" loggedData.translations + multiple = getMessage "Payments" loggedData.translations + in text <| plural (List.length payments) single multiple ] , li [] [ payments |> List.map .cost |> List.sum - |> price conf + |> Format.price loggedData.conf |> text ] ] + +monthsDetail : LoggedData -> Html +monthsDetail loggedData = + ul + [] + [] + +monthDetail : String -> Int -> Html +monthDetail month amount = + li + [] + [ text month + , text " " + , text (toString amount) + ] diff --git a/src/client/elm/LoggedIn/View.elm b/src/client/elm/LoggedIn/View.elm index b1ec4d3..dbbab33 100644 --- a/src/client/elm/LoggedIn/View.elm +++ b/src/client/elm/LoggedIn/View.elm @@ -3,6 +3,7 @@ module LoggedIn.View ) where import Html exposing (..) +import Html.Attributes exposing (..) import TransitRouter import Route exposing (..) @@ -19,9 +20,12 @@ import LoggedIn.Stat.View as StatView view : Model -> LoggedInModel.Model -> Html view model loggedIn = - let loggedData = LoggedData.build model loggedIn - in case TransitRouter.getRoute model of - Empty -> text "" - Home -> HomeView.view loggedData loggedIn.home - Income -> UserView.view loggedData loggedIn.income - Stat -> StatView.view loggedData + div + [ class "loggedIn" ] + [ let loggedData = LoggedData.build model loggedIn + in case TransitRouter.getRoute model of + Empty -> text "" + Home -> HomeView.view loggedData loggedIn.home + Income -> UserView.view loggedData loggedIn.income + Stat -> StatView.view loggedData + ] diff --git a/src/client/elm/LoggedIn/View/Format.elm b/src/client/elm/LoggedIn/View/Format.elm new file mode 100644 index 0000000..7925a5c --- /dev/null +++ b/src/client/elm/LoggedIn/View/Format.elm @@ -0,0 +1,37 @@ +module LoggedIn.View.Format + ( price + ) where + +import String exposing (..) + +import Model.Conf exposing (Conf) + +price : Conf -> Int -> String +price conf amount = + ( number amount + ++ " " + ++ conf.currency + ) + +number : Int -> String +number n = + abs n + |> toString + |> toList + |> List.reverse + |> group 3 + |> List.intersperse [' '] + |> List.concat + |> List.reverse + |> fromList + |> append (if n < 0 then "-" else "") + +group : Int -> List a -> List (List a) +group n xs = + if List.length xs <= n + then + [xs] + else + let take = List.take n xs + drop = List.drop n xs + in take :: (group n drop) diff --git a/src/client/elm/LoggedIn/View/Price.elm b/src/client/elm/LoggedIn/View/Price.elm deleted file mode 100644 index 2bfed23..0000000 --- a/src/client/elm/LoggedIn/View/Price.elm +++ /dev/null @@ -1,37 +0,0 @@ -module LoggedIn.View.Price - ( price - ) where - -import String exposing (..) - -import Model.Conf exposing (Conf) - -price : Conf -> Int -> String -price conf amount = - ( formatInt amount - ++ " " - ++ conf.currency - ) - -formatInt : Int -> String -formatInt n = - abs n - |> toString - |> toList - |> List.reverse - |> group 3 - |> List.intersperse [' '] - |> List.concat - |> List.reverse - |> fromList - |> append (if n < 0 then "-" else "") - -group : Int -> List a -> List (List a) -group n xs = - if List.length xs <= n - then - [xs] - else - let take = List.take n xs - drop = List.drop n xs - in take :: (group n drop) diff --git a/src/client/elm/View/Plural.elm b/src/client/elm/View/Plural.elm new file mode 100644 index 0000000..6e480fd --- /dev/null +++ b/src/client/elm/View/Plural.elm @@ -0,0 +1,7 @@ +module View.Plural + ( plural + ) where + +plural : Int -> String -> String -> String +plural n single multiple = + (toString n) ++ " " ++ if n <= 1 then single else multiple -- cgit v1.2.3