Skip to content

Commit dd72828

Browse files
committed
excel layout wip
1 parent 9d664dc commit dd72828

File tree

4 files changed

+43
-32
lines changed

4 files changed

+43
-32
lines changed

ghcjs/delivery-calculator/delivery-calculator.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ common pkg
1616
hs-source-dirs: src
1717
js-sources: static/app.js
1818
other-modules:
19+
App.I18n
1920
App.Jsm
2021
App.Types
2122
App.Widgets.Asset
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module App.I18n (xlsxHeaderRu) where
2+
3+
import Functora.Miso.Prelude
4+
5+
xlsxHeaderRu :: [Unicode]
6+
xlsxHeaderRu =
7+
["",
8+
"Ccылка/ 链接",
9+
"Картинка/ 图片",
10+
"Модель/ 型号",
11+
"Количество/ 数量",
12+
"Цена за 1 шт./ 单价",
13+
"Доставка по Китаю/ 运费",
14+
"Общая сумма/ 总价",
15+
"",
16+
"Примечание/ 注解"
17+
]

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,11 @@ stTeleUri st = do
464464
^. #modelState
465465
. #stMerchantTele
466466
. #fieldOutput
467-
link <-
468-
stUri st
469467
key <-
470468
URI.mkQueryKey "text"
471469
val <-
472470
URI.mkQueryValue
473-
$ "Hello, I have a question about the delivery of the following items: "
474-
<> URI.render link
471+
$ "Hello, I have a question about delivery. I will send the Excel file in the next message."
475472
pure
476473
$ base
477474
{ URI.uriPath = Just (False, [user]),

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

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module App.Xlsx
55
)
66
where
77

8+
import qualified App.I18n as I18n
89
import App.Types
910
import Codec.Xlsx
1011
import qualified Data.ByteString.Lazy as BL
@@ -28,7 +29,7 @@ newXlsx st imgs = xlsx
2829
.~ newRowProps rows
2930
& #wsColumnsProperties
3031
.~ newColProps (fmap snd rows)
31-
& addHeader st
32+
& addHeader
3233
& flip (foldl $ addRow imgs) rows
3334
& addFooter st (RowIndex (length rows) + 2)
3435
rows =
@@ -59,39 +60,25 @@ newColProps rows = nubOrd $ do
5960
else
6061
pure
6162
ColumnsProperties
62-
{ cpMin = colIdx,
63-
cpMax = colIdx,
63+
{ cpMin = mapCol colIdx,
64+
cpMax = mapCol colIdx,
6465
cpWidth = Just 45,
6566
cpStyle = Nothing,
6667
cpHidden = False,
6768
cpCollapsed = False,
6869
cpBestFit = False
6970
}
7071

71-
addHeader :: St Unique -> Worksheet -> Worksheet
72-
addHeader st sheet =
73-
case sortOn length headers of
74-
[] -> sheet
75-
(rowVal : _) ->
76-
foldl
77-
( \acc (colIdx, colVal) ->
78-
acc
79-
& cellValueAt (1, colIdx)
80-
?~ CellText (from @Unicode @Text colVal)
81-
)
82-
sheet
83-
$ zip [1 ..] rowVal
84-
where
85-
headers :: [[Unicode]]
86-
headers =
87-
fmap
88-
( ^..
89-
#assetFieldPairs
90-
. each
91-
. #fieldPairKey
92-
. #fieldOutput
93-
)
94-
$ stAssets st
72+
addHeader :: Worksheet -> Worksheet
73+
addHeader sheet =
74+
foldl
75+
( \acc (colIdx, colVal) ->
76+
acc
77+
& cellValueAt (1, colIdx)
78+
?~ CellText (from @Unicode @Text colVal)
79+
)
80+
sheet
81+
$ zip [1 ..] I18n.xlsxHeaderRu
9582

9683
addFooter :: St Unique -> RowIndex -> Worksheet -> Worksheet
9784
addFooter st rowOffset sheet =
@@ -127,7 +114,7 @@ addRow ::
127114
addRow imgs sheet (rowIdx, rowVal) =
128115
foldl
129116
( \acc (colIdx, colVal) ->
130-
addCol imgs acc rowIdx colIdx colVal
117+
addCol imgs acc rowIdx (mapCol colIdx) colVal
131118
)
132119
sheet
133120
$ zip [1 ..] rowVal
@@ -200,3 +187,12 @@ xlsxFile st =
200187

201188
xlsxMime :: Unicode
202189
xlsxMime = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
190+
191+
mapCol :: (Integral n) => n -> n
192+
mapCol = \case
193+
1 -> 2
194+
2 -> 3
195+
3 -> 6
196+
4 -> 5
197+
5 -> 10
198+
n -> n + 10

0 commit comments

Comments
 (0)