From f35b961c86412dc59d88a88a05e95d3c33668b41 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 29 May 2012 02:53:33 +0000 Subject: [PATCH] web: update for yesod 1.0 --- hledger-web/Hledger/Web/Foundation.hs | 6 +- hledger-web/Hledger/Web/Handlers.hs | 32 +++++----- .../Hledger/Web/Settings/StaticFiles.hs | 2 +- hledger-web/hledger-web.cabal | 62 +++++++++---------- hledger-web/hledger-web.hs | 2 + 5 files changed, 50 insertions(+), 54 deletions(-) diff --git a/hledger-web/Hledger/Web/Foundation.hs b/hledger-web/Hledger/Web/Foundation.hs index 106b922e2..7d8620ac6 100644 --- a/hledger-web/Hledger/Web/Foundation.hs +++ b/hledger-web/Hledger/Web/Foundation.hs @@ -27,7 +27,6 @@ import Yesod.Default.Util (addStaticContentExternal) import Yesod.Static import Yesod.Logger (Logger, logMsg, formatLogText) import Control.Monad.IO.Class (liftIO) -import Web.ClientSession (getKey) import Hledger.Web.Options import Hledger.Web.Settings @@ -56,9 +55,6 @@ instance Yesod App where -- approot = Hledger.Web.Settings.appRoot . settings approot = ApprootMaster $ appRoot . settings - -- Place the session key file in the config folder - encryptKey _ = fmap Just $ getKey "client_session_key.aes" - defaultLayout widget = do -- master <- getYesod -- mmsg <- getMessage @@ -74,7 +70,7 @@ instance Yesod App where pc <- widgetToPageContent $ do widget hamletToRepHtml [hamlet| -!!! +$doctype 5 #{pageTitle pc} diff --git a/hledger-web/Hledger/Web/Handlers.hs b/hledger-web/Hledger/Web/Handlers.hs index aab18be3b..b44356f60 100644 --- a/hledger-web/Hledger/Web/Handlers.hs +++ b/hledger-web/Hledger/Web/Handlers.hs @@ -58,7 +58,7 @@ import Text.Printf import Yesod.Core -- import Yesod.Json -import Hledger hiding (today) +import Hledger hiding (is) import Hledger.Cli hiding (version) import Hledger.Web.Foundation import Hledger.Web.Options @@ -94,14 +94,14 @@ getJournalR = do -- showlastcolumn = if injournal && not filtering then False else True title = case inacct of Nothing -> "Journal"++s2 - Just (a,subs) -> "Transactions in "++a++s1++s2 - where s1 = if subs then " (and subaccounts)" else "" + Just (a,inclsubs) -> "Transactions in "++a++s1++s2 + where s1 = if inclsubs then " (and subaccounts)" else "" where s2 = if filtering then ", filtered" else "" maincontent = journalTransactionsReportAsHtml opts vd $ journalTransactionsReport (reportopts_ $ cliopts_ opts) j m defaultLayout $ do setTitle "hledger-web journal" - addHamlet [hamlet| + addWidget $ toWidget [hamlet| ^{topbar vd} registerReportHtml opts vd $ accountTransactionsReport (reportopts_ $ cliopts_ opts) j m m' -- Nothing -> registerReportHtml opts vd $ journalTransactionsReport (reportopts_ $ cliopts_ opts) j m @@ -206,7 +206,7 @@ getAccountsR = do let j' = filterJournalPostings2 m j html = do setTitle "hledger-web accounts" - addHamlet $ accountsReportAsHtml opts vd $ accountsReport2 (reportopts_ $ cliopts_ opts) am j' + addWidget $ toWidget $ accountsReportAsHtml opts vd $ accountsReport2 (reportopts_ $ cliopts_ opts) am j' json = jsonMap [("accounts", toJSON $ journalAccountNames j')] defaultLayoutJson html json @@ -222,7 +222,7 @@ getAccountsJsonR = do -- | Render the sidebar used on most views. sidebar :: ViewData -> HtmlUrl AppRoute -sidebar vd@VD{..} = accountsReportAsHtml opts vd $ accountsReport2 (reportopts_ $ cliopts_ opts) am j +sidebar vd@VD{..} = accountsReportAsHtml opts vd $ accountsReport (reportopts_ $ cliopts_ opts) am j -- | Render an "AccountsReport" as html. accountsReportAsHtml :: WebOpts -> ViewData -> AccountsReport -> HtmlUrl AppRoute @@ -264,7 +264,7 @@ accountsReportAsHtml _ vd@VD{..} (items',total) = |] where - l = journalToLedger nullfilterspec j + l = journalToLedger Any j inacctmatcher = inAccountQuery qopts allaccts = isNothing inacctmatcher items = items' -- maybe items' (\m -> filter (matchesAccount m . \(a,_,_,_)->a) items') showacctmatcher @@ -519,7 +519,7 @@ handleAdd = do acct1E = maybe (Left "to account required") (Right . unpack) $ maybeNonNull acct1M acct2E = maybe (Left "from account required") (Right . unpack) $ maybeNonNull acct2M amt1E = maybe (Left "amount required") (either (const $ Left "could not parse amount") Right . parseWithCtx nullctx amount . unpack) amt1M - amt2E = maybe (Right missingamt) (either (const $ Left "could not parse amount") Right . parseWithCtx nullctx amount . unpack) amt2M + amt2E = maybe (Right missingmixedamt) (either (const $ Left "could not parse amount") Right . parseWithCtx nullctx amount . unpack) amt2M journalE = maybe (Right $ journalFilePath j) (\f -> let f' = unpack f in if f' `elem` journalFilePaths j diff --git a/hledger-web/Hledger/Web/Settings/StaticFiles.hs b/hledger-web/Hledger/Web/Settings/StaticFiles.hs index b1aeaaeca..7d7fade8d 100644 --- a/hledger-web/Hledger/Web/Settings/StaticFiles.hs +++ b/hledger-web/Hledger/Web/Settings/StaticFiles.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE QuasiQuotes, TemplateHaskell, TypeFamilies, CPP #-} +{-# LANGUAGE QuasiQuotes, TemplateHaskell, TypeFamilies, CPP, OverloadedStrings #-} {-| This module exports routes for all the files in the static directory at diff --git a/hledger-web/hledger-web.cabal b/hledger-web/hledger-web.cabal index 0e16f9518..ee998d2ef 100644 --- a/hledger-web/hledger-web.cabal +++ b/hledger-web/hledger-web.cabal @@ -122,39 +122,37 @@ executable hledger-web Hledger.Web.Handlers build-depends: - hledger == 0.18 - , hledger-lib == 0.18 + hledger == 0.18 + , hledger-lib == 0.18 + , base >= 4 && < 5 + , cabal-file-th + , cmdargs >= 0.9.1 && < 0.10 + , directory + , filepath + , HUnit + , io-storage >= 0.3 && < 0.4 + , old-locale + , parsec + , regexpr >= 0.5.1 + , safe >= 0.2 + , time - , cabal-file-th - , cmdargs >= 0.9.1 && < 0.10 - , directory - , filepath - , HUnit - , old-locale - , parsec - , regexpr >= 0.5.1 - , safe >= 0.2 - , time - , io-storage >= 0.3 && < 0.4 - , file-embed == 0.0.* - - , base >= 4 && < 5 - , blaze-html >= 0.4.3.1 && < 0.5 - , yesod-core >= 0.10 && < 0.11 - , yesod-static >= 0.10 && < 0.11 - , yesod-default >= 0.6 && < 0.7 - , clientsession >= 0.7.3 && < 0.8 - , bytestring >= 0.9 && < 0.10 - , text >= 0.11 && < 0.12 - , template-haskell - , hamlet >= 0.10 && < 0.11 - , shakespeare-text >= 0.10 && < 0.12 - , wai >= 1.1 && < 1.2 - , wai-extra >= 1.1 && < 1.2 - , transformers >= 0.2 && < 0.3 - , monad-control >= 0.3 && < 0.4 - , yaml >= 0.5 && < 0.6 - , warp >= 1.1.0.1 && < 1.2 + , yesod == 1.0.* + , yesod-core + , yesod-default + , yesod-static + , blaze-html + , clientsession + , hamlet + , network-conduit + , shakespeare-text + , template-haskell + , text >= 0.11 && < 0.12 + , transformers >= 0.2 && < 0.4 + , wai + , wai-extra + , warp + , yaml -- if flag(production) diff --git a/hledger-web/hledger-web.hs b/hledger-web/hledger-web.hs index 2b5d1516f..fb4ab676a 100644 --- a/hledger-web/hledger-web.hs +++ b/hledger-web/hledger-web.hs @@ -10,6 +10,7 @@ Released under GPL version 3 or later. module Main where +import Data.Conduit.Network (HostPreference(..)) import Network.Wai.Handler.Warp (runSettings, defaultSettings, settingsPort) import Yesod.Default.Config -- import Yesod.Default.Main (defaultMain) @@ -82,6 +83,7 @@ server baseurl port opts j = do appEnv = Development , appPort = port_ opts , appRoot = pack baseurl + , appHost = HostIPv4 , appExtra = Extra "" Nothing } logger <- defaultDevelopmentLogger