blob: 5363ca556a6a3e5c1bdcea17c3ddae18bba6c770 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
module View.Income.Table
( view
, IncomeTableIn(..)
) where
import qualified Data.List as L
import qualified Data.Maybe as Maybe
import Data.Text (Text)
import Reflex.Dom (Dynamic, MonadWidget)
import qualified Reflex.Dom as R
import Common.Model (Income (..), Init (..), 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
data IncomeTableIn t = IncomeTableIn
{ _tableIn_init :: Init
, _tableIn_incomes :: Dynamic t [Income]
}
view :: forall t m. MonadWidget t m => IncomeTableIn t -> m ()
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_perPage = 7
, _tableIn_resetPage = R.never
}
return ()
data Header
= UserHeader
| AmountHeader
| DateHeader
deriving (Eq, Show, Bounded, Enum)
headerLabel :: Header -> Text
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 =
case header of
UserHeader ->
Maybe.fromMaybe "" . fmap _user_name $ CM.findUser (_income_userId income) (_init_users init)
DateHeader ->
Format.longDay . _income_date $ income
AmountHeader ->
Format.price (_init_currency init) . _income_amount $ income
|