aboutsummaryrefslogtreecommitdiff
path: root/client/src/View/Income
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/View/Income')
-rw-r--r--client/src/View/Income/Form.hs4
-rw-r--r--client/src/View/Income/Header.hs11
-rw-r--r--client/src/View/Income/Income.hs73
-rw-r--r--client/src/View/Income/Init.hs11
-rw-r--r--client/src/View/Income/Table.hs17
5 files changed, 83 insertions, 33 deletions
diff --git a/client/src/View/Income/Form.hs b/client/src/View/Income/Form.hs
index b8a9094..2bfc23f 100644
--- a/client/src/View/Income/Form.hs
+++ b/client/src/View/Income/Form.hs
@@ -109,5 +109,5 @@ view formIn = do
where
ajax =
case _formIn_httpMethod formIn of
- Post -> Ajax.postJson
- Put -> Ajax.putJson
+ Post -> Ajax.post
+ Put -> Ajax.put
diff --git a/client/src/View/Income/Header.hs b/client/src/View/Income/Header.hs
index e384161..4e08955 100644
--- a/client/src/View/Income/Header.hs
+++ b/client/src/View/Income/Header.hs
@@ -11,19 +11,22 @@ import qualified Data.Time.Clock as Clock
import Reflex.Dom (Dynamic, Event, MonadWidget)
import qualified Reflex.Dom as R
-import Common.Model (Income (..), Init (..), User (..))
+import Common.Model (Currency, Income (..), User (..))
import qualified Common.Model as CM
import qualified Common.Msg as Msg
import qualified Common.View.Format as Format
+
import Component (ButtonOut (..))
import qualified Component
import qualified Component.Modal as Modal
import qualified Util.Date as DateUtil
import qualified View.Income.Add as Add
+import View.Income.Init (Init (..))
data HeaderIn t = HeaderIn
- { _headerIn_init :: Init
- , _headerIn_incomes :: Dynamic t [Income]
+ { _headerIn_init :: Init
+ , _headerIn_currency :: Currency
+ , _headerIn_incomes :: Dynamic t [Income]
}
data HeaderOut t = HeaderOut
@@ -55,7 +58,7 @@ view headerIn =
T.intercalate " "
[ _user_name user
, "−"
- , Format.price (_init_currency init) $
+ , Format.price (_headerIn_currency headerIn) $
CM.cumulativeIncomesSince currentTime since userIncomes
]
diff --git a/client/src/View/Income/Income.hs b/client/src/View/Income/Income.hs
index 167aedf..91682a0 100644
--- a/client/src/View/Income/Income.hs
+++ b/client/src/View/Income/Income.hs
@@ -1,40 +1,73 @@
module View.Income.Income
- ( view
+ ( init
+ , view
, IncomeIn(..)
) where
+import Prelude hiding (init)
import Reflex.Dom (Dynamic, MonadWidget)
import qualified Reflex.Dom as R
-import Common.Model (Init (..))
+import Common.Model (Currency)
+
+import Model.Loadable (Loadable (..))
+import qualified Model.Loadable as Loadable
+import qualified Util.Ajax as AjaxUtil
import View.Income.Header (HeaderIn (..), HeaderOut (..))
import qualified View.Income.Header as Header
+import View.Income.Init (Init (..))
import View.Income.Table (IncomeTableIn (..))
import qualified View.Income.Table as Table
-data IncomeIn = IncomeIn
- { _incomeIn_init :: Init
+data IncomeIn t = IncomeIn
+ { _incomeIn_currency :: Currency
+ , _incomeIn_init :: Dynamic t (Loadable Init)
}
-view :: forall t m. MonadWidget t m => IncomeIn -> m ()
-view incomeIn =
- R.elClass "main" "income" $ do
+init :: forall t m. MonadWidget t m => m (Dynamic t (Loadable Init))
+init = do
+ postBuild <- R.getPostBuild
+
+ usersEvent <- AjaxUtil.get (R.tag (R.constant "api/users") postBuild)
+ users <- Loadable.fromEvent usersEvent
+
+ incomesEvent <- AjaxUtil.get (R.tag (R.constant "api/incomes") postBuild)
+ incomes <- Loadable.fromEvent incomesEvent
+
+ paymentsEvent <- AjaxUtil.get (R.tag (R.constant "api/payments") postBuild)
+ payments <- Loadable.fromEvent paymentsEvent
+
+ return $ do
+ us <- users
+ is <- incomes
+ ps <- payments
+ return $ Init <$> us <*> is <*> ps
+
+view :: forall t m. MonadWidget t m => IncomeIn t -> m ()
+view incomeIn = do
+ R.dyn . R.ffor (_incomeIn_init incomeIn) . Loadable.view $ \init ->
+
+ R.elClass "main" "income" $ do
+
+ rec
- rec
+ incomes <- R.foldDyn
+ (:)
+ (_init_incomes init)
+ (_headerOut_addIncome header)
- incomes <- R.foldDyn
- (:)
- (_init_incomes . _incomeIn_init $ incomeIn)
- (_headerOut_addIncome header)
+ header <- Header.view $ HeaderIn
+ { _headerIn_init = init
+ , _headerIn_currency = _incomeIn_currency incomeIn
+ , _headerIn_incomes = incomes
+ }
- header <- Header.view $ HeaderIn
- { _headerIn_init = _incomeIn_init incomeIn
- , _headerIn_incomes = incomes
+ Table.view $ IncomeTableIn
+ { _tableIn_init = init
+ , _tableIn_currency = _incomeIn_currency incomeIn
+ , _tableIn_incomes = incomes
}
- Table.view $ IncomeTableIn
- { _tableIn_init = _incomeIn_init incomeIn
- , _tableIn_incomes = incomes
- }
+ return ()
- return ()
+ return ()
diff --git a/client/src/View/Income/Init.hs b/client/src/View/Income/Init.hs
new file mode 100644
index 0000000..4f3ef99
--- /dev/null
+++ b/client/src/View/Income/Init.hs
@@ -0,0 +1,11 @@
+module View.Income.Init
+ ( Init(..)
+ ) where
+
+import Common.Model (Income, Payment, User)
+
+data Init = Init
+ { _init_users :: [User]
+ , _init_incomes :: [Income]
+ , _init_payments :: [Payment]
+ } deriving (Show)
diff --git a/client/src/View/Income/Table.hs b/client/src/View/Income/Table.hs
index 5363ca5..d42848b 100644
--- a/client/src/View/Income/Table.hs
+++ b/client/src/View/Income/Table.hs
@@ -9,16 +9,19 @@ import Data.Text (Text)
import Reflex.Dom (Dynamic, MonadWidget)
import qualified Reflex.Dom as R
-import Common.Model (Income (..), Init (..), User (..))
+import Common.Model (Currency, Income (..), User (..))
import qualified Common.Model as CM
import qualified Common.Msg as Msg
import qualified Common.View.Format as Format
+
import Component (TableIn (..))
import qualified Component
+import View.Income.Init (Init (..))
data IncomeTableIn t = IncomeTableIn
- { _tableIn_init :: Init
- , _tableIn_incomes :: Dynamic t [Income]
+ { _tableIn_init :: Init
+ , _tableIn_currency :: Currency
+ , _tableIn_incomes :: Dynamic t [Income]
}
view :: forall t m. MonadWidget t m => IncomeTableIn t -> m ()
@@ -27,7 +30,7 @@ view tableIn = do
Component.table $ TableIn
{ _tableIn_headerLabel = headerLabel
, _tableIn_rows = R.ffor (_tableIn_incomes tableIn) $ reverse . L.sortOn _income_date
- , _tableIn_cell = cell (_tableIn_init tableIn)
+ , _tableIn_cell = cell (_tableIn_init tableIn) (_tableIn_currency tableIn)
, _tableIn_perPage = 7
, _tableIn_resetPage = R.never
}
@@ -45,8 +48,8 @@ headerLabel UserHeader = Msg.get Msg.Income_Name
headerLabel DateHeader = Msg.get Msg.Income_Date
headerLabel AmountHeader = Msg.get Msg.Income_Amount
-cell :: Init -> Header -> Income -> Text
-cell init header income =
+cell :: Init -> Currency -> Header -> Income -> Text
+cell init currency header income =
case header of
UserHeader ->
Maybe.fromMaybe "" . fmap _user_name $ CM.findUser (_income_userId income) (_init_users init)
@@ -55,4 +58,4 @@ cell init header income =
Format.longDay . _income_date $ income
AmountHeader ->
- Format.price (_init_currency init) . _income_amount $ income
+ Format.price currency . _income_amount $ income