aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/LoggedIn')
-rw-r--r--src/client/elm/LoggedIn/Home/AddPayment/View.elm68
-rw-r--r--src/client/elm/LoggedIn/Home/Header/View.elm97
-rw-r--r--src/client/elm/LoggedIn/Home/Model.elm44
-rw-r--r--src/client/elm/LoggedIn/Home/Msg.elm3
-rw-r--r--src/client/elm/LoggedIn/Home/Search/View.elm56
-rw-r--r--src/client/elm/LoggedIn/Home/Update.elm44
-rw-r--r--src/client/elm/LoggedIn/Home/View.elm28
-rw-r--r--src/client/elm/LoggedIn/Home/View/ExceedingPayers.elm (renamed from src/client/elm/LoggedIn/Stat/Account/View.elm)19
-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
-rw-r--r--src/client/elm/LoggedIn/Income/View.elm7
-rw-r--r--src/client/elm/LoggedIn/Stat/View.elm87
-rw-r--r--src/client/elm/LoggedIn/Update.elm61
14 files changed, 255 insertions, 434 deletions
diff --git a/src/client/elm/LoggedIn/Home/AddPayment/View.elm b/src/client/elm/LoggedIn/Home/AddPayment/View.elm
deleted file mode 100644
index 5ccdb35..0000000
--- a/src/client/elm/LoggedIn/Home/AddPayment/View.elm
+++ /dev/null
@@ -1,68 +0,0 @@
-module LoggedIn.Home.AddPayment.View exposing
- ( view
- )
-
-import Html exposing (..)
-import Html.Attributes exposing (..)
-import Html.Events exposing (..)
-import Html.App as Html
-import Task
-
-import Form exposing (Form)
-
-import Dialog
-
-import View.Form as Form
-import View.Events exposing (onSubmitPrevDefault)
-
-import Msg exposing (Msg)
-import LoggedIn.Msg as LoggedInMsg
-import LoggedIn.Home.Msg as HomeMsg
-
-import Model.Translations exposing (getMessage)
-import Model.Payment as Payment
-import Model.View exposing (View(LoggedInView))
-
-import LoggedData exposing (LoggedData)
-import LoggedIn.Home.Model as HomeModel
-
-view : LoggedData -> Html Msg
-view loggedData =
- let dialogConfig =
- { title = getMessage "AddPayment" loggedData.translations
- , body = \view -> (
- case view of
- LoggedInView loggedIn -> addPaymentForm loggedData loggedIn.home
- _ -> text ""
- )
- , confirm = getMessage "Confirm" loggedData.translations
- , confirmMsg = \view -> (
- case view of
- LoggedInView loggedIn ->
- case Form.getOutput loggedIn.home.addPayment of
- Just data ->
- Ok (Msg.UpdateLoggedIn <| LoggedInMsg.AddPayment data.name data.cost data.frequency)
- Nothing ->
- Err (Msg.UpdateLoggedIn <| LoggedInMsg.HomeMsg <| HomeMsg.AddPaymentMsg <| Form.Submit)
- _ ->
- Err (Msg.UpdateLoggedIn LoggedInMsg.NoOp)
- )
- , undo = getMessage "Undo" loggedData.translations
- }
- in button
- [ class "addPayment"
- , onClick (Msg.Dialog <| Dialog.Open dialogConfig)
- ]
- [ text (getMessage "AddPayment" loggedData.translations) ]
-
-addPaymentForm : LoggedData -> HomeModel.Model -> Html Msg
-addPaymentForm loggedData { addPayment } =
- let htmlMap = Html.map (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.AddPaymentMsg)
- in Html.form
- [ class "addPayment"
- , onSubmitPrevDefault Msg.NoOp
- ]
- [ Form.textInput loggedData.translations addPayment htmlMap "name"
- , Form.textInput loggedData.translations addPayment htmlMap "cost"
- , Form.radioInputs loggedData.translations addPayment htmlMap "frequency" [ toString Payment.Punctual, toString Payment.Monthly ]
- ]
diff --git a/src/client/elm/LoggedIn/Home/Header/View.elm b/src/client/elm/LoggedIn/Home/Header/View.elm
new file mode 100644
index 0000000..f9fbb6a
--- /dev/null
+++ b/src/client/elm/LoggedIn/Home/Header/View.elm
@@ -0,0 +1,97 @@
+module LoggedIn.Home.Header.View exposing
+ ( view
+ )
+
+import Html exposing (..)
+import Html.Attributes exposing (..)
+import Html.Events exposing (..)
+import Html.App as Html
+import String
+import Dict
+
+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 Home
+import Model.Translations exposing (getParamMessage)
+import Model.Conf exposing (Conf)
+import Model.Payment as Payment exposing (Payments, Frequency(..))
+import Model.Translations exposing (getMessage)
+
+import Dialog.AddPayment.View as AddPayment
+
+import LoggedIn.Home.View.ExceedingPayers as ExceedingPayers
+import LoggedIn.View.Format as Format
+import View.Plural exposing (plural)
+
+import Utils.Tuple as Tuple
+
+view : LoggedData -> Home.Model -> Payments -> Frequency -> Html Msg
+view loggedData { search } payments frequency =
+ Html.div
+ [ class "header" ]
+ [ ExceedingPayers.view loggedData
+ , searchLine loggedData search frequency
+ , infos loggedData payments
+ ]
+
+searchLine : LoggedData -> Form String Home.Search -> Frequency -> Html Msg
+searchLine loggedData search frequency =
+ Html.div
+ [ class "searchLine" ]
+ [ searchForm loggedData search
+ , AddPayment.view loggedData frequency
+ ]
+
+searchForm : LoggedData -> Form String Home.Search -> Html Msg
+searchForm loggedData search =
+ let htmlMap = Html.map (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.SearchMsg)
+ in Html.form
+ []
+ [ Form.textInput loggedData.translations search htmlMap "search" "name"
+ , if List.isEmpty (Payment.monthly loggedData.payments)
+ then text ""
+ else Form.radioInputs loggedData.translations search htmlMap "search" "frequency" [ toString Punctual, toString Monthly ]
+ ]
+
+infos : LoggedData -> Payments -> Html Msg
+infos loggedData payments =
+ let paymentsCount = List.length payments
+ in if paymentsCount == 0
+ then text ""
+ else
+ let count = plural loggedData.translations (List.length payments) "Payment" "Payments"
+ sum = paymentsSum loggedData.conf payments
+ in div
+ [ class "infos" ]
+ [ text <| getParamMessage [ count, sum ] "Worth" loggedData.translations
+ , span
+ [ class "partition" ]
+ [ text <| paymentsPartition loggedData payments ]
+ ]
+
+paymentsPartition : LoggedData -> Payments -> String
+paymentsPartition loggedData payments =
+ String.join
+ ", "
+ ( loggedData.users
+ |> Dict.toList
+ |> List.map (Tuple.mapFst (\userId -> Payment.totalPayments (always True) userId payments))
+ |> List.sortBy fst
+ |> List.reverse
+ |> List.map (\(sum, user) ->
+ getParamMessage [ user.name, Format.price loggedData.conf sum ] "By" 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/Model.elm b/src/client/elm/LoggedIn/Home/Model.elm
index e802828..be32fb7 100644
--- a/src/client/elm/LoggedIn/Home/Model.elm
+++ b/src/client/elm/LoggedIn/Home/Model.elm
@@ -2,7 +2,7 @@ module LoggedIn.Home.Model exposing
( Model
, Search
, init
- , addPaymentInitial
+ , searchInitial
)
import Form exposing (Form)
@@ -10,24 +10,17 @@ import Form.Validate as Validate exposing (Validation)
import Form.Field as Field exposing (Field)
import Model.User exposing (Users, UserId)
-import Model.Payment exposing (PaymentId, Payments, Frequency(..))
+import Model.Payment as Payment exposing (PaymentId, Payments, Frequency(..))
import Model.Payer exposing (Payers)
type alias Model =
{ paymentEdition : Maybe PaymentId
, currentPage : Int
- , monthlyDetail : Bool
, search : Form String Search
- , addPayment : Form String AddPayment
}
type alias Search =
- { searchText : Maybe String
- }
-
-type alias AddPayment =
- { name : String
- , cost : Int
+ { name : Maybe String
, frequency : Frequency
}
@@ -35,31 +28,14 @@ init : Model
init =
{ paymentEdition = Nothing
, currentPage = 1
- , monthlyDetail = False
- , search = Form.initial [] searchValidation
- , addPayment = Form.initial addPaymentInitial addPaymentValidation
+ , search = Form.initial (searchInitial Punctual) searchValidation
}
+searchInitial : Frequency -> List (String, Field)
+searchInitial frequency = [ ("frequency", Field.Radio (toString frequency)) ]
+
searchValidation : Validation String Search
searchValidation =
- Validate.form1 Search
- (Validate.get "searchText" (Validate.maybe Validate.string))
-
-addPaymentInitial : List (String, Field)
-addPaymentInitial = [ ("frequency", Field.Radio (toString Punctual)) ]
-
-addPaymentValidation : Validation String AddPayment
-addPaymentValidation =
- Validate.form3 AddPayment
- (Validate.get "name" (Validate.string `Validate.andThen` (Validate.nonEmpty)))
- (Validate.get "cost" (Validate.int `Validate.andThen` (Validate.minInt 1)))
- (Validate.get "frequency" validateFrequency)
-
-validateFrequency : Validation String Frequency
-validateFrequency =
- Validate.customValidation Validate.string (\str ->
- case str of
- "Punctual" -> Ok Punctual
- "Monthly" -> Ok Monthly
- _ -> Err (Validate.customError "InvalidFrequency")
- )
+ Validate.form2 Search
+ (Validate.get "name" (Validate.maybe Validate.string))
+ (Validate.get "frequency" Payment.validateFrequency)
diff --git a/src/client/elm/LoggedIn/Home/Msg.elm b/src/client/elm/LoggedIn/Home/Msg.elm
index bb6f77d..73b8980 100644
--- a/src/client/elm/LoggedIn/Home/Msg.elm
+++ b/src/client/elm/LoggedIn/Home/Msg.elm
@@ -10,7 +10,4 @@ type Msg =
NoOp
| ToggleEdit PaymentId
| UpdatePage Int
- | ShowMonthlyDetail
- | ToggleMonthlyDetail
| SearchMsg Form.Msg
- | AddPaymentMsg Form.Msg
diff --git a/src/client/elm/LoggedIn/Home/Search/View.elm b/src/client/elm/LoggedIn/Home/Search/View.elm
deleted file mode 100644
index 99eec95..0000000
--- a/src/client/elm/LoggedIn/Home/Search/View.elm
+++ /dev/null
@@ -1,56 +0,0 @@
-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 Model.Translations exposing (getMessage)
-
-import LoggedIn.Home.AddPayment.View as AddPayment
-
-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
- , AddPayment.view loggedData
- ]
-
-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 span
- [ class "stat" ]
- [ 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 562cd20..160e279 100644
--- a/src/client/elm/LoggedIn/Home/Update.elm
+++ b/src/client/elm/LoggedIn/Home/Update.elm
@@ -6,49 +6,35 @@ import Form exposing (Form)
import LoggedData exposing (LoggedData)
-import LoggedIn.Home.Msg as HomeMsg
-import LoggedIn.Home.Model as HomeModel
+import LoggedIn.Home.Msg as Home
+import LoggedIn.Home.Model as Home
-update : LoggedData -> HomeMsg.Msg -> HomeModel.Model -> (HomeModel.Model, Cmd HomeMsg.Msg)
-update loggedData msg homeModel =
+update : LoggedData -> Home.Msg -> Home.Model -> (Home.Model, Cmd Home.Msg)
+update loggedData msg model =
case msg of
- HomeMsg.NoOp -> (homeModel, Cmd.none)
-
- HomeMsg.ToggleEdit id ->
- ( { homeModel | paymentEdition = if homeModel.paymentEdition == Just id then Nothing else Just id }
- , Cmd.none
- )
-
- HomeMsg.UpdatePage page ->
- ( { homeModel | currentPage = page }
+ Home.NoOp ->
+ ( model
, Cmd.none
)
- HomeMsg.ShowMonthlyDetail ->
- ( { homeModel | monthlyDetail = True }
+ Home.ToggleEdit id ->
+ ( { model | paymentEdition = if model.paymentEdition == Just id then Nothing else Just id }
, Cmd.none
)
- HomeMsg.ToggleMonthlyDetail ->
- ( { homeModel | monthlyDetail = not homeModel.monthlyDetail }
+ Home.UpdatePage page ->
+ ( { model | currentPage = page }
, Cmd.none
)
- HomeMsg.SearchMsg formMsg ->
- ( { homeModel
- | search = Form.update formMsg homeModel.search
+ Home.SearchMsg formMsg ->
+ ( { model
+ | search = Form.update formMsg model.search
, currentPage =
case formMsg of
- Form.Input "searchText" _ -> 1
- _ -> homeModel.currentPage
- }
- , Cmd.none
- )
-
- HomeMsg.AddPaymentMsg formMsg ->
- ( { homeModel
- | addPayment = Form.update formMsg homeModel.addPayment
+ Form.Input "name" _ -> 1
+ _ -> model.currentPage
}
, Cmd.none
)
diff --git a/src/client/elm/LoggedIn/Home/View.elm b/src/client/elm/LoggedIn/Home/View.elm
index 8076673..0def64e 100644
--- a/src/client/elm/LoggedIn/Home/View.elm
+++ b/src/client/elm/LoggedIn/Home/View.elm
@@ -12,22 +12,24 @@ import Utils.Form as Form
import Msg exposing (Msg)
import LoggedData exposing (LoggedData)
-import Model.Payment as Payment
+import Model.Payment as Payment exposing (Frequency(..))
-import LoggedIn.Home.Model as LoggedInModel
-import LoggedIn.Home.Search.View as SearchView
-import LoggedIn.Home.View.Monthly as MonthlyView
+import LoggedIn.Home.Model as Home
+import LoggedIn.Home.Header.View as Header
-import LoggedIn.Home.View.Table exposing (paymentsTable)
-import LoggedIn.Home.View.Paging exposing (paymentsPaging)
+import LoggedIn.Home.View.Table as Table
+import LoggedIn.Home.View.Paging as Paging
-view : LoggedData -> LoggedInModel.Model -> Html Msg
-view loggedData loggedIn =
- let punctualPayments = Payment.sortedFiltredPunctual (Form.fieldAsText loggedIn.search "searchText") loggedData.payments
+view : LoggedData -> Home.Model -> Html Msg
+view loggedData home =
+ let (name, frequency) =
+ case Form.getOutput home.search of
+ Just data -> (Maybe.withDefault "" data.name, data.frequency)
+ Nothing -> ("", Punctual)
+ payments = Payment.search name frequency loggedData.payments
in div
[ class "home" ]
- [ SearchView.view loggedData loggedIn punctualPayments
- , MonthlyView.view loggedData loggedIn
- , paymentsTable loggedData loggedIn punctualPayments
- , paymentsPaging loggedIn punctualPayments
+ [ Header.view loggedData home payments frequency
+ , Table.view loggedData home payments frequency
+ , Paging.view home payments
]
diff --git a/src/client/elm/LoggedIn/Stat/Account/View.elm b/src/client/elm/LoggedIn/Home/View/ExceedingPayers.elm
index 3eb5ef4..15f5cf5 100644
--- a/src/client/elm/LoggedIn/Stat/Account/View.elm
+++ b/src/client/elm/LoggedIn/Home/View/ExceedingPayers.elm
@@ -1,4 +1,4 @@
-module LoggedIn.Stat.Account.View exposing
+module LoggedIn.Home.View.ExceedingPayers exposing
( view
)
@@ -13,18 +13,25 @@ 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 =
- ul
- [ class "exceedingPayers" ]
- (List.map (exceedingPayer loggedData) (getOrderedExceedingPayers loggedData.currentTime loggedData.users loggedData.incomes loggedData.payments))
+ 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 =
- li
- []
+ span
+ [ class "exceedingPayer" ]
[ span
[ class "userName" ]
[ payer.userId
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
diff --git a/src/client/elm/LoggedIn/Income/View.elm b/src/client/elm/LoggedIn/Income/View.elm
index 25cb5a6..be15c6b 100644
--- a/src/client/elm/LoggedIn/Income/View.elm
+++ b/src/client/elm/LoggedIn/Income/View.elm
@@ -80,8 +80,8 @@ addIncomeView loggedData addIncome =
let htmlMap = Html.map (Msg.UpdateLoggedIn << LoggedInMsg.IncomeMsg << IncomeMsg.AddIncomeMsg)
in Html.form
[ onSubmitPrevDefault Msg.NoOp ]
- [ Form.textInput loggedData.translations addIncome htmlMap "creation"
- , Form.textInput loggedData.translations addIncome htmlMap "amount"
+ [ Form.textInput loggedData.translations addIncome htmlMap "income" "creation"
+ , Form.textInput loggedData.translations addIncome htmlMap "income" "amount"
, button
[ case Form.getOutput addIncome of
Just data ->
@@ -112,7 +112,8 @@ incomeView loggedData (incomeId, income) =
, text " − "
, text <| Format.price loggedData.conf income.amount
, let dialogConfig =
- { title = getMessage "ConfirmDelete" loggedData.translations
+ { className = "incomeDialog"
+ , title = getMessage "ConfirmDelete" loggedData.translations
, body = always <| text ""
, confirm = getMessage "Confirm" loggedData.translations
, confirmMsg = always <| Ok <| Msg.UpdateLoggedIn <| LoggedInMsg.DeleteIncome incomeId
diff --git a/src/client/elm/LoggedIn/Stat/View.elm b/src/client/elm/LoggedIn/Stat/View.elm
index f99ef0e..72e1f34 100644
--- a/src/client/elm/LoggedIn/Stat/View.elm
+++ b/src/client/elm/LoggedIn/Stat/View.elm
@@ -3,8 +3,6 @@ module LoggedIn.Stat.View exposing
)
import Date exposing (Month)
-import Dict
-import String
import Html exposing (..)
import Html.Attributes exposing (..)
@@ -21,85 +19,30 @@ import LoggedIn.View.Format as Format
import LoggedIn.View.Date as Date
import View.Plural exposing (plural)
-import LoggedIn.Stat.Account.View as AccountView
-
-import Utils.Tuple as Tuple
import Utils.List as List
view : LoggedData -> Html Msg
view loggedData =
- div
- [ class "stat" ]
- [ 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
- ]
-
-paymentsDetail : LoggedData -> Payments -> Html Msg
-paymentsDetail loggedData payments =
- ul
- []
- [ li
- []
- [ text <| plural loggedData.translations (List.length payments) "Payment" "Payments" ]
- , li
- []
- [ text (paymentsSum loggedData.conf payments)
- , text " − "
- , text <| totalPayments loggedData
- ]
- ]
-
-totalPayments : LoggedData -> String
-totalPayments loggedData =
- String.join
- ", "
- ( loggedData.users
- |> Dict.toList
- |> List.map (Tuple.mapFst (\userId -> Payment.totalPayments (always True) userId loggedData.payments))
- |> List.sortBy fst
- |> List.map (\(sum, user) ->
- String.concat
- [ Format.price loggedData.conf sum
- , " "
- , getMessage "By" loggedData.translations
- , " "
- , user.name
- ]
- )
- )
-
-monthsDetail : LoggedData -> Html Msg
-monthsDetail 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
+ let paymentsByMonth = Payment.groupAndSortByMonth (Payment.punctual loggedData.payments)
+ monthPaymentMean = getMonthPaymentMean loggedData paymentsByMonth
in div
- []
- [ div
- [ class "mean" ]
- [ text (getParamMessage [ Format.price loggedData.conf monthPaymentMean ] "Mean" loggedData.translations)
- ]
+ [ class "stat" ]
+ [ h1 [] [ text (getParamMessage [ Format.price loggedData.conf monthPaymentMean ] "ByMonthsAndMean" loggedData.translations) ]
, ul
[]
- ( Payment.punctual loggedData.payments
- |> Payment.groupAndSortByMonth
- |> List.map (monthDetail loggedData)
- )
+ ( List.map (monthDetail loggedData) paymentsByMonth)
]
+getMonthPaymentMean : LoggedData -> List ((Month, Int), Payments) -> Int
+getMonthPaymentMean loggedData paymentsByMonth =
+ 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
+
monthDetail : LoggedData -> ((Month, Int), Payments) -> Html Msg
monthDetail loggedData ((month, year), payments) =
li
diff --git a/src/client/elm/LoggedIn/Update.elm b/src/client/elm/LoggedIn/Update.elm
index 4fddc2c..48d87f7 100644
--- a/src/client/elm/LoggedIn/Update.elm
+++ b/src/client/elm/LoggedIn/Update.elm
@@ -14,7 +14,7 @@ import Form
import Model exposing (Model)
import Model.Translations exposing (getMessage)
-import Model.Payment exposing (Payment, Frequency(..), deletePayment)
+import Model.Payment as Payment exposing (Payment, Frequency(..), deletePayment)
import Server
import LoggedData
@@ -59,27 +59,23 @@ update model msg loggedIn =
)
LoggedInMsg.AddPayment name cost frequency ->
- Server.addPayment name cost frequency
- |> Task.perform
- (\err ->
- case err of
- BadResponse 400 jsonErr ->
- LoggedInMsg.NoOp
- _ ->
- LoggedInMsg.NoOp
- )
- (\paymentId -> LoggedInMsg.ValidateAddPayment paymentId name cost frequency)
- |> \cmd -> (loggedIn, cmd)
+ ( loggedIn
+ , Server.addPayment name cost frequency
+ |> Task.perform
+ (\err ->
+ case err of
+ BadResponse 400 jsonErr ->
+ LoggedInMsg.NoOp
+ _ ->
+ LoggedInMsg.NoOp
+ )
+ (\paymentId -> LoggedInMsg.ValidateAddPayment paymentId name cost frequency)
+ )
LoggedInMsg.ValidateAddPayment paymentId name cost frequency ->
- update model (LoggedInMsg.HomeMsg <| HomeMsg.AddPaymentMsg (Form.Reset HomeModel.addPaymentInitial)) loggedIn
- :> (\loggedIn ->
- case frequency of
- Punctual ->
- update model (LoggedInMsg.HomeMsg <| HomeMsg.UpdatePage 1) loggedIn
- Monthly ->
- update model (LoggedInMsg.HomeMsg <| HomeMsg.ShowMonthlyDetail) loggedIn
- )
+ update model (LoggedInMsg.HomeMsg <| HomeMsg.SearchMsg (Form.Reset (HomeModel.searchInitial frequency))) loggedIn
+ :> update model (LoggedInMsg.HomeMsg <| HomeMsg.SearchMsg Form.Submit)
+ :> update model (LoggedInMsg.HomeMsg <| HomeMsg.UpdatePage 1)
:> (\loggedIn ->
let newPayment = Payment paymentId (Date.fromTime model.currentTime) name cost loggedIn.me frequency
in ( { loggedIn | payments = newPayment :: loggedIn.payments }
@@ -96,9 +92,28 @@ update model msg loggedIn =
)
LoggedInMsg.ValidateDeletePayment paymentId ->
- ( { loggedIn | payments = deletePayment paymentId loggedIn.payments }
- , Cmd.none
- )
+ let payments = deletePayment paymentId loggedIn.payments
+ frequency =
+ case Form.getOutput loggedIn.home.search of
+ Just data -> data.frequency
+ Nothing -> Punctual
+ switchToPunctual =
+ ( frequency == Monthly
+ && List.isEmpty (Payment.monthly payments)
+ )
+ in if switchToPunctual
+ then
+ update model (LoggedInMsg.HomeMsg <| HomeMsg.SearchMsg (Form.Reset (HomeModel.searchInitial Punctual))) loggedIn
+ :> update model (LoggedInMsg.HomeMsg <| HomeMsg.SearchMsg Form.Submit)
+ :> (\loggedIn ->
+ ( { loggedIn | payments = payments }
+ , Cmd.none
+ )
+ )
+ else
+ ( { loggedIn | payments = payments }
+ , Cmd.none
+ )
LoggedInMsg.AddIncome time amount ->
( loggedIn