diff --git a/hledger-web/Hledger/Web/Handler/JournalR.hs b/hledger-web/Hledger/Web/Handler/JournalR.hs index 54840d423..8ae91c26f 100644 --- a/hledger-web/Hledger/Web/Handler/JournalR.hs +++ b/hledger-web/Hledger/Web/Handler/JournalR.hs @@ -13,7 +13,7 @@ import Hledger.Web.Import import Hledger.Web.WebOptions import Hledger.Web.Widget.AddForm (addModal) import Hledger.Web.Widget.Common - (accountQuery, mixedAmountAsHtml, transactionFrag) + (accountQuery, mixedAmountAsHtml, transactionFragment) -- | The formatted journal view, with sidebar. getJournalR :: Handler Html @@ -27,6 +27,7 @@ getJournalR = do title' = title <> if m /= Any then ", filtered" else "" acctlink a = (RegisterR, [("q", accountQuery a)]) (_, items) = transactionsReport (reportopts_ $ cliopts_ opts) j m + transactionFrag = transactionFragment j defaultLayout $ do setTitle "journal - hledger-web" diff --git a/hledger-web/Hledger/Web/Handler/RegisterR.hs b/hledger-web/Hledger/Web/Handler/RegisterR.hs index 16cbc0a02..18394f1fe 100644 --- a/hledger-web/Hledger/Web/Handler/RegisterR.hs +++ b/hledger-web/Hledger/Web/Handler/RegisterR.hs @@ -18,7 +18,7 @@ import Hledger.Web.Import import Hledger.Web.WebOptions import Hledger.Web.Widget.AddForm (addModal) import Hledger.Web.Widget.Common - (accountQuery, mixedAmountAsHtml, transactionFrag) + (accountQuery, mixedAmountAsHtml, transactionFragment) -- | The main journal/account register view, with accounts sidebar. getRegisterR :: Handler Html @@ -45,6 +45,7 @@ getRegisterR = do tail $ (", "<$xs) ++ [""] r@(balancelabel,items) = accountTransactionsReport ropts j m acctQuery balancelabel' = if isJust (inAccount qopts) then balancelabel else "Total" + transactionFrag = transactionFragment j defaultLayout $ do setTitle "register - hledger-web" $(widgetFile "register") diff --git a/hledger-web/Hledger/Web/Widget/Common.hs b/hledger-web/Hledger/Web/Widget/Common.hs index fd4f99c2e..73902c6c9 100644 --- a/hledger-web/Hledger/Web/Widget/Common.hs +++ b/hledger-web/Hledger/Web/Widget/Common.hs @@ -14,7 +14,7 @@ module Hledger.Web.Widget.Common , fromFormSuccess , writeJournalTextIfValidAndChanged , journalFile404 - , transactionFrag + , transactionFragment ) where import Data.Default (def) @@ -24,6 +24,7 @@ import Data.Semigroup ((<>)) #endif import Data.Text (Text) import qualified Data.Text as T +import qualified Data.HashMap.Strict as HashMap import System.FilePath (takeFileName) import Text.Blaze ((!), textValue) import qualified Text.Blaze.Html5 as H @@ -106,6 +107,9 @@ mixedAmountAsHtml b _ = Just True -> "negative amount" _ -> "positive amount" -transactionFrag :: Transaction -> String -transactionFrag t = - printf "transaction-%s-%d" (sourceFilePath $ tsourcepos t) (tindex t) +transactionFragment :: Journal -> Transaction -> String +transactionFragment j = + let hm = HashMap.fromList $ zip (map fst $ jfiles j) [(1::Integer) ..] + in \t -> + printf "transaction-%d-%d" + (hm HashMap.! sourceFilePath (tsourcepos t)) (tindex t) diff --git a/hledger-web/hledger-web.cabal b/hledger-web/hledger-web.cabal index 163a9a4c5..36a5dd173 100644 --- a/hledger-web/hledger-web.cabal +++ b/hledger-web/hledger-web.cabal @@ -185,6 +185,7 @@ library , time >=1.5 , transformers , unix-compat + , unordered-containers , utf8-string , wai , wai-cors diff --git a/hledger-web/package.yaml b/hledger-web/package.yaml index 0cb331da6..2c80db9ed 100644 --- a/hledger-web/package.yaml +++ b/hledger-web/package.yaml @@ -130,6 +130,7 @@ library: - time >=1.5 - transformers - unix-compat + - unordered-containers - utf8-string - wai - wai-extra