aboutsummaryrefslogtreecommitdiff
path: root/src/client/LoggedIn/Update.elm
diff options
context:
space:
mode:
authorJoris2017-04-02 17:51:12 +0200
committerJoris2017-04-02 21:07:08 +0200
commit5c110716cfda6e616a795edd12f2012b132dca9f (patch)
tree71c3d04780302edf0648bec1cd914757cdbb2883 /src/client/LoggedIn/Update.elm
parent64ff4707fdcd81c27c6be9903c3c82bc543ef016 (diff)
Add a chart on payments by month by categories
Diffstat (limited to 'src/client/LoggedIn/Update.elm')
-rw-r--r--src/client/LoggedIn/Update.elm73
1 files changed, 39 insertions, 34 deletions
diff --git a/src/client/LoggedIn/Update.elm b/src/client/LoggedIn/Update.elm
index 753b1d3..a1d5f7d 100644
--- a/src/client/LoggedIn/Update.elm
+++ b/src/client/LoggedIn/Update.elm
@@ -2,55 +2,60 @@ module LoggedIn.Update exposing
( update
)
+import Date exposing (Date)
import Dict
-import String
-import Task
-
+import Form
import Http exposing (Error(..))
-import Date exposing (Date)
import Platform.Cmd exposing (Cmd)
+import String
+import Task
-import Form
-
+import LoggedData
+import LoggedIn.Home.Model as Home
+import LoggedIn.Home.Msg as Home
+import LoggedIn.Home.Update as Home
+import LoggedIn.Model as LoggedInModel
+import LoggedIn.Msg as LoggedIn
+import LoggedIn.Stat.Model as Stat
+import LoggedIn.Stat.Msg as Stat
+import LoggedIn.Stat.Update as Stat
import Model exposing (Model)
-import Model.Payment as Payment exposing (Payment)
+import Model.Category exposing (Category)
import Model.Frequency exposing (Frequency(..))
import Model.Income as Income exposing (Income)
-import Model.Category exposing (Category)
+import Model.Payment as Payment exposing (Payment)
import Model.PaymentCategory as PaymentCategory
-
import Server
-import LoggedData
-
-import LoggedIn.Msg as LoggedInMsg
-import LoggedIn.Model as LoggedInModel
-
-import LoggedIn.Home.Msg as Home
-import LoggedIn.Home.Update as Home
-import LoggedIn.Home.Model as Home
import Utils.Cmd exposing ((:>))
-update : Model -> LoggedInMsg.Msg -> LoggedInModel.Model -> (LoggedInModel.Model, Cmd LoggedInMsg.Msg)
+update : Model -> LoggedIn.Msg -> LoggedInModel.Model -> (LoggedInModel.Model, Cmd LoggedIn.Msg)
update model msg loggedIn =
- let loggedData = LoggedData.build model loggedIn
+ let loggedData = LoggedData.build model.currentTime model.translations model.conf loggedIn
in case msg of
- LoggedInMsg.NoOp ->
+ LoggedIn.NoOp ->
( loggedIn
, Cmd.none
)
- LoggedInMsg.HomeMsg homeMsg ->
+ LoggedIn.HomeMsg homeMsg ->
case Home.update loggedData homeMsg loggedIn.home of
(home, effects) ->
( { loggedIn | home = home }
- , Cmd.map LoggedInMsg.HomeMsg effects
+ , Cmd.map LoggedIn.HomeMsg effects
+ )
+
+ LoggedIn.StatMsg statMsg ->
+ case Stat.update loggedData statMsg loggedIn.stat of
+ (stat, effects) ->
+ ( { loggedIn | stat = stat }
+ , Cmd.map LoggedIn.StatMsg effects
)
- LoggedInMsg.ValidateCreatePayment paymentId name cost date category frequency ->
- update model (LoggedInMsg.HomeMsg <| Home.SearchMsg (Form.Reset (Home.searchInitial frequency))) loggedIn
- :> update model (LoggedInMsg.HomeMsg <| Home.UpdatePage 1)
+ LoggedIn.ValidateCreatePayment paymentId name cost date category frequency ->
+ update model (LoggedIn.HomeMsg <| Home.SearchMsg (Form.Reset (Home.searchInitial frequency))) loggedIn
+ :> update model (LoggedIn.HomeMsg <| Home.UpdatePage 1)
:> (\loggedIn ->
let newPayment = Payment paymentId name cost date loggedIn.me frequency
in ( { loggedIn
@@ -61,7 +66,7 @@ update model msg loggedIn =
)
)
- LoggedInMsg.ValidateEditPayment paymentId name cost date category frequency ->
+ LoggedIn.ValidateEditPayment paymentId name cost date category frequency ->
let updatedPayment = Payment paymentId name cost date loggedIn.me frequency
mbOldPayment = Payment.find paymentId loggedIn.payments
in ( { loggedIn
@@ -76,7 +81,7 @@ update model msg loggedIn =
, Cmd.none
)
- LoggedInMsg.ValidateDeletePayment paymentId ->
+ LoggedIn.ValidateDeletePayment paymentId ->
let payments = Payment.delete paymentId loggedIn.payments
frequency =
case Form.getOutput loggedIn.home.search of
@@ -88,7 +93,7 @@ update model msg loggedIn =
)
in if switchToPunctual
then
- update model (LoggedInMsg.HomeMsg <| Home.SearchMsg (Form.Reset (Home.searchInitial Punctual))) loggedIn
+ update model (LoggedIn.HomeMsg <| Home.SearchMsg (Form.Reset (Home.searchInitial Punctual))) loggedIn
:> (\loggedIn ->
( { loggedIn | payments = payments }
, Cmd.none
@@ -99,34 +104,34 @@ update model msg loggedIn =
, Cmd.none
)
- LoggedInMsg.ValidateCreateIncome incomeId amount date ->
+ LoggedIn.ValidateCreateIncome incomeId amount date ->
let newIncome = { userId = loggedIn.me, amount = amount, time = Date.toTime date }
in ( { loggedIn | incomes = Dict.insert incomeId newIncome loggedIn.incomes }
, Cmd.none
)
- LoggedInMsg.ValidateEditIncome incomeId amount date ->
+ LoggedIn.ValidateEditIncome incomeId amount date ->
let updateIncome _ = Just <| Income loggedIn.me (Date.toTime date) amount
in ( { loggedIn | incomes = Dict.update incomeId updateIncome loggedIn.incomes }
, Cmd.none
)
- LoggedInMsg.ValidateDeleteIncome incomeId ->
+ LoggedIn.ValidateDeleteIncome incomeId ->
( { loggedIn | incomes = Dict.remove incomeId loggedIn.incomes }
, Cmd.none
)
- LoggedInMsg.ValidateCreateCategory categoryId name color ->
+ LoggedIn.ValidateCreateCategory categoryId name color ->
let newCategory = { name = name, color = color }
in ( { loggedIn | categories = Dict.insert categoryId newCategory loggedIn.categories }
, Cmd.none
)
- LoggedInMsg.ValidateEditCategory categoryId name color ->
+ LoggedIn.ValidateEditCategory categoryId name color ->
let updateCategory _ = Just <| Category name color
in ( { loggedIn | categories = Dict.update categoryId updateCategory loggedIn.categories } , Cmd.none)
- LoggedInMsg.ValidateDeleteCategory categoryId ->
+ LoggedIn.ValidateDeleteCategory categoryId ->
( { loggedIn | categories = Dict.remove categoryId loggedIn.categories }
, Cmd.none
)