diff --git a/hledger-web/src/Foundation.hs b/hledger-web/src/Foundation.hs
index 554042067..7bf5427b5 100644
--- a/hledger-web/src/Foundation.hs
+++ b/hledger-web/src/Foundation.hs
@@ -9,8 +9,10 @@ import Data.IORef (IORef, readIORef, writeIORef)
import Data.List (isPrefixOf)
import Data.Maybe (fromMaybe)
import Data.Text (Text)
+import qualified Data.Text as T
import Data.Time.Calendar (Day)
import Network.HTTP.Conduit (Manager)
+import System.FilePath (takeFileName)
import Text.Blaze (Markup)
import Text.Blaze.Html.Renderer.String (renderHtml)
import Text.Hamlet (hamletFile)
@@ -19,6 +21,7 @@ import Yesod.Static
import Yesod.Default.Config
import Handler.AddForm
+import Handler.Common (balanceReportAsHtml)
import Settings.StaticFiles
import Settings (widgetFile, Extra (..))
#ifndef DEVELOPMENT
@@ -28,7 +31,7 @@ import Yesod.Default.Util (addStaticContentExternal)
#endif
import Hledger
-import Hledger.Cli
+import Hledger.Cli (CliOpts(..), journalReloadIfChanged)
import Hledger.Web.WebOptions
-- | The site argument for your application. This can be a good place to
@@ -78,50 +81,63 @@ type Form x = Html -> MForm (HandlerT App IO) (FormResult x, Widget)
-- Please see the documentation for the Yesod typeclass. There are a number
-- of settings which can be configured by overriding methods here.
instance Yesod App where
- approot = ApprootMaster $ appRoot . settings
+ approot = ApprootMaster $ appRoot . settings
- -- don't use session data
- makeSessionBackend _ = return Nothing
+ -- don't use session data
+ makeSessionBackend _ = return Nothing
- defaultLayout widget = do
- master <- getYesod
- lastmsg <- getMessage
- VD{j, opts} <- getViewData
+ defaultLayout widget = do
+ master <- getYesod
+ lastmsg <- getMessage
+ VD{am, here, j, opts, q, qopts, showsidebar} <- getViewData
- -- We break up the default layout into two components:
- -- default-layout is the contents of the body tag, and
- -- default-layout-wrapper is the entire page. Since the final
- -- value passed to hamletToRepHtml cannot be a widget, this allows
- -- you to use normal widget features in default-layout.
- pc <- widgetToPageContent $ do
- addStylesheet $ StaticR css_bootstrap_min_css
- addStylesheet $ StaticR css_bootstrap_datepicker_standalone_min_css
- -- load these things early, in HEAD:
- toWidgetHead [hamlet|
- |]
- addStylesheet $ StaticR hledger_css
- addScript $ StaticR hledger_js
- $(widgetFile "default-layout")
+ let journalcurrent = if here == JournalR then "inacct" else "" :: Text
+ ropts = reportopts_ (cliopts_ opts)
+ -- flip the default for items with zero amounts, show them by default
+ ropts' = ropts { empty_ = not (empty_ ropts) }
+ accounts = balanceReportAsHtml RegisterR j qopts $ balanceReport ropts' am j
- withUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet")
+ topShowmd = if showsidebar then "col-md-4" else "col-any-0" :: Text
+ topShowsm = if showsidebar then "col-sm-4" else "" :: Text
+ sideShowmd = if showsidebar then "col-md-4" else "col-any-0" :: Text
+ sideShowsm = if showsidebar then "col-sm-4" else "" :: Text
+ mainShowmd = if showsidebar then "col-md-8" else "col-md-12" :: Text
+ mainShowsm = if showsidebar then "col-sm-8" else "col-sm-12" :: Text
+
+ -- We break up the default layout into two components:
+ -- default-layout is the contents of the body tag, and
+ -- default-layout-wrapper is the entire page. Since the final
+ -- value passed to hamletToRepHtml cannot be a widget, this allows
+ -- you to use normal widget features in default-layout.
+ pc <- widgetToPageContent $ do
+ addStylesheet $ StaticR css_bootstrap_min_css
+ addStylesheet $ StaticR css_bootstrap_datepicker_standalone_min_css
+ -- load these things early, in HEAD:
+ toWidgetHead [hamlet|
+ |]
+ addStylesheet $ StaticR hledger_css
+ addScript $ StaticR hledger_js
+ $(widgetFile "default-layout")
+
+ withUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet")
#ifndef DEVELOPMENT
- -- This function creates static content files in the static folder
- -- and names them based on a hash of their content. This allows
- -- expiration dates to be set far in the future without worry of
- -- users receiving stale content.
- addStaticContent = addStaticContentExternal minifym base64md5 Settings.staticDir (StaticR . flip StaticRoute [])
+ -- This function creates static content files in the static folder
+ -- and names them based on a hash of their content. This allows
+ -- expiration dates to be set far in the future without worry of
+ -- users receiving stale content.
+ addStaticContent = addStaticContentExternal minifym base64md5 Settings.staticDir (StaticR . flip StaticRoute [])
#endif
-- This instance is required to use forms. You can modify renderMessage to
diff --git a/hledger-web/src/Handler/AddR.hs b/hledger-web/src/Handler/AddR.hs
index c6db99620..68dce1b01 100644
--- a/hledger-web/src/Handler/AddR.hs
+++ b/hledger-web/src/Handler/AddR.hs
@@ -62,7 +62,7 @@ postAddR = do
Right t -> do
-- 3. all fields look good and form a balanced transaction; append it to the file
liftIO (appendTransaction journalfile t)
- setMessage [shamlet|Transaction added.|]
+ setMessage "Transaction added."
redirect JournalR
where
bail :: [Text] -> Handler ()
diff --git a/hledger-web/src/Handler/Common.hs b/hledger-web/src/Handler/Common.hs
index 5543866ad..a008ed60b 100644
--- a/hledger-web/src/Handler/Common.hs
+++ b/hledger-web/src/Handler/Common.hs
@@ -4,80 +4,17 @@
module Handler.Common where
-import Import
-
+import Data.Semigroup ((<>))
+import Data.Text (Text)
import qualified Data.Text as T
import Data.Time.Calendar (Day, toGregorian)
-import System.FilePath (takeFileName)
import Text.Blaze (ToMarkup)
import Text.Blaze.Internal (preEscapedString)
-import Text.Printf (printf)
+import Yesod
-import Hledger.Cli.CliOptions
-import Hledger.Data
-import Hledger.Query
-import Hledger.Reports
-import Hledger.Utils
-import Hledger.Web.WebOptions
+import Settings (manualurl)
--------------------------------------------------------------------------------
--- Common page layout
-
--- | Standard hledger-web page layout.
-#if MIN_VERSION_yesod(1,6,0)
-hledgerLayout :: ViewData -> Text -> HtmlUrl AppRoute -> HandlerFor App Html
-#else
-hledgerLayout :: ViewData -> Text -> HtmlUrl AppRoute -> HandlerT App IO Html
-#endif
-hledgerLayout vd title content = do
- defaultLayout $ do
- setTitle $ toHtml $ title <> " - hledger-web"
- toWidget [hamlet|
- ^{topbar vd}
- ^{sidebar vd}
-
- ^{searchform vd}
- ^{content}
- |]
- where
- showmd = if showsidebar vd then "col-md-8" else "col-md-12" :: Text
- showsm = if showsidebar vd then "col-sm-8" else "col-sm-12" :: Text
-
--- | Global toolbar/heading area.
-topbar :: ViewData -> HtmlUrl AppRoute
-topbar VD{j, showsidebar} = [hamlet|
-