Skip to content

Commit 443e384

Browse files
committed
bigger img cell height
1 parent 7c072e6 commit 443e384

File tree

1 file changed

+34
-15
lines changed
  • ghcjs/delivery-calculator/src/App

1 file changed

+34
-15
lines changed

ghcjs/delivery-calculator/src/App/Xlsx.hs

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,43 @@ import App.Types
99
import Codec.Xlsx
1010
import qualified Data.ByteString.Lazy as BL
1111
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 ((?~), (^..))
1414

1515
newXlsx :: St Unique -> Map Unicode Rfc2397 -> BL.ByteString
1616
newXlsx st imgs = xlsx
1717
where
1818
xlsx =
1919
fromXlsx 0
2020
$ def
21-
& atSheet "Delivery Calculator" ?~ sheet
21+
& atSheet "Delivery Calculator"
22+
?~ sheet
2223
sheet =
2324
def
24-
& #wsDrawing ?~ Drawing mempty
25+
& #wsDrawing
26+
.~ Just (Drawing mempty)
27+
& #wsRowPropertiesMap
28+
.~ newRowProps rows
2529
& 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+
)
3349

3450
addHeader :: St Unique -> Worksheet -> Worksheet
3551
addHeader st sheet =
@@ -39,7 +55,8 @@ addHeader st sheet =
3955
foldl
4056
( \acc (colIdx, colVal) ->
4157
acc
42-
& cellValueAt (1, colIdx) ?~ CellText colVal
58+
& cellValueAt (1, colIdx)
59+
?~ CellText colVal
4360
)
4461
sheet
4562
$ zip [1 ..] rowVal
@@ -80,18 +97,20 @@ addCol imgs sheet rowIdx colIdx field =
8097
then
8198
sheet
8299
& cellValueAt (rowIdx, colIdx)
83-
?~ CellText txt
100+
?~ CellText txt
84101
else case Map.lookup txt imgs of
85102
--
86103
-- TODO : handle img link
87104
--
88105
Nothing ->
89106
sheet
90107
& cellValueAt (rowIdx, colIdx)
91-
?~ CellText txt
108+
?~ CellText txt
92109
Just img ->
93110
sheet
94-
& #wsDrawing . _Just %~ \case
111+
& #wsDrawing
112+
. _Just
113+
%~ \case
95114
Drawing xs ->
96115
Drawing $ newImg rowIdx colIdx (length xs) img : xs
97116
where

0 commit comments

Comments
 (0)