From df425802d4b61fa85be369e8d58b0107f045aab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Z=C3=A1rybnick=C3=BD?= Date: Sun, 17 Jun 2018 14:31:42 +0200 Subject: [PATCH] web: Add 'hide empty accounts' option (bound to 'e' key) --- hledger-web/src/Foundation.hs | 22 ++++++++++----------- hledger-web/src/Widget/Common.hs | 8 ++++---- hledger-web/static/hledger.js | 6 ++++++ hledger-web/templates/default-layout.hamlet | 1 + 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/hledger-web/src/Foundation.hs b/hledger-web/src/Foundation.hs index 6b82e4381..3df02edc7 100644 --- a/hledger-web/src/Foundation.hs +++ b/hledger-web/src/Foundation.hs @@ -100,12 +100,13 @@ instance Yesod App where VD {j, m, opts, q, qopts} <- getViewData msg <- getMessage showSidebar <- shouldShowSidebar + hideEmptyAccts <- (== Just "1") . lookup "hideemptyaccts" . reqCookies <$> getRequest let ropts = reportopts_ (cliopts_ opts) -- flip the default for items with zero amounts, show them by default ropts' = ropts { empty_ = not (empty_ ropts) } accounts = - balanceReportAsHtml (JournalR, RegisterR) here j qopts $ + balanceReportAsHtml (JournalR, RegisterR) here hideEmptyAccts j qopts $ balanceReport ropts' m j topShowmd = if showSidebar then "col-md-4" else "col-any-0" :: Text @@ -216,13 +217,12 @@ getCurrentJournal jref opts d = do j <- liftIO (readIORef jref) (ej, changed) <- liftIO $ journalReloadIfChanged opts d j -- re-apply any initial filter specified at startup - let initq = queryFromOpts d $ reportopts_ opts - if not changed - then return (j,Nothing) - else case filterJournalTransactions initq <$> ej of - Right j' -> do - liftIO $ writeIORef jref j' - return (j',Nothing) - Left e -> do - setMessage "error while reading journal" - return (j, Just e) + let initq = queryFromOpts d (reportopts_ opts) + case (changed, filterJournalTransactions initq <$> ej) of + (False, _) -> return (j, Nothing) + (True, Right j') -> do + liftIO $ writeIORef jref j' + return (j',Nothing) + (True, Left e) -> do + setMessage "error while reading journal" + return (j, Just e) diff --git a/hledger-web/src/Widget/Common.hs b/hledger-web/src/Widget/Common.hs index 88e998891..8be72ae63 100644 --- a/hledger-web/src/Widget/Common.hs +++ b/hledger-web/src/Widget/Common.hs @@ -56,8 +56,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 -> Journal -> [QueryOpt] -> BalanceReport -> HtmlUrl r -balanceReportAsHtml (journalR, registerR) here j qopts (items, total) = [hamlet| +balanceReportAsHtml :: Eq r => (r, r) -> r -> Bool -> Journal -> [QueryOpt] -> BalanceReport -> HtmlUrl r +balanceReportAsHtml (journalR, registerR) here hideEmpty j qopts (items, total) = [hamlet| $forall (acct, adisplay, aindent, abal) <- items - - + +
\#{indent aindent} a - add a transaction (escape to cancel)
  • s - toggle sidebar
  • f - focus search form ("find") +
  • e - hide empty accounts in sidebar

    General