-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableData.icl
76 lines (71 loc) · 2.55 KB
/
TableData.icl
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
implementation module TableData
import TableData
// A table without headers
instance TableData [[a]] | iTask a where
htmlTable data = TableTag [ClassAttr "customTable"]
[ TrTag []
[ TdTag [] [Text (toSingleLineText element)]
\\ element <- row
]
\\ row <- data
]
appendTable left right = [ lRow ++ rRow \\ lRow <- left & rRow <- right ]
// A table with headers
instance TableData ([a], [[b]]) | iTask a & iTask b where
htmlTable (headers, data) = TableTag [ClassAttr "customTable"] (headerTags ++ rowTags)
where
headerTags =
[ TrTag []
[ ThTag [] [Text (toSingleLineText header)]
\\ header <- headers
]
]
rowTags =
[ TrTag []
[ TdTag [] [Text (toSingleLineText element)]
\\ element <- row
]
\\ row <- data
]
appendTable (leftHeaders, leftRows) (rightHeaders, rightRows) = (bothHeaders, bothRows)
where
bothHeaders = leftHeaders ++ rightHeaders
bothRows = [ lRow ++ rRow \\ lRow <- leftRows & rRow <- rightRows ]
// A table with headers where columns and rows can have css classes
instance TableData ([a], [Maybe String], [([b], Maybe String)]) | iTask a & iTask b where
htmlTable (headers, columns, rows) = TableTag [ClassAttr "customTable"]
(colTags ++ headerTags ++ rowTags)
where
colTags =
[ ColTag (maybe [] (\columnClass -> [ClassAttr columnClass]) mColumnClass) []
\\ mColumnClass <- columns
]
headerTags =
[ TrTag []
[ ThTag [] [Text (toSingleLineText header)]
\\ header <- headers
]
]
rowTags =
[ TrTag (maybe [] (\rowClass -> [ClassAttr rowClass]) mRowClass)
[ TdTag [] [Text (toSingleLineText element)]
\\ element <- row
]
\\ (row, mRowClass) <- rows
]
appendTable (lHeaders, lColClasses, lRows) (rHeaders, rColClasses, rRows) =
(bothHeaders, bothColClasses, bothRows)
where
bothHeaders = lHeaders ++ rHeaders
bothColClasses = lColClasses ++ rColClasses
bothRows =
[ (lRow ++ rRow, combineRowClasses lClass rClass)
\\ (lRow, lClass) <- lRows
& (rRow, rClass) <- rRows
]
combineRowClasses Nothing Nothing = Nothing
combineRowClasses l=:(Just _) Nothing = l
combineRowClasses Nothing r=:(Just _) = r
combineRowClasses (Just lClass) (Just rClass) = Just (lClass +++ " " +++ rClass)
viewAsTable :: !d !m -> (Task m) | toPrompt d & TableData m & iTask m
viewAsTable desc data = viewInformation desc [ViewUsing htmlTable htmlView] data