aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Home/View
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/LoggedIn/Home/View')
-rw-r--r--src/client/elm/LoggedIn/Home/View/ExceedingPayers.elm45
-rw-r--r--src/client/elm/LoggedIn/Home/View/Monthly.elm93
-rw-r--r--src/client/elm/LoggedIn/Home/View/Paging.elm8
-rw-r--r--src/client/elm/LoggedIn/Home/View/Table.elm74
4 files changed, 93 insertions, 127 deletions
diff --git a/src/client/elm/LoggedIn/Home/View/ExceedingPayers.elm b/src/client/elm/LoggedIn/Home/View/ExceedingPayers.elm
new file mode 100644
index 0000000..15f5cf5
--- /dev/null
+++ b/src/client/elm/LoggedIn/Home/View/ExceedingPayers.elm
@@ -0,0 +1,45 @@
+module LoggedIn.Home.View.ExceedingPayers exposing
+ ( view
+ )
+
+import Html exposing (..)
+import Html.Attributes exposing (..)
+
+import Msg exposing (Msg)
+
+import LoggedData exposing (LoggedData)
+
+import LoggedIn.View.Format as Format
+
+import Model exposing (Model)
+import Model.User exposing (getUserName)
+import Model.Payment as Payment
+import Model.Payer exposing (..)
+import Model.Translations exposing (getMessage)
+
+view : LoggedData -> Html Msg
+view loggedData =
+ let payments = Payment.punctual loggedData.payments
+ exceedingPayers = getOrderedExceedingPayers loggedData.currentTime loggedData.users loggedData.incomes payments
+ in div
+ [ class "exceedingPayers" ]
+ ( if List.isEmpty exceedingPayers
+ then [ text <| getMessage "PaymentsAreBalanced" loggedData.translations ]
+ else (List.map (exceedingPayer loggedData) exceedingPayers)
+ )
+
+exceedingPayer : LoggedData -> ExceedingPayer -> Html Msg
+exceedingPayer loggedData payer =
+ span
+ [ class "exceedingPayer" ]
+ [ span
+ [ class "userName" ]
+ [ payer.userId
+ |> getUserName loggedData.users
+ |> Maybe.withDefault "−"
+ |> text
+ ]
+ , span
+ [ class "amount" ]
+ [ text ("+ " ++ (Format.price loggedData.conf payer.amount)) ]
+ ]
diff --git a/src/client/elm/LoggedIn/Home/View/Monthly.elm b/src/client/elm/LoggedIn/Home/View/Monthly.elm
deleted file mode 100644
index 20dda19..0000000
--- a/src/client/elm/LoggedIn/Home/View/Monthly.elm
+++ /dev/null
@@ -1,93 +0,0 @@
-module LoggedIn.Home.View.Monthly exposing
- ( view
- )
-
-import String
-import Color
-
-import FontAwesome
-
-import Html exposing (..)
-import Html.Attributes exposing (..)
-import Html.Events exposing (..)
-
-import Msg exposing (Msg)
-
-import LoggedIn.Msg as LoggedInMsg
-
-import LoggedIn.Home.Msg as HomeMsg
-import LoggedIn.Home.Model as HomeModel
-import LoggedIn.View.Format as Format
-import LoggedIn.Home.View.Expand exposing (..)
-
-import Model.Payment as Payment exposing (Payments, Payment, monthly)
-import Model.Translations exposing (getMessage, getParamMessage)
-import LoggedData exposing (LoggedData)
-
-view : LoggedData -> HomeModel.Model -> Html Msg
-view loggedData homeModel =
- let monthlyPayments = Payment.monthly loggedData.me loggedData.payments
- in if List.length monthlyPayments == 0
- then
- text ""
- else
- div
- [ classList
- [ ("monthly", True)
- , ("detail", homeModel.monthlyDetail)
- ]
- ]
- [ monthlyCount loggedData monthlyPayments homeModel
- , if homeModel.monthlyDetail
- then paymentsTable loggedData monthlyPayments homeModel
- else text ""
- ]
-
-monthlyCount : LoggedData -> Payments -> HomeModel.Model -> Html Msg
-monthlyCount loggedData monthlyPayments homeModel =
- let count = List.length monthlyPayments
- total = List.sum << List.map .cost <| monthlyPayments
- key = if count > 1 then "PluralMonthlyCount" else "SingularMonthlyCount"
- in button
- [ class "header"
- , onClick (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg <| HomeMsg.ToggleMonthlyDetail)
- ]
- [ text (getParamMessage [toString count, Format.price loggedData.conf total] key loggedData.translations)
- , expand ExpandDown homeModel.monthlyDetail
- ]
-
-paymentsTable : LoggedData -> Payments -> HomeModel.Model -> Html Msg
-paymentsTable loggedData monthlyPayments homeModel =
- div
- [ class "table" ]
- ( monthlyPayments
- |> List.sortBy (String.toLower << .name)
- |> List.map (paymentLine loggedData homeModel)
- )
-
-paymentLine : LoggedData -> HomeModel.Model -> Payment -> Html Msg
-paymentLine loggedData homeModel payment =
- a
- [ classList
- [ ("row", True)
- , ("edition", homeModel.paymentEdition == Just payment.id)
- ]
- , onClick (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg <| HomeMsg.ToggleEdit payment.id)
- ]
- [ div [ class "cell category" ] [ text (payment.name) ]
- , div
- [ classList
- [ ("cell cost", True)
- , ("refund", payment.cost < 0)
- ]
- ]
- [ text (Format.price loggedData.conf payment.cost) ]
- , div
- [ class "cell delete"
- , onClick (Msg.UpdateLoggedIn <| LoggedInMsg.DeletePayment payment.id)
- ]
- [ button
- []
- [ FontAwesome.times Color.white 20 ]
- ]
- ]
diff --git a/src/client/elm/LoggedIn/Home/View/Paging.elm b/src/client/elm/LoggedIn/Home/View/Paging.elm
index da69232..90ae522 100644
--- a/src/client/elm/LoggedIn/Home/View/Paging.elm
+++ b/src/client/elm/LoggedIn/Home/View/Paging.elm
@@ -1,5 +1,5 @@
module LoggedIn.Home.View.Paging exposing
- ( paymentsPaging
+ ( view
)
import Color exposing (Color)
@@ -22,11 +22,11 @@ import Model.Payment as Payment exposing (Payments, perPage)
showedPages : Int
showedPages = 5
-paymentsPaging : HomeModel.Model -> Payments -> Html Msg
-paymentsPaging homeModel payments =
+view : HomeModel.Model -> Payments -> Html Msg
+view homeModel payments =
let maxPage = ceiling (toFloat (List.length payments) / toFloat perPage)
pages = truncatePages homeModel.currentPage [1..maxPage]
- in if maxPage == 1
+ in if maxPage <= 1
then
text ""
else
diff --git a/src/client/elm/LoggedIn/Home/View/Table.elm b/src/client/elm/LoggedIn/Home/View/Table.elm
index a03faa2..9cd43a7 100644
--- a/src/client/elm/LoggedIn/Home/View/Table.elm
+++ b/src/client/elm/LoggedIn/Home/View/Table.elm
@@ -1,5 +1,5 @@
module LoggedIn.Home.View.Table exposing
- ( paymentsTable
+ ( view
)
import Dict exposing (..)
@@ -26,33 +26,43 @@ import LoggedIn.View.Format as Format
import Model.User exposing (getUserName)
import Model.Payment as Payment exposing (..)
+import Model.Translations exposing (getMessage)
-paymentsTable : LoggedData -> HomeModel.Model -> Payments -> Html Msg
-paymentsTable loggedData homeModel punctualPayments =
- div
- [ class "table" ]
- ( headerLine loggedData :: paymentLines loggedData homeModel punctualPayments)
+view : LoggedData -> HomeModel.Model -> Payments -> Frequency -> Html Msg
+view loggedData homeModel payments frequency =
+ let visiblePayments =
+ payments
+ |> List.drop ((homeModel.currentPage - 1) * perPage)
+ |> List.take perPage
+ in div
+ [ class "table" ]
+ [ div
+ [ class "lines" ]
+ ( headerLine loggedData frequency :: List.map (paymentLine loggedData homeModel frequency) visiblePayments )
+ , if List.isEmpty visiblePayments
+ then
+ div
+ [ class "noPayment" ]
+ [ text <| getMessage "NoPayment" loggedData.translations ]
+ else
+ text ""
+ ]
-headerLine : LoggedData -> Html Msg
-headerLine loggedData =
+headerLine : LoggedData -> Frequency -> Html Msg
+headerLine loggedData frequency =
div
[ class "header" ]
- [ 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 28 ]
- , div [ class "cell date" ] [ FontAwesome.calendar Color.white 28 ]
+ [ div [ class "cell category" ] [ text <| getMessage "Name" loggedData.translations ]
+ , div [ class "cell cost" ] [ text <| getMessage "Cost" loggedData.translations ]
+ , div [ class "cell user" ] [ text <| getMessage "Payer" loggedData.translations ]
+ , case frequency of
+ Punctual -> div [ class "cell date" ] [ text <| getMessage "Date" loggedData.translations ]
+ Monthly -> text ""
, div [ class "cell" ] []
]
-paymentLines : LoggedData -> HomeModel.Model -> Payments -> List (Html Msg)
-paymentLines loggedData homeModel punctualPayments =
- punctualPayments
- |> List.drop ((homeModel.currentPage - 1) * perPage)
- |> List.take perPage
- |> List.map (paymentLine loggedData homeModel)
-
-paymentLine : LoggedData -> HomeModel.Model -> Payment -> Html Msg
-paymentLine loggedData homeModel payment =
+paymentLine : LoggedData -> HomeModel.Model -> Frequency -> Payment -> Html Msg
+paymentLine loggedData homeModel frequency payment =
a
[ classList
[ ("row", True)
@@ -75,15 +85,19 @@ paymentLine loggedData homeModel payment =
|> Maybe.withDefault "−"
|> text
]
- , div
- [ class "cell date" ]
- [ span
- [ class "shortDate" ]
- [ text (renderShortDate payment.creation loggedData.translations) ]
- , span
- [ class "longDate" ]
- [ text (renderLongDate payment.creation loggedData.translations) ]
- ]
+ , case frequency of
+ Punctual ->
+ div
+ [ class "cell date" ]
+ [ span
+ [ class "shortDate" ]
+ [ text (renderShortDate payment.creation loggedData.translations) ]
+ , span
+ [ class "longDate" ]
+ [ text (renderLongDate payment.creation loggedData.translations) ]
+ ]
+ Monthly ->
+ text ""
, if loggedData.me == payment.userId
then
div