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
59
60
61
|
module Component.Table
( table
, TableIn(..)
, TableOut(..)
) where
import Data.Text (Text)
import Reflex.Dom (Dynamic, Event, MonadWidget)
import qualified Reflex.Dom as R
import Component.Pages (PagesIn (..), PagesOut (..))
import qualified Component.Pages as Pages
data TableIn h r t = TableIn
{ _tableIn_headerLabel :: h -> Text
, _tableIn_rows :: Dynamic t [r]
, _tableIn_cell :: h -> r -> Text
, _tableIn_perPage :: Int
, _tableIn_resetPage :: Event t ()
}
data TableOut = TableOut
{}
table :: forall t m h r. (MonadWidget t m, Bounded h, Enum h) => TableIn h r t -> m (TableOut)
table tableIn =
R.divClass "table" $ do
rec
R.divClass "lines" $ do
R.divClass "header" $
flip mapM_ [minBound..] $ \header ->
R.divClass "cell" . R.text $
_tableIn_headerLabel tableIn header
let rows = getRange
(_tableIn_perPage tableIn)
<$> (_pagesOut_currentPage pages)
<*> (_tableIn_rows tableIn)
R.simpleList rows $ \r ->
R.divClass "row" $
flip mapM_ [minBound..] $ \h ->
R.divClass "cell name" $
R.dynText $
R.ffor r (_tableIn_cell tableIn h)
pages <- Pages.widget $ PagesIn
{ _pagesIn_total = length <$> (_tableIn_rows tableIn)
, _pagesIn_perPage = _tableIn_perPage tableIn
, _pagesIn_reset = _tableIn_resetPage tableIn
}
return ()
return $ TableOut
{}
getRange :: forall a. Int -> Int -> [a] -> [a]
getRange perPage currentPage =
take perPage . drop ((currentPage - 1) * perPage)
|