aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn
diff options
context:
space:
mode:
authorJoris2016-08-08 20:58:17 +0200
committerJoris2016-08-08 20:58:17 +0200
commit8816cf758119a6a2073e561c8df297a833630986 (patch)
tree20e63f3c0de15945b818a6d7a78359f9134b5e82 /src/client/elm/LoggedIn
parentb54d8e45fc8784d8fa6eaa03f58536b7a19cf70b (diff)
downloadbudget-8816cf758119a6a2073e561c8df297a833630986.tar.gz
budget-8816cf758119a6a2073e561c8df297a833630986.tar.bz2
budget-8816cf758119a6a2073e561c8df297a833630986.zip
Show incomes in a table and update like payments are updated
Diffstat (limited to 'src/client/elm/LoggedIn')
-rw-r--r--src/client/elm/LoggedIn/Home/Header/View.elm8
-rw-r--r--src/client/elm/LoggedIn/Home/View/Expand.elm29
-rw-r--r--src/client/elm/LoggedIn/Home/View/Table.elm23
-rw-r--r--src/client/elm/LoggedIn/Income/View.elm55
-rw-r--r--src/client/elm/LoggedIn/Income/View/Table.elm131
-rw-r--r--src/client/elm/LoggedIn/Msg.elm3
-rw-r--r--src/client/elm/LoggedIn/Stat/View.elm2
-rw-r--r--src/client/elm/LoggedIn/Update.elm19
8 files changed, 187 insertions, 83 deletions
diff --git a/src/client/elm/LoggedIn/Home/Header/View.elm b/src/client/elm/LoggedIn/Home/Header/View.elm
index 95cef3c..e6b2444 100644
--- a/src/client/elm/LoggedIn/Home/Header/View.elm
+++ b/src/client/elm/LoggedIn/Home/Header/View.elm
@@ -25,8 +25,8 @@ import Model.Conf exposing (Conf)
import Model.Payment as Payment exposing (Payments, Frequency(..))
import Model.Translations exposing (getMessage)
-import Dialog.Model as DialogModel
-import Dialog.AddPaymentButton.View as AddPaymentButton
+import Dialog.AddPayment.Model as AddPayment
+import Dialog.AddPayment.View as AddPayment
import LoggedIn.Home.View.ExceedingPayers as ExceedingPayers
import LoggedIn.View.Format as Format
@@ -42,9 +42,9 @@ view loggedData { search } payments frequency =
[ div
[ class "payerAndAdd" ]
[ ExceedingPayers.view loggedData
- , AddPaymentButton.view
+ , AddPayment.button
loggedData
- (DialogModel.addPaymentInitial loggedData.translations currentDate frequency)
+ (AddPayment.initialAdd loggedData.translations currentDate frequency)
"AddPayment"
(text (getMessage "AddPayment" loggedData.translations))
Nothing
diff --git a/src/client/elm/LoggedIn/Home/View/Expand.elm b/src/client/elm/LoggedIn/Home/View/Expand.elm
deleted file mode 100644
index 2bcfec1..0000000
--- a/src/client/elm/LoggedIn/Home/View/Expand.elm
+++ /dev/null
@@ -1,29 +0,0 @@
-module LoggedIn.Home.View.Expand exposing
- ( expand
- , ExpandType(..)
- )
-
-import View.Color as Color
-
-import FontAwesome
-
-import Html exposing (..)
-import Html.Attributes exposing (..)
-
-import Msg exposing (Msg)
-
-type ExpandType = ExpandUp | ExpandDown
-
-expand : ExpandType -> Bool -> Html Msg
-expand expandType isExpanded =
- div
- [ class "expand" ]
- [ (chevronIcon expandType isExpanded) Color.white 15 ]
-
-chevronIcon : ExpandType -> Bool -> (Color -> Int -> Html msg)
-chevronIcon expandType isExpanded =
- case (expandType, isExpanded) of
- (ExpandUp, True) -> FontAwesome.chevron_down
- (ExpandUp, False) -> FontAwesome.chevron_up
- (ExpandDown, True) -> FontAwesome.chevron_up
- (ExpandDown, False) -> FontAwesome.chevron_down
diff --git a/src/client/elm/LoggedIn/Home/View/Table.elm b/src/client/elm/LoggedIn/Home/View/Table.elm
index 429632c..6c12f31 100644
--- a/src/client/elm/LoggedIn/Home/View/Table.elm
+++ b/src/client/elm/LoggedIn/Home/View/Table.elm
@@ -14,8 +14,8 @@ import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Dialog
-import Dialog.Model as DialogModel
-import Dialog.AddPaymentButton.View as AddPaymentButton
+import Dialog.AddPayment.Model as AddPayment
+import Dialog.AddPayment.View as AddPayment
import Tooltip
@@ -25,8 +25,7 @@ import LoggedData exposing (LoggedData)
import LoggedIn.Msg as LoggedInMsg
-import LoggedIn.Home.Msg as HomeMsg
-import LoggedIn.Home.Model as HomeModel
+import LoggedIn.Home.Model as Home
import View.Date as Date
import LoggedIn.View.Format as Format
@@ -34,7 +33,7 @@ import Model.User exposing (getUserName)
import Model.Payment as Payment exposing (..)
import Model.Translations exposing (getMessage)
-view : LoggedData -> HomeModel.Model -> Payments -> Frequency -> Html Msg
+view : LoggedData -> Home.Model -> Payments -> Frequency -> Html Msg
view loggedData homeModel payments frequency =
let visiblePayments =
payments
@@ -48,7 +47,7 @@ view loggedData homeModel payments frequency =
, if List.isEmpty visiblePayments
then
div
- [ class "noPayment" ]
+ [ class "emptyTableMsg" ]
[ text <| getMessage "NoPayment" loggedData.translations ]
else
text ""
@@ -69,7 +68,7 @@ headerLine loggedData frequency =
, div [ class "cell" ] []
]
-paymentLine : LoggedData -> HomeModel.Model -> Frequency -> Payment -> Html Msg
+paymentLine : LoggedData -> Home.Model -> Frequency -> Payment -> Html Msg
paymentLine loggedData homeModel frequency payment =
div
[ class "row" ]
@@ -104,9 +103,9 @@ paymentLine loggedData homeModel frequency payment =
, div
[ class "cell button" ]
[ let currentDate = Date.fromTime loggedData.currentTime
- in AddPaymentButton.view
+ in AddPayment.button
loggedData
- (DialogModel.clonePaymentInitial loggedData.translations currentDate payment)
+ (AddPayment.initialClone loggedData.translations currentDate payment)
"ClonePayment"
(FontAwesome.clone Color.chestnutRose 18)
(Just (getMessage "Clone" loggedData.translations))
@@ -117,11 +116,11 @@ paymentLine loggedData homeModel frequency payment =
then
text ""
else
- AddPaymentButton.view
+ AddPayment.button
loggedData
- (DialogModel.editPaymentInitial loggedData.translations payment)
+ (AddPayment.initialEdit loggedData.translations payment)
"EditPayment"
- (FontAwesome.edit Color.chestnutRose 18)
+ (FontAwesome.pencil Color.chestnutRose 18)
(Just (getMessage "Edit" loggedData.translations))
]
, div
diff --git a/src/client/elm/LoggedIn/Income/View.elm b/src/client/elm/LoggedIn/Income/View.elm
index 2b69806..5a2c18e 100644
--- a/src/client/elm/LoggedIn/Income/View.elm
+++ b/src/client/elm/LoggedIn/Income/View.elm
@@ -19,6 +19,8 @@ import View.Form as Form
import View.Events exposing (onSubmitPrevDefault)
import Dialog
+import Dialog.AddIncome.Model as AddIncome
+import Dialog.AddIncome.View as AddIncome
import Msg exposing (Msg)
@@ -29,33 +31,42 @@ import Model.Translations exposing (getMessage, getParamMessage)
import Model.Payer exposing (useIncomesFrom)
import Model.User exposing (UserId, User)
import Model.View as View
-import LoggedIn.Income.Model as IncomeModel
+import LoggedIn.Income.Model as Income
import LoggedIn.Msg as LoggedInMsg
import LoggedIn.Income.Msg as IncomeMsg
import View.Date as Date
import LoggedIn.View.Format as Format
-
import View.Color as Color
+import LoggedIn.Income.View.Table as Table
-view : LoggedData -> IncomeModel.Model -> Html Msg
+view : LoggedData -> Income.Model -> Html Msg
view loggedData incomeModel =
div
[ class "income" ]
[ case useIncomesFrom loggedData.users loggedData.incomes loggedData.payments of
Just since -> cumulativeIncomesView loggedData since
Nothing -> text ""
- , h1 [] [ text <| getMessage "MonthlyNetIncomes" loggedData.translations ]
- , addIncomeView loggedData incomeModel.addIncome
- , incomesView loggedData
+ , div
+ [ class "textual monthlyNetIncomes" ]
+ [ h1 [] [ text <| getMessage "MonthlyNetIncomes" loggedData.translations ]
+ , AddIncome.button
+ "addIncome"
+ loggedData
+ (AddIncome.initialAdd loggedData.translations (Date.fromTime loggedData.currentTime))
+ "AddIncome"
+ (text (getMessage "AddIncome" loggedData.translations))
+ Nothing
+ ]
+ , Table.view loggedData incomeModel
]
cumulativeIncomesView : LoggedData -> Time -> Html Msg
cumulativeIncomesView loggedData since =
let longDate = Date.longView (Date.fromTime since) loggedData.translations
in div
- []
+ [ class "textual" ]
[ h1 [] [ text <| getParamMessage [longDate] "CumulativeIncomesSince" loggedData.translations ]
, ul
[]
@@ -75,36 +86,6 @@ cumulativeIncomesView loggedData since =
)
]
-addIncomeView : LoggedData -> Form String IncomeModel.AddIncome -> Html Msg
-addIncomeView loggedData addIncome =
- let htmlMap = Html.map (Msg.UpdateLoggedIn << LoggedInMsg.IncomeMsg << IncomeMsg.AddIncomeMsg)
- in Html.form
- [ onSubmitPrevDefault Msg.NoOp ]
- [ htmlMap <| Form.textInput loggedData.translations addIncome "income" "amount"
- , htmlMap <| Form.textInput loggedData.translations addIncome "income" "date"
- , button
- [ class "add"
- , case Form.getOutput addIncome of
- Just data ->
- onClick (Msg.UpdateLoggedIn <| LoggedInMsg.CreateIncome data.amount data.date)
- Nothing ->
- onClick (Msg.UpdateLoggedIn <| LoggedInMsg.IncomeMsg <| IncomeMsg.AddIncomeMsg <| Form.Submit)
- ]
- [ text (getMessage "Add" loggedData.translations) ]
- ]
-
-incomesView : LoggedData -> Html Msg
-incomesView loggedData =
- ul
- [ class "incomes" ]
- ( loggedData.incomes
- |> Dict.toList
- |> List.filter ((==) loggedData.me << .userId << snd)
- |> List.sortBy (.time << snd)
- |> List.reverse
- |> List.map (incomeView loggedData)
- )
-
incomeView : LoggedData -> (IncomeId, Income) -> Html Msg
incomeView loggedData (incomeId, income) =
li
diff --git a/src/client/elm/LoggedIn/Income/View/Table.elm b/src/client/elm/LoggedIn/Income/View/Table.elm
new file mode 100644
index 0000000..cf82772
--- /dev/null
+++ b/src/client/elm/LoggedIn/Income/View/Table.elm
@@ -0,0 +1,131 @@
+module LoggedIn.Income.View.Table exposing
+ ( view
+ )
+
+import Dict exposing (..)
+import Date exposing (Date)
+import String exposing (append)
+
+import FontAwesome
+import View.Color as Color
+
+import Html exposing (..)
+import Html.Attributes exposing (..)
+import Html.Events exposing (..)
+
+import Dialog
+import Dialog.AddIncome.Model as AddIncome
+import Dialog.AddIncome.View as AddIncome
+
+import Tooltip
+
+import Msg exposing (Msg)
+
+import LoggedData exposing (LoggedData)
+
+import LoggedIn.Msg as LoggedInMsg
+
+import LoggedIn.Income.Model as Income
+import View.Date as Date
+import LoggedIn.View.Format as Format
+
+import Model.User exposing (getUserName)
+import Model.Income as Income exposing (..)
+import Model.Translations exposing (getMessage)
+
+view : LoggedData -> Income.Model -> Html Msg
+view loggedData incomeModel =
+ let incomes =
+ loggedData.incomes
+ |> Dict.toList
+ |> List.sortBy (.time << snd)
+ |> List.reverse
+ in div
+ [ class "table" ]
+ [ div
+ [ class "lines" ]
+ ( headerLine loggedData :: List.map (paymentLine loggedData incomeModel) incomes)
+ , if List.isEmpty (Dict.toList loggedData.incomes)
+ then
+ div
+ [ class "emptyTableMsg" ]
+ [ text <| getMessage "NoPayment" loggedData.translations ]
+ else
+ text ""
+ ]
+
+headerLine : LoggedData -> Html Msg
+headerLine loggedData =
+ div
+ [ class "header" ]
+ [ div [ class "cell name" ] [ text <| getMessage "Name" loggedData.translations ]
+ , div [ class "cell income" ] [ text <| getMessage "Income" loggedData.translations ]
+ , div [ class "cell date" ] [ text <| getMessage "Date" loggedData.translations ]
+ , div [ class "cell" ] []
+ , div [ class "cell" ] []
+ , div [ class "cell" ] []
+ ]
+
+paymentLine : LoggedData -> Income.Model -> (IncomeId, Income) -> Html Msg
+paymentLine loggedData incomeModel (incomeId, income) =
+ div
+ [ class "row" ]
+ [ div
+ [ class "cell name" ]
+ [ income.userId
+ |> getUserName loggedData.users
+ |> Maybe.withDefault "−"
+ |> text
+ ]
+ , div
+ [ class "cell income" ]
+ [ text (Format.price loggedData.conf income.amount) ]
+ , div
+ [ class "cell date" ]
+ [ text (Date.longView (Date.fromTime income.time) loggedData.translations) ]
+ , div
+ [ class "cell button" ]
+ [ let currentDate = Date.fromTime loggedData.currentTime
+ in AddIncome.button
+ ""
+ loggedData
+ (AddIncome.initialClone loggedData.translations currentDate income)
+ "CloneIncome"
+ (FontAwesome.clone Color.chestnutRose 18)
+ (Just (getMessage "Clone" loggedData.translations))
+ ]
+ , div
+ [ class "cell button" ]
+ [ if loggedData.me /= income.userId
+ then
+ text ""
+ else
+ AddIncome.button
+ ""
+ loggedData
+ (AddIncome.initialEdit loggedData.translations incomeId income)
+ "EditIncome"
+ (FontAwesome.pencil Color.chestnutRose 18)
+ (Just (getMessage "Edit" loggedData.translations))
+ ]
+ , div
+ [ class "cell button" ]
+ [ if loggedData.me /= income.userId
+ then
+ text ""
+ else
+ let dialogConfig =
+ { className = "deleteIncomeDialog"
+ , title = getMessage "ConfirmIncomeDelete" loggedData.translations
+ , body = always <| text ""
+ , confirm = getMessage "Confirm" loggedData.translations
+ , confirmMsg = always <| Msg.Dialog <| Dialog.UpdateAndClose <| Msg.UpdateLoggedIn <| LoggedInMsg.DeleteIncome incomeId
+ , undo = getMessage "Undo" loggedData.translations
+ }
+ in button
+ ( Tooltip.show Msg.Tooltip (getMessage "Delete" loggedData.translations)
+ ++ [ onClick (Msg.Dialog <| Dialog.Open dialogConfig) ]
+ )
+ [ FontAwesome.trash Color.chestnutRose 18 ]
+ ]
+ ]
diff --git a/src/client/elm/LoggedIn/Msg.elm b/src/client/elm/LoggedIn/Msg.elm
index 77fb0ed..9bb87b9 100644
--- a/src/client/elm/LoggedIn/Msg.elm
+++ b/src/client/elm/LoggedIn/Msg.elm
@@ -27,5 +27,8 @@ type Msg =
| CreateIncome Int Date
| ValidateCreateIncome IncomeId Int Date
+ | EditIncome IncomeId Int Date
+ | ValidateEditIncome IncomeId Int Date
+
| DeleteIncome IncomeId
| ValidateDeleteIncome IncomeId
diff --git a/src/client/elm/LoggedIn/Stat/View.elm b/src/client/elm/LoggedIn/Stat/View.elm
index 636312d..a6faf5c 100644
--- a/src/client/elm/LoggedIn/Stat/View.elm
+++ b/src/client/elm/LoggedIn/Stat/View.elm
@@ -26,7 +26,7 @@ view loggedData =
let paymentsByMonth = Payment.groupAndSortByMonth (Payment.punctual loggedData.payments)
monthPaymentMean = getMonthPaymentMean loggedData paymentsByMonth
in div
- [ class "stat" ]
+ [ class "stat textual" ]
[ h1 [] [ text (getParamMessage [ Format.price loggedData.conf monthPaymentMean ] "ByMonthsAndMean" loggedData.translations) ]
, ul
[]
diff --git a/src/client/elm/LoggedIn/Update.elm b/src/client/elm/LoggedIn/Update.elm
index db851f1..68e840e 100644
--- a/src/client/elm/LoggedIn/Update.elm
+++ b/src/client/elm/LoggedIn/Update.elm
@@ -15,6 +15,7 @@ import Form
import Model exposing (Model)
import Model.Translations exposing (getMessage)
import Model.Payment as Payment exposing (Payment, Frequency(..))
+import Model.Income as Income exposing (Income)
import Server
import LoggedData
@@ -139,6 +140,24 @@ update model msg loggedIn =
, Cmd.none
)
+ LoggedInMsg.EditIncome incomeId amount date ->
+ ( loggedIn
+ , Server.editIncome incomeId amount date
+ |> Task.perform
+ (always LoggedInMsg.NoOp)
+ (always <| LoggedInMsg.ValidateEditIncome incomeId amount date)
+ )
+
+ LoggedInMsg.ValidateEditIncome incomeId amount date ->
+ let updatedIncome = Income loggedIn.me (Date.toTime date) amount
+ updateIncome mbIncome =
+ case mbIncome of
+ Just _ -> Just updatedIncome
+ Nothing -> Just updatedIncome
+ in ( { loggedIn | incomes = Dict.update incomeId updateIncome loggedIn.incomes }
+ , Cmd.none
+ )
+
LoggedInMsg.DeleteIncome incomeId ->
( loggedIn
, Server.deleteIncome incomeId