From f9ce624ef0f8008a6a9ac411b9c44995f7885573 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 15 Jul 2011 21:58:46 +0000 Subject: [PATCH] web: separate journal & register urls, ui tweaks, code refactoring --- hledger-web/.hledger/web/static/style.css | 5 +- hledger-web/Handlers.hs | 311 +++++++++++++++------- hledger-web/routes | 8 +- hledger/Hledger/Cli/Register.hs | 1 + 4 files changed, 219 insertions(+), 106 deletions(-) diff --git a/hledger-web/.hledger/web/static/style.css b/hledger-web/.hledger/web/static/style.css index df42ebabb..62d749287 100644 --- a/hledger-web/.hledger/web/static/style.css +++ b/hledger-web/.hledger/web/static/style.css @@ -27,13 +27,12 @@ body { backgroun .notinacct, .notinacct :link, .notinacct :visited { color:#888; } .notinacct .negative { color:#b77; } .balancereport .numpostings { padding-left:1em; color:#aaa; } -.balancereport .hoverlinks { visibility:hidden; } .balancereport td.add.mouseover { background-color:rgba(208,208,208,0.5); } .balancereport td.journal.mouseover { background-color:rgba(208,208,208,0.5); } .balancereport td.journal.mouseover .hoverlinks { visibility:visible; } -.balancereport .hoverlinks { visibility:hidden; } .balancereport td.account.mouseover { background-color:rgba(208,208,208,0.5); } .balancereport td.account.mouseover .hoverlinks { visibility:visible; } +.balancereport .hoverlinks { visibility:hidden; } .balancereport .hoverlinks { margin-left:0em; font-weight:normal; /*font-size:smaller;*/ display:inline-block; text-align:right; } .balancereport .hoverlinks a { margin-left:0.5em; } @@ -103,7 +102,7 @@ body { margin:0; } .positive { } table.journalreport { border-spacing: 0; } -.journalreport td { border-top:thin solid #ded; } +.journalreport td { } .journalreport pre { margin-top:0; } .balancereport { border-spacing:0; } diff --git a/hledger-web/Handlers.hs b/hledger-web/Handlers.hs index b0fec30c5..c06fa26c6 100644 --- a/hledger-web/Handlers.hs +++ b/hledger-web/Handlers.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings, RecordWildCards #-} {- hledger-web's request handlers, and helpers. @@ -46,16 +46,90 @@ getRootR :: Handler RepHtml getRootR = redirect RedirectTemporary defaultroute where defaultroute = RegisterR ---------------------------------------------------------------------- --- main views +-- main views: --- | The journal entries view, with accounts sidebar. +-- | The formatted journal view, with sidebar. getJournalR :: Handler RepHtml getJournalR = do - vd@VD{opts=opts,m=m,am=am,j=j} <- getViewData + vd@VD{opts=opts,qopts=qopts,m=m,j=j} <- getViewData + let sidecontent = sidebar vd + -- XXX like registerReportAsHtml + inacct = inAccount qopts + -- injournal = isNothing inacct + filtering = m /= MatchAny + -- showlastcolumn = if injournal && not filtering then False else True + title = case inacct of + Nothing -> "Journal"++filter + Just (a,subs) -> "Transactions in "++a++andsubs++filter + where andsubs = if subs then " (and subaccounts)" else "" + where + filter = if filtering then ", filtered" else "" + maincontent = formattedJournalReportAsHtml opts vd $ journalRegisterReport opts j m + defaultLayout $ do + setTitle "hledger-web journal" + addHamlet [$hamlet| +^{topbar vd} +#{title} + ^{searchform vd} + "Journal"++filter +-- Just (a,subs) -> "Transactions in "++a++andsubs++filter +-- where andsubs = if subs then " (and subaccounts)" else "" +-- where +-- filter = if filtering then ", filtered" else "" +-- maincontent = +-- case inAccountMatcher qopts of Just m' -> registerReportAsHtml opts vd $ accountRegisterReport opts j m m' +-- Nothing -> registerReportAsHtml opts vd $ journalRegisterReport opts j m +-- defaultLayout $ do +-- setTitle "hledger-web register" +-- addHamlet [$hamlet| +-- ^{topbar vd} +-- #{title} +-- ^{searchform vd} +-- "Journal"++filter - Just (a,subs) -> "Transactions in "++a++andsubs++filter - where andsubs = if subs then " (and subaccounts)" else "" - where - filter = if filtering then ", filtered" else "" - maincontent = - case inAccountMatcher qopts of Just m' -> registerReportAsHtml opts vd $ accountRegisterReport opts j m m' - Nothing -> registerReportAsHtml opts vd $ journalRegisterReport opts j m + title = "Transactions in "++a++andsubs++filter + where + (a,subs) = fromMaybe ("all accounts",False) $ inAccount qopts + andsubs = if subs then " (and subaccounts)" else "" + filter = if filtering then ", filtered" else "" + maincontent = registerReportHtml opts vd $ accountRegisterReport opts j m $ fromMaybe MatchAny $ inAccountMatcher qopts defaultLayout $ do setTitle "hledger-web register" addHamlet [$hamlet| @@ -117,15 +187,17 @@ getRegisterR = do ^{importform} |] --- | The register view with no sidebar. +-- | The register view, no sidebar. getRegisterOnlyR :: Handler RepHtml getRegisterOnlyR = do vd@VD{opts=opts,qopts=qopts,m=m,j=j} <- getViewData defaultLayout $ do setTitle "hledger-web register only" addHamlet $ - case inAccountMatcher qopts of Just m' -> registerReportAsHtml opts vd $ accountRegisterReport opts j m m' - Nothing -> registerReportAsHtml opts vd $ journalRegisterReport opts j m + case inAccountMatcher qopts of Just m' -> registerReportHtml opts vd $ accountRegisterReport opts j m m' + Nothing -> registerReportHtml opts vd $ journalRegisterReport opts j m + +---------------------------------------------------------------------- -- | A simple accounts view. This one is json-capable, returning the chart -- of accounts as json if the Accept header specifies json. @@ -149,12 +221,16 @@ getAccountsJsonR = do ---------------------------------------------------------------------- -- view helpers +-- | Render the sidebar used on most views. +sidebar :: ViewData -> Hamlet AppRoute +sidebar vd@VD{opts=opts,am=am,j=j} = balanceReportAsHtml opts vd $ balanceReport2 opts am j + -- | Render a "BalanceReport" as HTML. balanceReportAsHtml :: [Opt] -> ViewData -> BalanceReport -> Hamlet AppRoute balanceReportAsHtml _ vd@VD{qopts=qopts,j=j} (items',total) = [$hamlet| [+/-] + [+] - Journal + Journal entries + raw   - edit + edit +   + (edit) AccountName -> (AppRoute,[(String,ByteString)]) accountUrl r a = (r, [("q",pack $ accountQuery a)]) --- | Render a "JournalReport" as HTML. -journalReportAsHtml :: [Opt] -> ViewData -> JournalReport -> Hamlet AppRoute -journalReportAsHtml _ vd items = [$hamlet| +-- | Render a "JournalReport" as HTML for the raw journal view. +rawJournalReportAsHtml :: [Opt] -> ViewData -> JournalReport -> Hamlet AppRoute +rawJournalReportAsHtml _ vd items = [$hamlet| $forall i <- numbered items ^{itemAsHtml vd i} @@ -246,11 +324,107 @@ journalReportAsHtml _ vd items = [$hamlet| evenodd = if even n then "even" else "odd" :: String txn = trimnl $ showTransaction t where trimnl = reverse . dropWhile (=='\n') . reverse --- Render an "AccountRegisterReport" as html, for the journal/account register views. -registerReportAsHtml :: [Opt] -> ViewData -> AccountRegisterReport -> Hamlet AppRoute -registerReportAsHtml _ vd@VD{m=m,qopts=qopts} (balancelabel,items) = [$hamlet| -$if showlastcolumn -