From 48f208be8f4becb8012436f9ed2a974ab2c7868b Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 11 Jun 2011 18:42:38 +0000 Subject: [PATCH] web: clicking an account now gives the traditional single-account register report --- hledger-web/.hledger/web/static/style.css | 4 ++-- .../.hledger/web/templates/filterform.hamlet | 12 +++++----- hledger-web/Handlers.hs | 22 +++++++++++++------ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/hledger-web/.hledger/web/static/style.css b/hledger-web/.hledger/web/static/style.css index bdb2b9ac8..878fc042f 100644 --- a/hledger-web/.hledger/web/static/style.css +++ b/hledger-web/.hledger/web/static/style.css @@ -22,8 +22,8 @@ body { backgroun #editform textarea { background-color:#eee; } .negative { color:#800; } -.balancereport .inacct { /*background-color:#f0f0f0;*/ } -.notinacct, .notinacct :link, .notinacct :visited, .notinacct .negative { color:#aaa; } +.balancereport .inacct { background-color:#eee; font-weight:bold; } +.notinacct, .notinacct :link, .notinacct :visited, .notinacct .negative { /*color:#aaa;*/ } /*------------------------------------------------------------------------------------------*/ /* 2. font families & sizes */ diff --git a/hledger-web/.hledger/web/templates/filterform.hamlet b/hledger-web/.hledger/web/templates/filterform.hamlet index 7f678e686..8e0a35d80 100644 --- a/hledger-web/.hledger/web/templates/filterform.hamlet +++ b/hledger-web/.hledger/web/templates/filterform.hamlet @@ -7,15 +7,15 @@ \ # show all + clear search - not: to negate, multiple patterns are AND'ed, patterns are regular expressions -
- leave blank to see general journal (all postings) + leave blank to see general journal (all postings)
+ acct:REGEXP to see postings to matched accounts, desc:REGEXP to search by description
+ inacct:FULLACCTNAME or click an account to see transactions and accurate balance in a single account
+ not: to negate, single or double quotes to include spaces, multiple patterns are AND'ed diff --git a/hledger-web/Handlers.hs b/hledger-web/Handlers.hs index d9d1e81f8..cd6f9ef10 100644 --- a/hledger-web/Handlers.hs +++ b/hledger-web/Handlers.hs @@ -15,7 +15,7 @@ import Data.List import Data.Maybe import Data.Text(Text,pack,unpack) import Data.Time.Calendar -import Safe +-- import Safe import System.FilePath (takeFileName, ()) import System.IO.Storage (putValue, getValue) import Text.Hamlet hiding (hamletFile) @@ -63,7 +63,7 @@ getRegisterR :: Handler RepHtml getRegisterR = do vd@VD{opts=opts,m=m,j=j} <- getViewData let sidecontent = balanceReportAsHtml opts vd{q=""} $ balanceReport opts nullfilterspec j - maincontent = registerReportAsHtml opts vd $ registerReport opts nullfilterspec $ filterJournalPostings2 m j + maincontent = registerReportAsHtml opts vd $ accountOrJournalRegisterReport opts m j editform' = editform vd defaultLayout $ do setTitle "hledger-web register" @@ -89,11 +89,17 @@ getRegisterOnlyR = do vd@VD{opts=opts,m=m,j=j} <- getViewData defaultLayout $ do setTitle "hledger-web register only" - addHamlet $ registerReportAsHtml opts vd $ registerReport opts nullfilterspec $ filterJournalPostings2 m j + addHamlet $ registerReportAsHtml opts vd $ accountOrJournalRegisterReport opts m j postRegisterOnlyR :: Handler RepPlain postRegisterOnlyR = handlePost +-- temporary helper - use the new account register report when in:ACCT is specified. +accountOrJournalRegisterReport :: [Opt] -> Matcher -> Journal -> RegisterReport +accountOrJournalRegisterReport opts m j = + case matcherInAccount m of Just a -> accountRegisterReport opts j m a + Nothing -> registerReport opts nullfilterspec $ filterJournalPostings2 m j + -- | A simple accounts view, like hledger balance. If the Accept header -- specifies json, returns the chart of accounts as json. getAccountsR :: Handler RepHtmlJson @@ -116,19 +122,21 @@ getAccountsJsonR = do -- helpers accountUrl :: String -> String -accountUrl a = "in:" ++ quoteIfSpaced (accountNameToAccountRegex a) +accountUrl a = "inacct:" ++ quoteIfSpaced a -- (accountNameToAccountRegex a) -- | Render a balance report as HTML. balanceReportAsHtml :: [Opt] -> ViewData -> BalanceReport -> Hamlet AppRoute balanceReportAsHtml _ vd@VD{here=here,q=q,m=m,j=j} (items,total) = $(Settings.hamletFile "balancereport") where filtering = not $ null q - inacct = headMay $ filter (m `matchesInAccount`) $ journalAccountNames j + inacct = matcherInAccount m -- headMay $ filter (m `matchesInAccount`) $ journalAccountNames j itemAsHtml :: ViewData -> BalanceReportItem -> Hamlet AppRoute itemAsHtml VD{here=here,q=q} (acct, adisplay, aindent, abal) = $(Settings.hamletFile "balancereportitem") where depthclass = "depth"++show aindent - inclass = if acct == inacct then "inacct" else "notinacct" :: String + inclass | Just acct == inacct = "inacct" + | isJust inacct = "notinacct" + | otherwise = "" :: String indent = preEscapedString $ concat $ replicate (2 * aindent) " " accturl = (here, [("q", pack $ accountUrl acct)]) @@ -407,7 +415,7 @@ getViewData = do Just here' <- getCurrentRoute today <- liftIO getCurrentDay q <- getParameter "q" - let m = strace $ parseMatcher today q + let m = parseMatcher today q return mkvd{opts=opts, q=q, m=m, j=j, today=today, here=here', msg=msg} where -- | Update our copy of the journal if the file changed. If there is an