From 067c5e4db63fdc9fb301f94e1558134c5c41291b Mon Sep 17 00:00:00 2001 From: Henning Thielemann Date: Sat, 19 Oct 2024 22:12:43 +0200 Subject: [PATCH] cli: Commands.Aregister.htmlRow: replace by call to generic accountTransactionsReportItemAsRecord --- hledger/Hledger/Cli/Commands/Aregister.hs | 43 +++++++++++------------ 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Aregister.hs b/hledger/Hledger/Cli/Commands/Aregister.hs index 7c5af567d..4a4c382bb 100644 --- a/hledger/Hledger/Cli/Commands/Aregister.hs +++ b/hledger/Hledger/Cli/Commands/Aregister.hs @@ -23,17 +23,21 @@ import Data.Default (def) import Data.List (find) import Data.Maybe (fromMaybe) import Data.Text (Text) +import Data.Foldable (for_) import qualified Data.Map as Map import qualified Data.Text as T import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy.Builder as TB -import Lucid as L hiding (value_) +import Control.Monad (guard) +import Lucid (toHtml) +import qualified Lucid as L import System.Console.CmdArgs.Explicit (flagNone, flagReq) import Hledger import Hledger.Write.Csv (CSV, printCSV, printTSV) import Hledger.Write.Ods (printFods) import qualified Hledger.Write.Spreadsheet as Spr +import qualified Hledger.Write.Html.Lucid as Html import Hledger.Cli.CliOptions import Hledger.Cli.Utils import Text.Tabular.AsciiWide hiding (render) @@ -137,20 +141,19 @@ accountTransactionsReportAsSpreadsheet fmt wd reportq thisacctq is = Spr.addHeaderBorders (map Spr.headerCell ["txnidx","date","code","description","otheraccounts","change","balance"]) - : map (accountTransactionsReportItemAsRecord fmt wd reportq thisacctq) is + : map (accountTransactionsReportItemAsRecord fmt True wd reportq thisacctq) is accountTransactionsReportItemAsRecord :: - (Spr.Lines border) => - AmountFormat -> + AmountFormat -> Bool -> WhichDate -> Query -> Query -> AccountTransactionsReportItem -> - [Spr.Cell border Text] + [Spr.Cell Spr.NumLines Text] accountTransactionsReportItemAsRecord - fmt wd reportq thisacctq + fmt internals wd reportq thisacctq (t@Transaction{tindex,tcode,tdescription}, _, _issplit, otheracctsstr, change, balance) - = [Spr.integerCell tindex, - date, - cell tcode, - cell tdescription, + = (guard internals >> [Spr.integerCell tindex]) ++ + date : + (guard internals >> [cell tcode]) ++ + [cell tdescription, cell otheracctsstr, amountCell change, amountCell balance] @@ -167,7 +170,7 @@ accountTransactionsReportItemAsRecord accountTransactionsReportAsHTML :: CliOpts -> Query -> Query -> AccountTransactionsReport -> TL.Text accountTransactionsReportAsHTML copts reportq thisacctq items = L.renderText $ do - L.link_ [L.rel_ "stylesheet", href_ "hledger.css"] + L.link_ [L.rel_ "stylesheet", L.href_ "hledger.css"] L.table_ $ do L.thead_ $ L.tr_ $ do L.th_ "date" @@ -175,18 +178,12 @@ accountTransactionsReportAsHTML copts reportq thisacctq items = L.th_ "otheraccounts" L.th_ "change" L.th_ "balance" - L.tbody_ $ mconcat $ map (htmlRow copts reportq thisacctq) items - --- | Render one account register report line item as a HTML table row snippet. -htmlRow :: CliOpts -> Query -> Query -> AccountTransactionsReportItem -> L.Html () -htmlRow CliOpts{reportspec_=ReportSpec{_rsReportOpts=ropts}} reportq thisacctq - (t@Transaction{tdescription}, _, _issplit, otheracctsstr, amt, bal) = - L.tr_ (do (L.td_ . toHtml . show . transactionRegisterDate (whichDate ropts) reportq thisacctq) t - (L.td_ . toHtml) tdescription - (L.td_ . toHtml) otheracctsstr - -- piggy back on the oneLineNoCostFmt display style for now. - (L.td_ . toHtml . wbUnpack . showMixedAmountB oneLineNoCostFmt) amt - (L.td_ . toHtml . wbUnpack . showMixedAmountB oneLineNoCostFmt) bal) + L.tbody_ $ for_ items $ + Html.formatRow . map (fmap toHtml) . + accountTransactionsReportItemAsRecord + oneLineNoCostFmt False + (whichDate $ _rsReportOpts $ reportspec_ copts) + reportq thisacctq -- | Render a register report as plain text suitable for console output. accountTransactionsReportAsText :: CliOpts -> Query -> Query -> AccountTransactionsReport -> TL.Text