From 3dccfcad6844796338950e4d1ad43d23d07ebd94 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 1 Jul 2011 00:32:09 +0000 Subject: [PATCH] web: show account+subs by default --- hledger-lib/Hledger/Data/Matching.hs | 28 ++++++++----------- .../accountregisterreportitem.hamlet | 2 +- .../web/templates/balancereportitem.hamlet | 4 +-- .../.hledger/web/templates/searchform.hamlet | 2 +- hledger-web/Handlers.hs | 13 +++------ 5 files changed, 20 insertions(+), 29 deletions(-) diff --git a/hledger-lib/Hledger/Data/Matching.hs b/hledger-lib/Hledger/Data/Matching.hs index a0b91e6a0..c7325b322 100644 --- a/hledger-lib/Hledger/Data/Matching.hs +++ b/hledger-lib/Hledger/Data/Matching.hs @@ -54,9 +54,8 @@ data Matcher = MatchAny -- ^ always match -- | A query option changes a query's/report's behaviour and output in some way. -- XXX could use regular cli Opts ? -data QueryOpt = QueryOptInAcct AccountName -- ^ show an account register focussed on this account - | QueryOptInAcctSubs AccountName -- ^ as above but include sub-accounts in the account register - | QueryOptInAcctSubsOnly AccountName -- ^ as above plus narrow the accounts sidebar to show just these accounts +data QueryOpt = QueryOptInAcctOnly AccountName -- ^ show an account register focussed on this account + | QueryOptInAcct AccountName -- ^ as above but include sub-accounts in the account register -- | QueryOptCostBasis -- ^ show amounts converted to cost where possible -- | QueryOptEffectiveDate -- ^ show effective dates instead of actual dates deriving (Show, Eq) @@ -65,23 +64,21 @@ data QueryOpt = QueryOptInAcct AccountName -- ^ show an account register focuss -- Just looks at the first query option. inAccount :: [QueryOpt] -> Maybe AccountName inAccount [] = Nothing +inAccount (QueryOptInAcctOnly a:_) = Just a inAccount (QueryOptInAcct a:_) = Just a -inAccount (QueryOptInAcctSubs a:_) = Just a -inAccount (QueryOptInAcctSubsOnly a:_) = Just a -- | A matcher for the account(s) we are currently focussed on, if any. -- Just looks at the first query option. inAccountMatcher :: [QueryOpt] -> Maybe Matcher inAccountMatcher [] = Nothing -inAccountMatcher (QueryOptInAcct a:_) = Just $ MatchAcct True $ accountNameToAccountOnlyRegex a -inAccountMatcher (QueryOptInAcctSubs a:_) = Just $ MatchAcct True $ accountNameToAccountRegex a -inAccountMatcher (QueryOptInAcctSubsOnly a:_) = Just $ MatchAcct True $ accountNameToAccountRegex a +inAccountMatcher (QueryOptInAcctOnly a:_) = Just $ MatchAcct True $ accountNameToAccountOnlyRegex a +inAccountMatcher (QueryOptInAcct a:_) = Just $ MatchAcct True $ accountNameToAccountRegex a --- | A matcher restricting the account(s) to be shown in the sidebar, if any. --- Just looks at the first query option. -showAccountMatcher :: [QueryOpt] -> Maybe Matcher -showAccountMatcher (QueryOptInAcctSubsOnly a:_) = Just $ MatchAcct True $ accountNameToAccountRegex a -showAccountMatcher _ = Nothing +-- -- | A matcher restricting the account(s) to be shown in the sidebar, if any. +-- -- Just looks at the first query option. +-- showAccountMatcher :: [QueryOpt] -> Maybe Matcher +-- showAccountMatcher (QueryOptInAcctSubsOnly a:_) = Just $ MatchAcct True $ accountNameToAccountRegex a +-- showAccountMatcher _ = Nothing -- | Convert a query expression containing zero or more space-separated -- terms to a matcher and zero or more query options. A query term is either: @@ -109,15 +106,14 @@ parseQuery d s = (m,qopts) -- keep synced with patterns below, excluding "not" prefixes = map (++":") [ - "inacct","inaccts","inacctsonly", + "inacct","inacctonly", "desc","acct","date","edate","status","real","empty","depth" ] defaultprefix = "acct" -- | Parse a single query term as either a matcher or a query option. parseMatcher :: Day -> String -> Either Matcher QueryOpt -parseMatcher _ ('i':'n':'a':'c':'c':'t':'s':'o':'n':'l':'y':':':s) = Right $ QueryOptInAcctSubsOnly s -parseMatcher _ ('i':'n':'a':'c':'c':'t':'s':':':s) = Right $ QueryOptInAcctSubs s +parseMatcher _ ('i':'n':'a':'c':'c':'t':'o':'n':'l':'y':':':s) = Right $ QueryOptInAcctOnly s parseMatcher _ ('i':'n':'a':'c':'c':'t':':':s) = Right $ QueryOptInAcct s parseMatcher d ('n':'o':'t':':':s) = case parseMatcher d $ quoteIfSpaced s of Left m -> Left $ negateMatcher m diff --git a/hledger-web/.hledger/web/templates/accountregisterreportitem.hamlet b/hledger-web/.hledger/web/templates/accountregisterreportitem.hamlet index ffe4f2fe4..48dbacb0c 100644 --- a/hledger-web/.hledger/web/templates/accountregisterreportitem.hamlet +++ b/hledger-web/.hledger/web/templates/accountregisterreportitem.hamlet @@ -19,6 +19,6 @@ $if True  #{elideRight 40 $ paccount p} +  #{elideRight 40 $ paccount p} #{mixedAmountAsHtml $ pamount p} diff --git a/hledger-web/.hledger/web/templates/balancereportitem.hamlet b/hledger-web/.hledger/web/templates/balancereportitem.hamlet index 3938e9be0..eaecd05a5 100644 --- a/hledger-web/.hledger/web/templates/balancereportitem.hamlet +++ b/hledger-web/.hledger/web/templates/balancereportitem.hamlet @@ -1,11 +1,11 @@ #{adisplay} + #{adisplay} +subs + only diff --git a/hledger-web/.hledger/web/templates/searchform.hamlet b/hledger-web/.hledger/web/templates/searchform.hamlet index a4ca1ea8c..9543848fd 100644 --- a/hledger-web/.hledger/web/templates/searchform.hamlet +++ b/hledger-web/.hledger/web/templates/searchform.hamlet @@ -19,7 +19,7 @@ Transactions/postings may additionally be filtered by:
diff --git a/hledger-web/Handlers.hs b/hledger-web/Handlers.hs index 5ddc399e1..eea491c54 100644 --- a/hledger-web/Handlers.hs +++ b/hledger-web/Handlers.hs @@ -122,11 +122,8 @@ getAccountsJsonR = do accountQuery :: AccountName -> String accountQuery a = "inacct:" ++ quoteIfSpaced a -- (accountNameToAccountRegex a) -accountsQuery :: AccountName -> String -accountsQuery a = "inaccts:" ++ quoteIfSpaced a -- (accountNameToAccountRegex a) - -accountsOnlyQuery :: AccountName -> String -accountsOnlyQuery a = "inacctsonly:" ++ quoteIfSpaced a -- (accountNameToAccountRegex a) +accountOnlyQuery :: AccountName -> String +accountOnlyQuery a = "inacctonly:" ++ quoteIfSpaced a -- (accountNameToAccountRegex a) -- accountUrl :: AppRoute -> AccountName -> (AppRoute,[(String,ByteString)]) accountUrl r a = (r, [("q",pack $ accountQuery a)]) @@ -137,9 +134,8 @@ balanceReportAsHtml _ vd@VD{here=here,m=m,q=q,qopts=qopts,j=j} (items',total) = where l = journalToLedger nullfilterspec j inacctmatcher = inAccountMatcher qopts - showacctmatcher = showAccountMatcher qopts allaccts = isNothing inacctmatcher - items = maybe items' (\m -> filter (matchesAccount m . \(a,_,_,_)->a) items') showacctmatcher + items = items' -- maybe items' (\m -> filter (matchesAccount m . \(a,_,_,_)->a) items') showacctmatcher itemAsHtml :: ViewData -> BalanceReportItem -> Hamlet AppRoute itemAsHtml VD{here=here,q=q} (acct, adisplay, aindent, abal) = $(Settings.hamletFile "balancereportitem") where @@ -151,8 +147,7 @@ balanceReportAsHtml _ vd@VD{here=here,m=m,q=q,qopts=qopts,j=j} (items',total) = Nothing -> "" :: String indent = preEscapedString $ concat $ replicate (2 * aindent) " " acctquery = (RegisterR, [("q", pack $ accountQuery acct)]) - acctsquery = (RegisterR, [("q", pack $ accountsQuery acct)]) - acctsonlyquery = (RegisterR, [("q", pack $ accountsOnlyQuery acct)]) + acctonlyquery = (RegisterR, [("q", pack $ accountOnlyQuery acct)]) -- | Render a journal report as HTML. journalReportAsHtml :: [Opt] -> ViewData -> JournalReport -> Hamlet AppRoute