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/Header/View.elm1
-rw-r--r--src/client/elm/LoggedIn/Home/View/Table.elm14
-rw-r--r--src/client/elm/LoggedIn/Income/View.elm2
-rw-r--r--src/client/elm/LoggedIn/Msg.elm11
-rw-r--r--src/client/elm/LoggedIn/Update.elm40
5 files changed, 46 insertions, 22 deletions
diff --git a/src/client/elm/LoggedIn/Home/Header/View.elm b/src/client/elm/LoggedIn/Home/Header/View.elm
index 753a120..b23e6fe 100644
--- a/src/client/elm/LoggedIn/Home/Header/View.elm
+++ b/src/client/elm/LoggedIn/Home/Header/View.elm
@@ -52,6 +52,7 @@ searchLine loggedData search frequency =
, AddPaymentButton.view
loggedData
(DialogModel.addPaymentInitial loggedData.translations currentDate frequency)
+ "AddPayment"
(text (getMessage "AddPayment" loggedData.translations))
]
diff --git a/src/client/elm/LoggedIn/Home/View/Table.elm b/src/client/elm/LoggedIn/Home/View/Table.elm
index d2087bb..ebffeb9 100644
--- a/src/client/elm/LoggedIn/Home/View/Table.elm
+++ b/src/client/elm/LoggedIn/Home/View/Table.elm
@@ -64,6 +64,7 @@ headerLine loggedData frequency =
Monthly -> text ""
, div [ class "cell" ] []
, div [ class "cell" ] []
+ , div [ class "cell" ] []
]
paymentLine : LoggedData -> HomeModel.Model -> Frequency -> Payment -> Html Msg
@@ -104,6 +105,7 @@ paymentLine loggedData homeModel frequency payment =
in AddPaymentButton.view
loggedData
(DialogModel.clonePaymentInitial loggedData.translations currentDate payment)
+ "ClonePayment"
(FontAwesome.clone Color.chestnutRose 18)
]
, div
@@ -112,6 +114,18 @@ paymentLine loggedData homeModel frequency payment =
then
text ""
else
+ AddPaymentButton.view
+ loggedData
+ (DialogModel.editPaymentInitial loggedData.translations payment)
+ "EditPayment"
+ (FontAwesome.edit Color.chestnutRose 18)
+ ]
+ , div
+ [ class "cell button" ]
+ [ if loggedData.me /= payment.userId
+ then
+ text ""
+ else
let dialogConfig =
{ className = "paymentDialog"
, title = getMessage "ConfirmPaymentDelete" loggedData.translations
diff --git a/src/client/elm/LoggedIn/Income/View.elm b/src/client/elm/LoggedIn/Income/View.elm
index 6466f70..9638ddc 100644
--- a/src/client/elm/LoggedIn/Income/View.elm
+++ b/src/client/elm/LoggedIn/Income/View.elm
@@ -86,7 +86,7 @@ addIncomeView loggedData addIncome =
[ class "add"
, case Form.getOutput addIncome of
Just data ->
- onClick (Msg.UpdateLoggedIn <| LoggedInMsg.AddIncome data.amount data.date)
+ onClick (Msg.UpdateLoggedIn <| LoggedInMsg.CreateIncome data.amount data.date)
Nothing ->
onClick (Msg.UpdateLoggedIn <| LoggedInMsg.IncomeMsg <| IncomeMsg.AddIncomeMsg <| Form.Submit)
]
diff --git a/src/client/elm/LoggedIn/Msg.elm b/src/client/elm/LoggedIn/Msg.elm
index cbae67f..77fb0ed 100644
--- a/src/client/elm/LoggedIn/Msg.elm
+++ b/src/client/elm/LoggedIn/Msg.elm
@@ -15,14 +15,17 @@ type Msg =
| HomeMsg HomeMsg.Msg
| IncomeMsg IncomeMsg.Msg
- | AddPayment String Int Date Frequency
- | ValidateAddPayment PaymentId String Int Date Frequency
+ | CreatePayment String Int Date Frequency
+ | ValidateCreatePayment PaymentId String Int Date Frequency
+
+ | EditPayment PaymentId String Int Date Frequency
+ | ValidateEditPayment PaymentId String Int Date Frequency
| DeletePayment PaymentId
| ValidateDeletePayment PaymentId
- | AddIncome Int Date
- | ValidateAddIncome IncomeId Int Date
+ | CreateIncome Int Date
+ | ValidateCreateIncome IncomeId Int Date
| DeleteIncome IncomeId
| ValidateDeleteIncome IncomeId
diff --git a/src/client/elm/LoggedIn/Update.elm b/src/client/elm/LoggedIn/Update.elm
index 1f09271..db851f1 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 as Payment exposing (Payment, Frequency(..), deletePayment)
+import Model.Payment as Payment exposing (Payment, Frequency(..))
import Server
import LoggedData
@@ -58,23 +58,16 @@ update model msg loggedIn =
, Cmd.map LoggedInMsg.IncomeMsg cmd
)
- LoggedInMsg.AddPayment name cost date frequency ->
+ LoggedInMsg.CreatePayment name cost date frequency ->
( loggedIn
, Server.createPayment name cost date frequency
|> Task.perform
- (\err ->
- case err of
- BadResponse 400 jsonErr ->
- LoggedInMsg.NoOp
- _ ->
- LoggedInMsg.NoOp
- )
- (\paymentId -> LoggedInMsg.ValidateAddPayment paymentId name cost date frequency)
+ (always LoggedInMsg.NoOp)
+ (\paymentId -> LoggedInMsg.ValidateCreatePayment paymentId name cost date frequency)
)
- LoggedInMsg.ValidateAddPayment paymentId name cost date frequency ->
+ LoggedInMsg.ValidateCreatePayment paymentId name cost date frequency ->
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 name cost date loggedIn.me frequency
@@ -83,6 +76,20 @@ update model msg loggedIn =
)
)
+ LoggedInMsg.EditPayment paymentId name cost date frequency ->
+ ( loggedIn
+ , Server.editPayment paymentId name cost date frequency
+ |> Task.perform
+ (always LoggedInMsg.NoOp)
+ (always <| LoggedInMsg.ValidateEditPayment paymentId name cost date frequency)
+ )
+
+ LoggedInMsg.ValidateEditPayment paymentId name cost date frequency ->
+ let updatedPayment = Payment paymentId name cost date loggedIn.me frequency
+ in ( { loggedIn | payments = Payment.edit updatedPayment loggedIn.payments }
+ , Cmd.none
+ )
+
LoggedInMsg.DeletePayment paymentId ->
( loggedIn
, Server.deletePayment paymentId
@@ -92,7 +99,7 @@ update model msg loggedIn =
)
LoggedInMsg.ValidateDeletePayment paymentId ->
- let payments = deletePayment paymentId loggedIn.payments
+ let payments = Payment.delete paymentId loggedIn.payments
frequency =
case Form.getOutput loggedIn.home.search of
Just data -> data.frequency
@@ -104,7 +111,6 @@ update model msg loggedIn =
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
@@ -115,15 +121,15 @@ update model msg loggedIn =
, Cmd.none
)
- LoggedInMsg.AddIncome amount date ->
+ LoggedInMsg.CreateIncome amount date ->
( loggedIn
, Server.createIncome amount date
|> Task.perform
(always LoggedInMsg.NoOp)
- (\incomeId -> (LoggedInMsg.ValidateAddIncome incomeId amount date))
+ (\incomeId -> (LoggedInMsg.ValidateCreateIncome incomeId amount date))
)
- LoggedInMsg.ValidateAddIncome incomeId amount date ->
+ LoggedInMsg.ValidateCreateIncome incomeId amount date ->
let newIncome = { userId = loggedIn.me, amount = amount, time = Date.toTime date }
loggedInIncome = loggedIn.income
in ( { loggedIn