allow-filtering-on-accounts-for-web-queries

This commit is contained in:
Trygve Laugstøl 2011-05-31 14:41:55 +00:00
parent 7c6c90f205
commit 635b6c60e7

View File

@ -106,8 +106,10 @@ postRegisterOnlyR = handlePost
-- specifies json, returns the chart of accounts as json.
getAccountsOnlyR :: Handler RepHtmlJson
getAccountsOnlyR = do
vd@VD{opts=opts,fspec=fspec,j=j} <- getViewData
let json = jsonMap [("accounts", toJSON $ journalAccountNames j)]
vd@VD{opts=opts,fspec=fspec,j=j,a=a} <- getViewData
let accountNames = journalAccountNames j :: [AccountName]
accountNames' = filter (matchpats [a]) $ accountNames
json = jsonMap [("accounts", toJSON $ accountNames')]
html = do
setTitle "hledger-web accounts"
addHamlet $ balanceReportAsHtml opts vd $ balanceReport opts fspec j
@ -116,8 +118,10 @@ getAccountsOnlyR = do
-- | Return the chart of accounts as json, without needing a special Accept header.
getAccountsJsonR :: Handler RepJson
getAccountsJsonR = do
VD{j=j} <- getViewData
jsonToRepJson $ jsonMap [("accounts", toJSON $ journalAccountNames j)]
VD{a=a,j=j} <- getViewData
let accountNames = journalAccountNames j :: [AccountName]
accountNames' = filter (matchpats [a]) $ accountNames
jsonToRepJson $ jsonMap [("accounts", toJSON $ accountNames')]
-- helpers