@@ -9,27 +9,43 @@ import App.Types
9
9
import Codec.Xlsx
10
10
import qualified Data.ByteString.Lazy as BL
11
11
import qualified Data.Map as Map
12
- import Functora.Miso.Prelude hiding ( (^.) , _Just )
13
- import Lens.Micro hiding ( each , to )
12
+ import Functora.Miso.Prelude
13
+ import Lens.Micro ( (?~) , (^..) )
14
14
15
15
newXlsx :: St Unique -> Map Unicode Rfc2397 -> BL. ByteString
16
16
newXlsx st imgs = xlsx
17
17
where
18
18
xlsx =
19
19
fromXlsx 0
20
20
$ def
21
- & atSheet " Delivery Calculator" ?~ sheet
21
+ & atSheet " Delivery Calculator"
22
+ ?~ sheet
22
23
sheet =
23
24
def
24
- & # wsDrawing ?~ Drawing mempty
25
+ & # wsDrawing
26
+ .~ Just (Drawing mempty )
27
+ & # wsRowPropertiesMap
28
+ .~ newRowProps rows
25
29
& addHeader st
26
- & flip
27
- (foldl $ addRow imgs)
28
- ( zip [2 .. ]
29
- $ fmap
30
- (^.. # assetFieldPairs . each . # fieldPairValue)
31
- (st ^. # stAssets)
32
- )
30
+ & flip (foldl $ addRow imgs) rows
31
+ rows =
32
+ zip [2 .. ]
33
+ $ fmap
34
+ (^.. # assetFieldPairs . each . # fieldPairValue)
35
+ (st ^. # stAssets)
36
+
37
+ newRowProps ::
38
+ [(RowIndex , [Field DynamicField Unique ])] ->
39
+ Map RowIndex RowProperties
40
+ newRowProps =
41
+ Map. fromList
42
+ . catMaybes
43
+ . fmap
44
+ ( \ (rowIdx, rowVal) ->
45
+ if any (\ x -> x ^. # fieldType == FieldTypeImage ) rowVal
46
+ then Just (rowIdx, def & # rowHeight ?~ CustomHeight 200 )
47
+ else Nothing
48
+ )
33
49
34
50
addHeader :: St Unique -> Worksheet -> Worksheet
35
51
addHeader st sheet =
@@ -39,7 +55,8 @@ addHeader st sheet =
39
55
foldl
40
56
( \ acc (colIdx, colVal) ->
41
57
acc
42
- & cellValueAt (1 , colIdx) ?~ CellText colVal
58
+ & cellValueAt (1 , colIdx)
59
+ ?~ CellText colVal
43
60
)
44
61
sheet
45
62
$ zip [1 .. ] rowVal
@@ -80,18 +97,20 @@ addCol imgs sheet rowIdx colIdx field =
80
97
then
81
98
sheet
82
99
& cellValueAt (rowIdx, colIdx)
83
- ?~ CellText txt
100
+ ?~ CellText txt
84
101
else case Map. lookup txt imgs of
85
102
--
86
103
-- TODO : handle img link
87
104
--
88
105
Nothing ->
89
106
sheet
90
107
& cellValueAt (rowIdx, colIdx)
91
- ?~ CellText txt
108
+ ?~ CellText txt
92
109
Just img ->
93
110
sheet
94
- & # wsDrawing . _Just %~ \ case
111
+ & # wsDrawing
112
+ . _Just
113
+ %~ \ case
95
114
Drawing xs ->
96
115
Drawing $ newImg rowIdx colIdx (length xs) img : xs
97
116
where
0 commit comments