;web: maintain query when choosing a different 'inacct' account on the sidebar

This commit is contained in:
Henning Thielemann 2020-05-25 10:49:34 +02:00 committed by Simon Michael
parent 54300328cd
commit ec27eb6b17
4 changed files with 17 additions and 5 deletions

View File

@ -49,6 +49,7 @@ module Hledger.Query (
matchesCommodity,
matchesPriceDirective,
words'',
prefixes,
-- * tests
tests_Query
)

View File

@ -122,7 +122,7 @@ instance Yesod App where
-- flip the default for items with zero amounts, show them by default
ropts' = ropts { empty_ = not (empty_ ropts) }
accounts =
balanceReportAsHtml (JournalR, RegisterR) here hideEmptyAccts j qopts $
balanceReportAsHtml (JournalR, RegisterR) here hideEmptyAccts j q qopts $
balanceReport ropts' m j
topShowmd = if showSidebar then "col-md-4" else "col-any-0" :: Text

View File

@ -37,6 +37,7 @@ import Yesod
import Hledger
import Hledger.Cli.Utils (writeFileWithBackupIfChanged)
import Hledger.Web.Settings (manualurl)
import qualified Hledger.Query as Query
#if MIN_VERSION_yesod(1,6,0)
journalFile404 :: FilePath -> Journal -> HandlerFor m (FilePath, Text)
@ -82,8 +83,8 @@ helplink topic label _ = H.a ! A.href u ! A.target "hledgerhelp" $ toHtml label
where u = textValue $ manualurl <> if T.null topic then "" else T.cons '#' topic
-- | Render a "BalanceReport" as html.
balanceReportAsHtml :: Eq r => (r, r) -> r -> Bool -> Journal -> [QueryOpt] -> BalanceReport -> HtmlUrl r
balanceReportAsHtml (journalR, registerR) here hideEmpty j qopts (items, total) =
balanceReportAsHtml :: Eq r => (r, r) -> r -> Bool -> Journal -> Text -> [QueryOpt] -> BalanceReport -> HtmlUrl r
balanceReportAsHtml (journalR, registerR) here hideEmpty j q qopts (items, total) =
$(hamletFile "templates/balance-report.hamlet")
where
l = ledgerFromJournal Any j
@ -113,3 +114,13 @@ transactionFragment j =
in \t ->
printf "transaction-%d-%d"
(hm HashMap.! sourceFilePath (tsourcepos t)) (tindex t)
removeInacct :: Text -> [Text]
removeInacct =
map quoteIfSpaced .
filter (\term ->
not $ T.isPrefixOf "inacct:" term || T.isPrefixOf "inacctonly:" term) .
Query.words'' Query.prefixes
replaceInacct :: Text -> Text -> Text
replaceInacct q acct = T.unwords $ acct : removeInacct q

View File

@ -11,11 +11,11 @@ $forall (acct, adisplay, aindent, abal) <- items
<td .acct :isZeroMixedAmount abal:.empty>
<div .ff-wrapper>
\#{indent aindent}
<a.acct-name href="@?{(registerR, [("q", accountQuery acct)])}"
<a.acct-name href="@?{(registerR, [("q", replaceInacct q $ accountQuery acct)])}"
title="Show transactions affecting this account and subaccounts">
#{adisplay}
$if hasSubAccounts acct
<a href="@?{(registerR, [("q", accountOnlyQuery acct)])}" .only.hidden-sm.hidden-xs
<a href="@?{(registerR, [("q", replaceInacct q $ accountOnlyQuery acct)])}" .only.hidden-sm.hidden-xs
title="Show transactions affecting this account but not subaccounts">only
<td>
^{mixedAmountAsHtml abal}