lib: Write.Ods.printFods: change type of number of fixed rows/columns from (Maybe Int) to Int

0 is a perfect value for no fixed row or column.
This commit is contained in:
Henning Thielemann 2024-10-21 13:23:13 +02:00 committed by Simon Michael
parent b2aad52168
commit 3714ac0593
6 changed files with 16 additions and 13 deletions

View File

@ -13,6 +13,7 @@ module Hledger.Write.Ods (
) where
import Prelude hiding (Applicative(..))
import Control.Monad (guard)
import Control.Applicative (Applicative(..))
import qualified Data.Text.Lazy as TL
@ -38,7 +39,7 @@ import Hledger.Data.Types (acommodity, aquantity, astyle, asprecision)
printFods ::
IO.TextEncoding ->
Map Text ((Maybe Int, Maybe Int), [[Cell Spr.NumLines Text]]) -> TL.Text
Map Text ((Int, Int), [[Cell Spr.NumLines Text]]) -> TL.Text
printFods encoding tables =
let fileOpen customStyles =
map (map (\c -> case c of '\'' -> '"'; _ -> c)) $
@ -87,14 +88,14 @@ printFods encoding tables =
" <config:config-item-map-entry>" :
" <config:config-item-map-named config:name='Tables'>" :
(fold $
flip Map.mapWithKey tableNames $ \tableName (mTopRow,mLeftColumn) ->
flip Map.mapWithKey tableNames $ \tableName (topRow,leftColumn) ->
printf " <config:config-item-map-entry config:name='%s'>" tableName :
(flip foldMap mLeftColumn $ \leftColumn ->
((guard (leftColumn>0) >>) $
" <config:config-item config:name='HorizontalSplitMode' config:type='short'>2</config:config-item>" :
printf " <config:config-item config:name='HorizontalSplitPosition' config:type='int'>%d</config:config-item>" leftColumn :
printf " <config:config-item config:name='PositionRight' config:type='int'>%d</config:config-item>" leftColumn :
[]) ++
(flip foldMap mTopRow $ \topRow ->
((guard (topRow>0) >>) $
" <config:config-item config:name='VerticalSplitMode' config:type='short'>2</config:config-item>" :
printf " <config:config-item config:name='VerticalSplitPosition' config:type='int'>%d</config:config-item>" topRow :
printf " <config:config-item config:name='PositionBottom' config:type='int'>%d</config:config-item>" topRow :

View File

@ -121,7 +121,7 @@ aregister opts@CliOpts{rawopts_=rawopts,reportspec_=rspec} j = do
| fmt=="tsv" = printTSV . accountTransactionsReportAsCsv wd (_rsQuery rspec') thisacctq
| fmt=="fods" =
printFods IO.localeEncoding . Map.singleton "Aregister" .
(,) (Just 1, Nothing) .
(,) (1,0) .
accountTransactionsReportAsSpreadsheet oneLineNoCostFmt wd (_rsQuery rspec') thisacctq
| fmt=="json" = toJsonText
| otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL:

View File

@ -394,7 +394,7 @@ balance opts@CliOpts{reportspec_=rspec} j = case balancecalc_ ropts of
"html" -> (<>"\n") . L.renderText .
printHtml . map (map (fmap L.toHtml)) . budgetReportAsSpreadsheet ropts
"fods" -> printFods IO.localeEncoding .
Map.singleton "Budget Report" . (,) (Just 1, Nothing) . budgetReportAsSpreadsheet ropts
Map.singleton "Budget Report" . (,) (1,0) . budgetReportAsSpreadsheet ropts
_ -> error' $ unsupportedOutputFormatError fmt
writeOutputLazyText opts $ render budgetreport
@ -420,7 +420,7 @@ balance opts@CliOpts{reportspec_=rspec} j = case balancecalc_ ropts of
"html" -> (<>"\n") . L.renderText .
printHtml . map (map (fmap L.toHtml)) . balanceReportAsSpreadsheet ropts
"json" -> (<>"\n") . toJsonText
"fods" -> printFods IO.localeEncoding . Map.singleton "Balance Report" . (,) (Just 1, Nothing) . balanceReportAsSpreadsheet ropts
"fods" -> printFods IO.localeEncoding . Map.singleton "Balance Report" . (,) (1,0) . balanceReportAsSpreadsheet ropts
_ -> error' $ unsupportedOutputFormatError fmt -- PARTIAL:
writeOutputLazyText opts $ render report
where
@ -718,12 +718,12 @@ multiBalanceReportAsHtml ropts mbr =
-- Returns the heading row, 0 or more body rows, and the totals row if enabled.
multiBalanceReportAsSpreadsheet ::
ReportOpts -> MultiBalanceReport ->
((Maybe Int, Maybe Int), [[Ods.Cell Ods.NumLines Text]])
((Int, Int), [[Ods.Cell Ods.NumLines Text]])
multiBalanceReportAsSpreadsheet ropts mbr =
let (header,body,total) =
multiBalanceReportAsSpreadsheetParts oneLineNoCostFmt ropts mbr
in (if transpose_ ropts then swap *** Ods.transpose else id) $
((Just 1, case layout_ ropts of LayoutWide _ -> Just 1; _ -> Nothing),
((1, case layout_ ropts of LayoutWide _ -> 1; _ -> 0),
header : body ++ total)

View File

@ -146,7 +146,7 @@ printEntries opts@CliOpts{rawopts_=rawopts, reportspec_=rspec} j =
styleAmounts styles
| fmt=="fods" =
printFods IO.localeEncoding . Map.singleton "Print" .
(,) (Just 1, Nothing) .
(,) (1,0) .
entriesReportAsSpreadsheet oneLineNoCostFmt baseUrl query .
styleAmounts styles
| otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL:

View File

@ -108,7 +108,7 @@ register opts@CliOpts{rawopts_=rawopts, reportspec_=rspec} j
postingsReportAsSpreadsheet oneLineNoCostFmt baseUrl query
| fmt=="fods" =
printFods IO.localeEncoding . Map.singleton "Register" .
(,) (Just 1, Nothing) .
(,) (1,0) .
postingsReportAsSpreadsheet oneLineNoCostFmt baseUrl query
| otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL:
where fmt = outputFormatFromOpts opts
@ -119,6 +119,8 @@ postingsReportAsCsv :: PostingsReport -> CSV
postingsReportAsCsv =
Spr.rawTableContent . postingsReportAsSpreadsheet machineFmt Nothing []
-- ToDo: --layout=bare etc.
-- ToDo: Text output does not show headers, but Spreadsheet does
postingsReportAsSpreadsheet ::
AmountFormat -> Maybe Text -> [Text] ->
PostingsReport -> [[Spr.Cell Spr.NumLines Text]]

View File

@ -343,7 +343,7 @@ compoundBalanceReportAsHtml ropts cbr =
compoundBalanceReportAsSpreadsheet ::
AmountFormat -> T.Text -> Maybe T.Text ->
ReportOpts -> CompoundPeriodicReport DisplayName MixedAmount ->
(T.Text, ((Maybe Int, Maybe Int), NonEmpty [Spr.Cell Spr.NumLines T.Text]))
(T.Text, ((Int, Int), NonEmpty [Spr.Cell Spr.NumLines T.Text]))
compoundBalanceReportAsSpreadsheet fmt accountLabel maybeBlank ropts cbr =
let
CompoundPeriodicReport title colspans subreports totalrow = cbr
@ -397,5 +397,5 @@ compoundBalanceReportAsSpreadsheet fmt accountLabel maybeBlank ropts cbr =
& addTotalBorders -- marking the first row for special styling
in (title,
((Just 1, Just 1),
((1,1),
headerrow :| concatMap subreportrows subreports ++ totalrows))