From cf5dda72b1ae50ce8b3aa791118322b561ffdb54 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 14 Jan 2016 09:44:26 -0800 Subject: [PATCH 1/9] site: download: hledger-ui now on stackage (#301) --- site/download.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/site/download.md b/site/download.md index 528f26212..4b73952d4 100644 --- a/site/download.md +++ b/site/download.md @@ -98,9 +98,7 @@ This is a quick way to help the project and your fellow users! 2. `stack setup` (if you need GHC installed. If you're not sure, run the next command and it will tell you.) -3. `stack --resolver nightly-2015-11-04 install hledger [hledger-web]` \ - - *2015/11/3: hledger-ui has [not yet reached stackage](https://github.com/fpco/stackage/issues/938); you must install it from source or with cabal, see below.* +3. `stack --resolver lts-4 install hledger [hledger-ui] [hledger-web]` 4. Ensure `~/.local/bin` or the Windows equivalent is in your `$PATH`, so that you can just type `hledger` to run it. (stack will show the proper directory and will tell you if it is not in $PATH). From 5b7040fecd5faf1d42f1cfa84f9943a40f5ed236 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 12 Jan 2016 13:44:14 -0800 Subject: [PATCH 2/9] ui: allow brick 0.4 --- hledger-ui/hledger-ui.cabal | 2 +- hledger-ui/package.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hledger-ui/hledger-ui.cabal b/hledger-ui/hledger-ui.cabal index 3c6aab7b6..7b5ad03f9 100644 --- a/hledger-ui/hledger-ui.cabal +++ b/hledger-ui/hledger-ui.cabal @@ -60,7 +60,7 @@ executable hledger-ui , hledger-lib >= 0.27 && < 0.28 , base >= 3 && < 5 , base-compat >= 0.8.1 - , brick >= 0.2 && < 0.4 + , brick >= 0.2 && < 0.5 , cmdargs >= 0.8 , containers , data-default diff --git a/hledger-ui/package.yaml b/hledger-ui/package.yaml index e3daa9177..f24be7c54 100644 --- a/hledger-ui/package.yaml +++ b/hledger-ui/package.yaml @@ -69,7 +69,7 @@ executables: - hledger-lib >= 0.27 && < 0.28 - base >= 3 && < 5 - base-compat >= 0.8.1 - - brick >= 0.2 && < 0.4 + - brick >= 0.2 && < 0.5 - cmdargs >= 0.8 - containers - data-default From 142c52e5b992800d2c94e351396d4169c3c24787 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 12 Jan 2016 13:46:47 -0800 Subject: [PATCH 3/9] ui: changelog, bump version to 0.27.3 --- hledger-ui/CHANGES | 4 ++++ hledger-ui/hledger-ui.cabal | 6 +++--- hledger-ui/package.yaml | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hledger-ui/CHANGES b/hledger-ui/CHANGES index 90eae4f14..659ad041f 100644 --- a/hledger-ui/CHANGES +++ b/hledger-ui/CHANGES @@ -1,6 +1,10 @@ User-visible changes in hledger-ui. See also hledger's change log. +0.27.3 (2016/1/12) + +- allow brick 0.4 + 0.27.2 (2016/1/11) - allow brick 0.3.x diff --git a/hledger-ui/hledger-ui.cabal b/hledger-ui/hledger-ui.cabal index 7b5ad03f9..0ece2e898 100644 --- a/hledger-ui/hledger-ui.cabal +++ b/hledger-ui/hledger-ui.cabal @@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: hledger-ui -version: 0.27.2 +version: 0.27.3 stability: beta category: Finance, Console synopsis: Curses-style user interface for the hledger accounting tool @@ -25,7 +25,7 @@ homepage: http://hledger.org bug-reports: http://bugs.hledger.org cabal-version: >= 1.10 build-type: Simple -tested-with: GHC==7.8.4, GHC==7.10.2 +tested-with: GHC==7.8.4, GHC==7.10.3 extra-source-files: CHANGES @@ -54,7 +54,7 @@ executable hledger-ui ghc-options: -Wall -fno-warn-unused-do-bind -fno-warn-name-shadowing -fno-warn-missing-signatures -fno-warn-type-defaults -fno-warn-orphans if flag(threaded) ghc-options: -threaded - cpp-options: -DVERSION="0.27.2" + cpp-options: -DVERSION="0.27.3" build-depends: hledger >= 0.27 && < 0.28 , hledger-lib >= 0.27 && < 0.28 diff --git a/hledger-ui/package.yaml b/hledger-ui/package.yaml index f24be7c54..058970b3a 100644 --- a/hledger-ui/package.yaml +++ b/hledger-ui/package.yaml @@ -9,7 +9,7 @@ # - conditional blocks name : hledger-ui -version : '0.27.2' +version : '0.27.3' stability : beta category : Finance, Console synopsis : Curses-style user interface for the hledger accounting tool @@ -31,7 +31,7 @@ github : simonmichael/hledger homepage : http://hledger.org bug-reports : http://bugs.hledger.org # XXX not supported -tested-with : GHC==7.10.2 +tested-with : GHC==7.10.3 extra-source-files: - CHANGES @@ -54,7 +54,7 @@ ghc-options: -fno-warn-type-defaults -fno-warn-orphans -cpp-options: -DVERSION="0.27.2" +cpp-options: -DVERSION="0.27.3" executables: hledger-ui: From 94f2b37f121e0de054361a460145c2efe9f8eeb8 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 14 Jan 2016 20:48:44 -0800 Subject: [PATCH 4/9] tools: travis: use latest stack --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7a5ea5437..d2731e6d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ +# http://docs.haskellstack.org/en/stable/travis_ci.html + language: haskell branches: @@ -19,7 +21,7 @@ cache: before_install: - mkdir -p ~/.local/bin - export PATH=~/.local/bin:$PATH - - travis_retry curl -L https://github.com/commercialhaskell/stack/releases/download/v0.1.3.1/stack-0.1.3.1-x86_64-linux.gz | gunzip > ~/.local/bin/stack + - travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack' - chmod a+x ~/.local/bin/stack install: From 26ba907a2e8e0ce24e23481c47947591d70978bf Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 17 Jan 2016 08:52:19 -0800 Subject: [PATCH 5/9] tools: make cloc, counts lines of code --- Makefile | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 629177db4..542be015f 100644 --- a/Makefile +++ b/Makefile @@ -1273,13 +1273,12 @@ tagrelease: \ # @darcs changes --from-tag $(FROMTAG) |grep '^\w' |cut -c 31- |sort |uniq # @echo -# showloc: \ -# $(call def-help,showloc,\ -# \ -# ) -# @echo Current lines of code including tests: -# @sloccount `ls $(SOURCEFILES)` | grep haskell: -# @echo +cloc: \ + $(call def-help,cloc, count lines of source code ) + @echo Lines of code including tests: + @cloc --exclude-lang=HTML --exclude-dir=.stack-work,.idea,dist,old,bin,doc,site,.tutorial-data . + @echo +# `ls $(SOURCEFILES)` # sloc: \ # $(call def-help,sloc,\ From 798f4e82d0ef838b9d2d9c09cb4afd3f371b4d0e Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 17 Jan 2016 09:33:24 -0800 Subject: [PATCH 6/9] api: /accounts returns Accounts, /accountnames just the names --- hledger-api/hledger-api.hs | 50 +++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/hledger-api/hledger-api.hs b/hledger-api/hledger-api.hs index d7b22a909..766aef8a7 100644 --- a/hledger-api/hledger-api.hs +++ b/hledger-api/hledger-api.hs @@ -19,7 +19,7 @@ import Data.Decimal import qualified Data.Map as M import Data.Monoid import Data.Proxy -import Data.Text +import Data.Text hiding (map) import GHC.Generics import Network.Wai as Wai import Network.Wai.Handler.Warp as Warp @@ -68,7 +68,7 @@ main = do serveApi :: FilePath -> Int -> Journal -> IO () serveApi f p j = do - printf "Starting web api for %s on port %d\nPress ctrl-c to quit\n" f p >> hFlush stdout + printf "Starting web api for %s on port %d\nPress ctrl-c to quit\n" f p Warp.run p $ hledgerApiApp j hledgerApiApp :: Journal -> Wai.Application @@ -77,6 +77,7 @@ hledgerApiApp j = Servant.serve hledgerApi hledgerApiServer hledgerApi :: Proxy HledgerApi hledgerApi = Proxy + -- add Reader to the server monad so handlers can see the journal hledgerApiServer :: Servant.Server HledgerApi hledgerApiServer = Servant.enter readerToEither hledgerServerT where @@ -84,22 +85,25 @@ hledgerApiApp j = Servant.serve hledgerApi hledgerApiServer readerToEither = Nat $ \r -> return (runReader r j) type HledgerApi = - "accounts" :> Get '[JSON] [AccountName] + "accountnames" :> Get '[JSON] [AccountName] :<|> "transactions" :> Get '[JSON] [Transaction] - :<|> "prices" :> Get '[JSON] [MarketPrice] - :<|> "commodities" :> Get '[JSON] [Commodity] + :<|> "prices" :> Get '[JSON] [MarketPrice] + :<|> "commodities" :> Get '[JSON] [Commodity] + :<|> "accounts" :> Get '[JSON] [Account] hledgerServerT :: ServerT HledgerApi (Reader Journal) hledgerServerT = - accountsH + accountnamesH :<|> transactionsH :<|> pricesH :<|> commoditiesH + :<|> accountsH where - accountsH = journalAccountNames <$> ask + accountnamesH = journalAccountNames <$> ask transactionsH = jtxns <$> ask pricesH = jmarketprices <$> ask commoditiesH = (M.keys . jcommoditystyles) <$> ask + accountsH = laccounts . ledgerFromJournal Hledger.Cli.Any <$> ask instance ToJSON ClearedStatus where toJSON = genericToJSON defaultOptions -- avoid https://github.com/bos/aeson/issues/290 @@ -115,17 +119,16 @@ instance ToJSON Posting where toJSON Posting{..} = object - ["pdate" .= toJSON pdate - ,"pdate2" .= toJSON pdate2 - ,"pstatus" .= toJSON pstatus - ,"paccount" .= toJSON paccount - ,"pamount" .= toJSON pamount - ,"pcomment" .= toJSON pcomment - ,"ptype" .= toJSON ptype - ,"ptags" .= toJSON ptags + ["pdate" .= toJSON pdate + ,"pdate2" .= toJSON pdate2 + ,"pstatus" .= toJSON pstatus + ,"paccount" .= toJSON paccount + ,"pamount" .= toJSON pamount + ,"pcomment" .= toJSON pcomment + ,"ptype" .= toJSON ptype + ,"ptags" .= toJSON ptags ,"pbalanceassertion" .= toJSON pbalanceassertion - -- just show parent transaction's index - ,"ptransaction" .= toJSON (maybe "" (show.tindex) ptransaction) + ,"ptransactionidx" .= toJSON (maybe "" (show.tindex) ptransaction) ] instance ToJSON PostingType where toJSON = genericToJSON defaultOptions instance ToJSON Transaction where toJSON = genericToJSON defaultOptions @@ -135,3 +138,16 @@ instance ToJSON Decimal -- object ["places" .= decimalPlaces, "mantissa" .= decimalMantissa] -- toEncoding = genericToEncoding defaultOptions toJSON d = toJSON $ show d +instance ToJSON Account + where + toJSON a = + object + ["aname" .= toJSON (aname a) + ,"aebalance" .= toJSON (aebalance a) + ,"aibalance" .= toJSON (aibalance a) + ,"anumpostings" .= toJSON (anumpostings a) + ,"aboring" .= toJSON (aboring a) + ,"aparentname" .= toJSON (maybe "" aname $ aparent a) + ,"asubs" .= toJSON (map toJSON $ asubs a) + ] + From ab1d47cfe28e4ba7c159a549d8f536e95a61663a Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 17 Jan 2016 10:19:48 -0800 Subject: [PATCH 7/9] api: /reports/accounttransactions/ACCTNAME --- hledger-api/hledger-api.hs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/hledger-api/hledger-api.hs b/hledger-api/hledger-api.hs index 766aef8a7..957898dac 100644 --- a/hledger-api/hledger-api.hs +++ b/hledger-api/hledger-api.hs @@ -8,10 +8,12 @@ -- {-# LANGUAGE TypeSynonymInstances #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE ScopedTypeVariables #-} module Main where import Control.Monad +import Control.Monad.IO.Class import Control.Monad.Trans.Either import Control.Monad.Trans.Reader import Data.Aeson @@ -19,7 +21,7 @@ import Data.Decimal import qualified Data.Map as M import Data.Monoid import Data.Proxy -import Data.Text hiding (map) +import Data.Text hiding (map,reverse) import GHC.Generics import Network.Wai as Wai import Network.Wai.Handler.Warp as Warp @@ -31,6 +33,7 @@ import System.Exit import System.IO import Text.Printf +import Hledger.Query import Hledger.Cli hiding (Reader, version) version="0.27.98" @@ -90,6 +93,9 @@ type HledgerApi = :<|> "prices" :> Get '[JSON] [MarketPrice] :<|> "commodities" :> Get '[JSON] [Commodity] :<|> "accounts" :> Get '[JSON] [Account] + :<|> "reports" :> + -- "accounttransactions" :> QueryParam "acct" AccountName :> Get '[JSON] AccountTransactionsReport + "accounttransactions" :> Capture "acct" AccountName :> Get '[JSON] AccountTransactionsReport hledgerServerT :: ServerT HledgerApi (Reader Journal) hledgerServerT = @@ -98,13 +104,24 @@ hledgerServerT = :<|> pricesH :<|> commoditiesH :<|> accountsH + :<|> accounttransactionsH where accountnamesH = journalAccountNames <$> ask transactionsH = jtxns <$> ask pricesH = jmarketprices <$> ask commoditiesH = (M.keys . jcommoditystyles) <$> ask accountsH = laccounts . ledgerFromJournal Hledger.Cli.Any <$> ask - + accounttransactionsH (a::AccountName) = do + j <- ask + -- d <- liftIO getCurrentDay + let + ropts = defreportopts + -- ropts' = ropts {depth_=Nothing + -- ,balancetype_=HistoricalBalance + -- } + q = Hledger.Query.Any --filterQuery (not . queryIsDepth) $ queryFromOpts d ropts' + thisacctq = Acct $ accountNameToAccountRegex a -- includes subs + return $ accountTransactionsReport ropts j q thisacctq instance ToJSON ClearedStatus where toJSON = genericToJSON defaultOptions -- avoid https://github.com/bos/aeson/issues/290 instance ToJSON GenericSourcePos where toJSON = genericToJSON defaultOptions @@ -151,3 +168,5 @@ instance ToJSON Account ,"asubs" .= toJSON (map toJSON $ asubs a) ] + +instance ToJSON AccountTransactionsReport where toJSON = genericToJSON defaultOptions From cabcd80ad5cad5646b0540cb72e436038c4939e5 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 17 Jan 2016 11:07:26 -0800 Subject: [PATCH 8/9] api: cleanup --- hledger-api/hledger-api.hs | 73 +++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/hledger-api/hledger-api.hs b/hledger-api/hledger-api.hs index 957898dac..fe780a413 100644 --- a/hledger-api/hledger-api.hs +++ b/hledger-api/hledger-api.hs @@ -82,7 +82,7 @@ hledgerApiApp j = Servant.serve hledgerApi hledgerApiServer -- add Reader to the server monad so handlers can see the journal hledgerApiServer :: Servant.Server HledgerApi - hledgerApiServer = Servant.enter readerToEither hledgerServerT + hledgerApiServer = Servant.enter readerToEither hledgerAPIServer where readerToEither :: Reader Journal :~> EitherT ServantErr IO readerToEither = Nat $ \r -> return (runReader r j) @@ -94,11 +94,10 @@ type HledgerApi = :<|> "commodities" :> Get '[JSON] [Commodity] :<|> "accounts" :> Get '[JSON] [Account] :<|> "reports" :> - -- "accounttransactions" :> QueryParam "acct" AccountName :> Get '[JSON] AccountTransactionsReport "accounttransactions" :> Capture "acct" AccountName :> Get '[JSON] AccountTransactionsReport -hledgerServerT :: ServerT HledgerApi (Reader Journal) -hledgerServerT = +hledgerAPIServer :: ServerT HledgerApi (Reader Journal) +hledgerAPIServer = accountnamesH :<|> transactionsH :<|> pricesH @@ -123,8 +122,12 @@ hledgerServerT = thisacctq = Acct $ accountNameToAccountRegex a -- includes subs return $ accountTransactionsReport ropts j q thisacctq -instance ToJSON ClearedStatus where toJSON = genericToJSON defaultOptions -- avoid https://github.com/bos/aeson/issues/290 +-- brief toJSON definitions included to avoid https://github.com/bos/aeson/issues/290 +-- use toEncoding = genericToEncoding defaultOptions instead ? +instance ToJSON ClearedStatus where toJSON = genericToJSON defaultOptions instance ToJSON GenericSourcePos where toJSON = genericToJSON defaultOptions +instance ToJSON Decimal where + toJSON = toJSON . show instance ToJSON Amount where toJSON = genericToJSON defaultOptions instance ToJSON AmountStyle where toJSON = genericToJSON defaultOptions instance ToJSON Side where toJSON = genericToJSON defaultOptions @@ -132,41 +135,31 @@ instance ToJSON DigitGroupStyle where toJSON = genericToJSON defaultOptions instance ToJSON MixedAmount where toJSON = genericToJSON defaultOptions instance ToJSON Price where toJSON = genericToJSON defaultOptions instance ToJSON MarketPrice where toJSON = genericToJSON defaultOptions -instance ToJSON Posting - where - toJSON Posting{..} = - object - ["pdate" .= toJSON pdate - ,"pdate2" .= toJSON pdate2 - ,"pstatus" .= toJSON pstatus - ,"paccount" .= toJSON paccount - ,"pamount" .= toJSON pamount - ,"pcomment" .= toJSON pcomment - ,"ptype" .= toJSON ptype - ,"ptags" .= toJSON ptags - ,"pbalanceassertion" .= toJSON pbalanceassertion - ,"ptransactionidx" .= toJSON (maybe "" (show.tindex) ptransaction) - ] instance ToJSON PostingType where toJSON = genericToJSON defaultOptions +instance ToJSON Posting where + toJSON Posting{..} = + object + ["pdate" .= toJSON pdate + ,"pdate2" .= toJSON pdate2 + ,"pstatus" .= toJSON pstatus + ,"paccount" .= toJSON paccount + ,"pamount" .= toJSON pamount + ,"pcomment" .= toJSON pcomment + ,"ptype" .= toJSON ptype + ,"ptags" .= toJSON ptags + ,"pbalanceassertion" .= toJSON pbalanceassertion + ,"ptransactionidx" .= toJSON (maybe "" (show.tindex) ptransaction) + ] instance ToJSON Transaction where toJSON = genericToJSON defaultOptions -instance ToJSON Decimal - where - -- toJSON (Decimal decimalPlaces decimalMantissa) = - -- object ["places" .= decimalPlaces, "mantissa" .= decimalMantissa] - -- toEncoding = genericToEncoding defaultOptions - toJSON d = toJSON $ show d -instance ToJSON Account - where - toJSON a = - object - ["aname" .= toJSON (aname a) - ,"aebalance" .= toJSON (aebalance a) - ,"aibalance" .= toJSON (aibalance a) - ,"anumpostings" .= toJSON (anumpostings a) - ,"aboring" .= toJSON (aboring a) - ,"aparentname" .= toJSON (maybe "" aname $ aparent a) - ,"asubs" .= toJSON (map toJSON $ asubs a) - ] - - +instance ToJSON Account where + toJSON a = + object + ["aname" .= toJSON (aname a) + ,"aebalance" .= toJSON (aebalance a) + ,"aibalance" .= toJSON (aibalance a) + ,"anumpostings" .= toJSON (anumpostings a) + ,"aboring" .= toJSON (aboring a) + ,"aparentname" .= toJSON (maybe "" aname $ aparent a) + ,"asubs" .= toJSON (map toJSON $ asubs a) + ] instance ToJSON AccountTransactionsReport where toJSON = genericToJSON defaultOptions From fb32d54a90c3eada94e81e61cd79e49c87cdddda Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 18 Jan 2016 08:46:56 -0800 Subject: [PATCH 9/9] api: also serve files from static/; drop ServerT --- hledger-api/hledger-api.hs | 68 ++++++++++++++++------------------- hledger-api/static/README.txt | 1 + 2 files changed, 32 insertions(+), 37 deletions(-) create mode 100644 hledger-api/static/README.txt diff --git a/hledger-api/hledger-api.hs b/hledger-api/hledger-api.hs index fe780a413..e6fcf5a41 100644 --- a/hledger-api/hledger-api.hs +++ b/hledger-api/hledger-api.hs @@ -74,19 +74,6 @@ serveApi f p j = do printf "Starting web api for %s on port %d\nPress ctrl-c to quit\n" f p Warp.run p $ hledgerApiApp j -hledgerApiApp :: Journal -> Wai.Application -hledgerApiApp j = Servant.serve hledgerApi hledgerApiServer - where - hledgerApi :: Proxy HledgerApi - hledgerApi = Proxy - - -- add Reader to the server monad so handlers can see the journal - hledgerApiServer :: Servant.Server HledgerApi - hledgerApiServer = Servant.enter readerToEither hledgerAPIServer - where - readerToEither :: Reader Journal :~> EitherT ServantErr IO - readerToEither = Nat $ \r -> return (runReader r j) - type HledgerApi = "accountnames" :> Get '[JSON] [AccountName] :<|> "transactions" :> Get '[JSON] [Transaction] @@ -95,32 +82,39 @@ type HledgerApi = :<|> "accounts" :> Get '[JSON] [Account] :<|> "reports" :> "accounttransactions" :> Capture "acct" AccountName :> Get '[JSON] AccountTransactionsReport + :<|> Raw -hledgerAPIServer :: ServerT HledgerApi (Reader Journal) -hledgerAPIServer = - accountnamesH - :<|> transactionsH - :<|> pricesH - :<|> commoditiesH - :<|> accountsH - :<|> accounttransactionsH +hledgerApiApp :: Journal -> Wai.Application +hledgerApiApp j = Servant.serve api server where - accountnamesH = journalAccountNames <$> ask - transactionsH = jtxns <$> ask - pricesH = jmarketprices <$> ask - commoditiesH = (M.keys . jcommoditystyles) <$> ask - accountsH = laccounts . ledgerFromJournal Hledger.Cli.Any <$> ask - accounttransactionsH (a::AccountName) = do - j <- ask - -- d <- liftIO getCurrentDay - let - ropts = defreportopts - -- ropts' = ropts {depth_=Nothing - -- ,balancetype_=HistoricalBalance - -- } - q = Hledger.Query.Any --filterQuery (not . queryIsDepth) $ queryFromOpts d ropts' - thisacctq = Acct $ accountNameToAccountRegex a -- includes subs - return $ accountTransactionsReport ropts j q thisacctq + api :: Proxy HledgerApi + api = Proxy + + server :: Server HledgerApi + server = + accountnamesH + :<|> transactionsH + :<|> pricesH + :<|> commoditiesH + :<|> accountsH + :<|> accounttransactionsH + :<|> serveDirectory "static" + where + accountnamesH = return $ journalAccountNames j + transactionsH = return $ jtxns j + pricesH = return $ jmarketprices j + commoditiesH = return $ (M.keys . jcommoditystyles) j + accountsH = return $ laccounts $ ledgerFromJournal Hledger.Cli.Any j + accounttransactionsH (a::AccountName) = do + -- d <- liftIO getCurrentDay + let + ropts = defreportopts + -- ropts' = ropts {depth_=Nothing + -- ,balancetype_=HistoricalBalance + -- } + q = Hledger.Query.Any --filterQuery (not . queryIsDepth) $ queryFromOpts d ropts' + thisacctq = Acct $ accountNameToAccountRegex a -- includes subs + return $ accountTransactionsReport ropts j q thisacctq -- brief toJSON definitions included to avoid https://github.com/bos/aeson/issues/290 -- use toEncoding = genericToEncoding defaultOptions instead ? diff --git a/hledger-api/static/README.txt b/hledger-api/static/README.txt new file mode 100644 index 000000000..2b8913edb --- /dev/null +++ b/hledger-api/static/README.txt @@ -0,0 +1 @@ +Files under this directory are served by hledger-api when no other API route is matched.