diff options
author | Joris | 2016-03-29 23:46:47 +0200 |
---|---|---|
committer | Joris | 2016-03-29 23:46:47 +0200 |
commit | 76f8b85eb9f796d6df861a04f702ef5f48630795 (patch) | |
tree | c8b975df9854994cbbefff15908ad9bb728264bc /src/client/elm/LoggedIn/Home/View | |
parent | cc58377a48d13ef85cedb5ec0e19eb8b879dd497 (diff) |
Move logged data to LoggedIn component
Diffstat (limited to 'src/client/elm/LoggedIn/Home/View')
-rw-r--r-- | src/client/elm/LoggedIn/Home/View/Monthly.elm | 90 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/View/Paging.elm | 23 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/View/Price.elm | 9 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/View/Table.elm | 46 |
4 files changed, 130 insertions, 38 deletions
diff --git a/src/client/elm/LoggedIn/Home/View/Monthly.elm b/src/client/elm/LoggedIn/Home/View/Monthly.elm new file mode 100644 index 0000000..487c05d --- /dev/null +++ b/src/client/elm/LoggedIn/Home/View/Monthly.elm @@ -0,0 +1,90 @@ +module LoggedIn.Home.View.Monthly + ( view + ) where + +import String + +import Html exposing (..) +import Html.Attributes exposing (..) +import Html.Events exposing (..) + +import LoggedIn.Action as LoggedInAction + +import LoggedIn.Home.Action as HomeAction +import LoggedIn.Home.Model as HomeModel +import LoggedIn.Home.View.Price exposing (price) +import LoggedIn.Home.View.Expand exposing (..) + +import Model.Payment as Payment exposing (Payment) +import Model.Translations exposing (getMessage, getParamMessage) +import LoggedData exposing (LoggedData) + +import Action +import Mailbox + +import View.Icon exposing (renderIcon) + +view : LoggedData -> HomeModel.Model -> Html +view loggedData homeModel = + if List.length loggedData.monthlyPayments == 0 + then + text "" + else + div + [ classList + [ ("monthlyPayments", True) + , ("detail", homeModel.monthlyDetail) + ] + ] + [ monthlyCount loggedData homeModel + , if homeModel.monthlyDetail + then paymentsTable loggedData homeModel + else text "" + ] + +monthlyCount : LoggedData -> HomeModel.Model -> Html +monthlyCount loggedData homeModel = + let count = List.length loggedData.monthlyPayments + total = List.sum << List.map .cost <| loggedData.monthlyPayments + key = if count > 1 then "PluralMonthlyCount" else "SingularMonthlyCount" + in button + [ class "header" + , onClick Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction <| HomeAction.ToggleMonthlyDetail) + ] + [ text (getParamMessage [toString count, price loggedData.conf total] key loggedData.translations) + , expand ExpandDown homeModel.monthlyDetail + ] + +paymentsTable : LoggedData -> HomeModel.Model -> Html +paymentsTable loggedData homeModel = + div + [ class "table" ] + ( loggedData.monthlyPayments + |> List.sortBy (String.toLower << .name) + |> List.map (paymentLine loggedData homeModel) + ) + +paymentLine : LoggedData -> HomeModel.Model -> Payment -> Html +paymentLine loggedData homeModel payment = + a + [ classList + [ ("row", True) + , ("edition", homeModel.paymentEdition == Just payment.id) + ] + , onClick Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction <| HomeAction.ToggleEdit payment.id) + ] + [ div [ class "cell category" ] [ text (payment.name) ] + , div + [ classList + [ ("cell cost", True) + , ("refund", payment.cost < 0) + ] + ] + [ text (price loggedData.conf payment.cost) ] + , div + [ class "cell delete" + , onClick Mailbox.address (Action.UpdateLoggedIn <| LoggedInAction.DeletePayment payment Payment.Monthly) + ] + [ button [] [ renderIcon "times" ] + ] + ] diff --git a/src/client/elm/LoggedIn/Home/View/Paging.elm b/src/client/elm/LoggedIn/Home/View/Paging.elm index 9942aa8..09a5b62 100644 --- a/src/client/elm/LoggedIn/Home/View/Paging.elm +++ b/src/client/elm/LoggedIn/Home/View/Paging.elm @@ -13,17 +13,18 @@ import LoggedIn.Action as LoggedInAction import LoggedIn.Home.Action as HomeAction import LoggedIn.Home.Model as HomeModel -import Action exposing (..) -import Model.Payment exposing (perPage) +import Action exposing (Action) +import LoggedData exposing (LoggedData) +import Model.Payment exposing (Payments, perPage) import View.Icon exposing (renderIcon) showedPages : Int showedPages = 5 -paymentsPaging : Address Action -> HomeModel.Model -> Html -paymentsPaging address homeModel = - let maxPage = ceiling (toFloat (List.length homeModel.payments) / toFloat perPage) +paymentsPaging : Address Action -> Payments -> HomeModel.Model -> Html +paymentsPaging address payments homeModel = + let maxPage = ceiling (toFloat (List.length payments) / toFloat perPage) pages = truncatePages homeModel.currentPage [1..maxPage] in if maxPage == 1 then @@ -60,7 +61,7 @@ firstPage : Address Action -> Html firstPage address = button [ class "page" - , onClick address (UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| 1) + , onClick address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| 1) ] [ renderIcon "fast-backward" ] @@ -68,7 +69,7 @@ previousPage : Address Action -> HomeModel.Model -> Html previousPage address homeModel = button [ class "page" - , onClick address (UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| homeModel.currentPage - 1) + , onClick address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| homeModel.currentPage - 1) ] [ renderIcon "backward" ] @@ -76,7 +77,7 @@ nextPage : Address Action -> HomeModel.Model -> Html nextPage address homeModel = button [ class "page" - , onClick address (UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| homeModel.currentPage + 1) + , onClick address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| homeModel.currentPage + 1) ] [ renderIcon "forward" ] @@ -84,7 +85,7 @@ lastPage : Address Action -> Int -> Html lastPage address maxPage = button [ class "page" - , onClick address (UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| maxPage) + , onClick address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| maxPage) ] [ renderIcon "fast-forward" ] @@ -97,6 +98,8 @@ paymentsPage address homeModel page = , ("current", onCurrentPage) ] , onClick address <| - if onCurrentPage then Action.NoOp else UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| page + if onCurrentPage + then Action.NoOp + else Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| page ] [ text (toString page) ] diff --git a/src/client/elm/LoggedIn/Home/View/Price.elm b/src/client/elm/LoggedIn/Home/View/Price.elm index a3229a0..2e208f9 100644 --- a/src/client/elm/LoggedIn/Home/View/Price.elm +++ b/src/client/elm/LoggedIn/Home/View/Price.elm @@ -4,14 +4,13 @@ module LoggedIn.Home.View.Price import String exposing (..) -import Model exposing (Model) -import Model.Translations exposing (getMessage) +import Model.Conf exposing (Conf) -price : Model -> Int -> String -price model amount = +price : Conf -> Int -> String +price conf amount = ( formatInt amount ++ " " - ++ model.conf.currency + ++ conf.currency ) formatInt : Int -> String diff --git a/src/client/elm/LoggedIn/Home/View/Table.elm b/src/client/elm/LoggedIn/Home/View/Table.elm index e49fd05..58f2d0b 100644 --- a/src/client/elm/LoggedIn/Home/View/Table.elm +++ b/src/client/elm/LoggedIn/Home/View/Table.elm @@ -4,13 +4,14 @@ module LoggedIn.Home.View.Table import Dict exposing (..) import Date exposing (Date) -import Signal exposing (Address) import String exposing (append) import Html exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (..) +import LoggedData exposing (LoggedData) + import LoggedIn.Action as LoggedInAction import LoggedIn.Home.Action as HomeAction @@ -18,48 +19,47 @@ import LoggedIn.Home.Model as HomeModel import LoggedIn.Home.View.Date exposing (..) import LoggedIn.Home.View.Price exposing (price) -import Model exposing (Model) import Model.User exposing (getUserName) import Model.Payment exposing (..) -import Model.Translations exposing (getMessage) -import Action exposing (..) +import Action +import Mailbox import View.Icon exposing (renderIcon) -paymentsTable : Address Action -> Model -> HomeModel.Model -> Html -paymentsTable address model homeModel = +paymentsTable : LoggedData -> HomeModel.Model -> Html +paymentsTable loggedData homeModel = div [ class "table" ] - ( headerLine model :: paymentLines address model homeModel) + ( headerLine loggedData :: paymentLines loggedData homeModel) -headerLine : Model -> Html -headerLine model = +headerLine : LoggedData -> Html +headerLine loggedData = div [ class "header" ] [ div [ class "cell category" ] [ renderIcon "shopping-cart" ] - , div [ class "cell cost" ] [ text model.conf.currency ] + , div [ class "cell cost" ] [ text loggedData.conf.currency ] , div [ class "cell user" ] [ renderIcon "user" ] , div [ class "cell date" ] [ renderIcon "calendar" ] , div [ class "cell" ] [] ] -paymentLines : Address Action -> Model -> HomeModel.Model -> List Html -paymentLines address model homeModel = - homeModel.payments +paymentLines : LoggedData -> HomeModel.Model -> List Html +paymentLines loggedData homeModel = + loggedData.payments |> List.sortBy (Date.toTime << .creation) |> List.reverse |> List.drop ((homeModel.currentPage - 1) * perPage) |> List.take perPage - |> List.map (paymentLine address model homeModel) + |> List.map (paymentLine loggedData homeModel) -paymentLine : Address Action -> Model -> HomeModel.Model -> Payment -> Html -paymentLine address model homeModel payment = +paymentLine : LoggedData -> HomeModel.Model -> Payment -> Html +paymentLine loggedData homeModel payment = a [ classList [ ("row", True) , ("edition", homeModel.paymentEdition == Just payment.id) ] - , onClick address (UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.ToggleEdit <| payment.id) + , onClick Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.ToggleEdit <| payment.id) ] [ div [ class "cell category" ] [ text payment.name ] , div @@ -68,11 +68,11 @@ paymentLine address model homeModel payment = , ("refund", payment.cost < 0) ] ] - [ text (price model payment.cost) ] + [ text (price loggedData.conf payment.cost) ] , div [ class "cell user" ] [ payment.userId - |> getUserName homeModel.users + |> getUserName loggedData.users |> Maybe.withDefault "−" |> text ] @@ -80,17 +80,17 @@ paymentLine address model homeModel payment = [ class "cell date" ] [ span [ class "shortDate" ] - [ text (renderShortDate payment.creation model.translations) ] + [ text (renderShortDate payment.creation loggedData.translations) ] , span [ class "longDate" ] - [ text (renderLongDate payment.creation model.translations) ] + [ text (renderLongDate payment.creation loggedData.translations) ] ] - , if homeModel.account.me == payment.userId + , if loggedData.me == payment.userId then div [ class "cell delete" ] [ button - [ onClick address (UpdateLoggedIn <| LoggedInAction.HomeAction <| HomeAction.DeletePayment payment Punctual)] + [ onClick Mailbox.address (Action.UpdateLoggedIn <| LoggedInAction.DeletePayment payment Punctual)] [ renderIcon "times" ] ] else |