mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-19 10:17:35 +03:00
dev: web: refactor: ViewData q, m -> qparam, q
This commit is contained in:
parent
981ebb6518
commit
559f436d3e
@ -114,7 +114,7 @@ instance Yesod App where
|
||||
|
||||
master <- getYesod
|
||||
here <- fromMaybe RootR <$> getCurrentRoute
|
||||
VD {caps, j, m, opts, q, qopts} <- getViewData
|
||||
VD{opts, j, qparam, q, qopts, caps} <- getViewData
|
||||
msg <- getMessage
|
||||
showSidebar <- shouldShowSidebar
|
||||
|
||||
@ -124,14 +124,14 @@ instance Yesod App where
|
||||
{accountlistmode_ = ALTree -- force tree mode for sidebar
|
||||
,empty_ = True -- show zero items by default
|
||||
}
|
||||
rspec' = rspec{_rsQuery=m,_rsReportOpts=ropts'}
|
||||
rspec' = rspec{_rsQuery=q,_rsReportOpts=ropts'}
|
||||
|
||||
hideEmptyAccts <- if empty_ ropts
|
||||
then return True
|
||||
else (== Just "1") . lookup "hideemptyaccts" . reqCookies <$> getRequest
|
||||
|
||||
let accounts =
|
||||
balanceReportAsHtml (JournalR, RegisterR) here hideEmptyAccts j q qopts $
|
||||
balanceReportAsHtml (JournalR, RegisterR) here hideEmptyAccts j qparam qopts $
|
||||
balanceReport rspec' j
|
||||
|
||||
topShowmd = if showSidebar then "col-md-4" else "col-any-0" :: Text
|
||||
@ -195,8 +195,8 @@ data ViewData = VD
|
||||
{ opts :: WebOpts -- ^ the command-line options at startup
|
||||
, today :: Day -- ^ today's date (for queries containing relative dates)
|
||||
, j :: Journal -- ^ the up-to-date parsed unfiltered journal
|
||||
, q :: Text -- ^ the current q parameter, the main query expression
|
||||
, m :: Query -- ^ a query parsed from the q parameter
|
||||
, qparam :: Text -- ^ the current "q" request parameter
|
||||
, q :: Query -- ^ a query parsed from the q parameter
|
||||
, qopts :: [QueryOpt] -- ^ query options parsed from the q parameter
|
||||
, caps :: [Capability] -- ^ capabilities enabled for this request
|
||||
} deriving (Show)
|
||||
@ -242,7 +242,7 @@ getViewData = do
|
||||
Left e -> [] <$ addMessage "" ("Unknown permission: " <> toHtml (BC.unpack e))
|
||||
Right c -> pure [c]
|
||||
|
||||
return VD{opts, today, j, q=qparam, m=q, qopts, caps} -- adapt to old q, m field names for now
|
||||
return VD{opts, today, j, qparam, q, qopts, caps}
|
||||
|
||||
checkServerSideUiEnabled :: Handler ()
|
||||
checkServerSideUiEnabled = do
|
||||
|
@ -20,14 +20,14 @@ import Hledger.Web.Widget.Common
|
||||
getJournalR :: Handler Html
|
||||
getJournalR = do
|
||||
checkServerSideUiEnabled
|
||||
VD{caps, j, m, opts, q, qopts, today} <- getViewData
|
||||
VD{caps, j, q, opts, qparam, qopts, today} <- getViewData
|
||||
when (CapView `notElem` caps) (permissionDenied "Missing the 'view' capability")
|
||||
let title = case inAccount qopts of
|
||||
Nothing -> "General Journal"
|
||||
Just (a, inclsubs) -> "Transactions in " <> a <> if inclsubs then "" else " (excluding subaccounts)"
|
||||
title' = title <> if m /= Any then ", filtered" else ""
|
||||
acctlink a = (RegisterR, [("q", replaceInacct q $ accountQuery a)])
|
||||
rspec = (reportspec_ $ cliopts_ opts){_rsQuery = filterQuery (not . queryIsDepth) m}
|
||||
title' = title <> if q /= Any then ", filtered" else ""
|
||||
acctlink a = (RegisterR, [("q", replaceInacct qparam $ accountQuery a)])
|
||||
rspec = (reportspec_ $ cliopts_ opts){_rsQuery = filterQuery (not . queryIsDepth) q}
|
||||
items = reverse $ entriesReport rspec j
|
||||
transactionFrag = transactionFragment j
|
||||
|
||||
|
@ -26,26 +26,26 @@ import Hledger.Web.Widget.Common
|
||||
getRegisterR :: Handler Html
|
||||
getRegisterR = do
|
||||
checkServerSideUiEnabled
|
||||
VD{caps, j, m, opts, q, qopts, today} <- getViewData
|
||||
VD{caps, j, q, opts, qparam, qopts, today} <- getViewData
|
||||
when (CapView `notElem` caps) (permissionDenied "Missing the 'view' capability")
|
||||
|
||||
let (a,inclsubs) = fromMaybe ("all accounts",True) $ inAccount qopts
|
||||
s1 = if inclsubs then "" else " (excluding subaccounts)"
|
||||
s2 = if m /= Any then ", filtered" else ""
|
||||
s2 = if q /= Any then ", filtered" else ""
|
||||
header = a <> s1 <> s2
|
||||
|
||||
let rspec = reportspec_ (cliopts_ opts)
|
||||
acctQuery = fromMaybe Any (inAccountQuery qopts)
|
||||
acctlink acc = (RegisterR, [("q", replaceInacct q $ accountQuery acc)])
|
||||
acctlink acc = (RegisterR, [("q", replaceInacct qparam $ accountQuery acc)])
|
||||
otherTransAccounts =
|
||||
map (\(acct,(name,comma)) -> (acct, (T.pack name, T.pack comma))) .
|
||||
undecorateLinks . elideRightDecorated 40 . decorateLinks .
|
||||
addCommas . preferReal . otherTransactionAccounts m acctQuery
|
||||
addCommas . preferReal . otherTransactionAccounts q acctQuery
|
||||
addCommas xs =
|
||||
zip xs $
|
||||
zip (map (T.unpack . accountSummarisedName . paccount) xs) $
|
||||
tail $ (", "<$xs) ++ [""]
|
||||
items = accountTransactionsReport rspec{_rsQuery=m} j acctQuery
|
||||
items = accountTransactionsReport rspec{_rsQuery=q} j acctQuery
|
||||
balancelabel
|
||||
| isJust (inAccount qopts), balanceaccum_ (_rsReportOpts rspec) == Historical = "Historical Total"
|
||||
| isJust (inAccount qopts) = "Period Total"
|
||||
|
@ -77,7 +77,7 @@ helplink topic label _ = H.a ! A.href u ! A.target "hledgerhelp" $ toHtml label
|
||||
|
||||
-- | Render a "BalanceReport" as html.
|
||||
balanceReportAsHtml :: Eq r => (r, r) -> r -> Bool -> Journal -> Text -> [QueryOpt] -> BalanceReport -> HtmlUrl r
|
||||
balanceReportAsHtml (journalR, registerR) here hideEmpty j q qopts (items, total) =
|
||||
balanceReportAsHtml (journalR, registerR) here hideEmpty j qparam qopts (items, total) =
|
||||
$(hamletFile "templates/balance-report.hamlet")
|
||||
where
|
||||
l = ledgerFromJournal Any j
|
||||
|
@ -11,11 +11,11 @@ $forall (acct, adisplay, aindent, abal) <- items
|
||||
<td .acct :not (isInterestingAccount acct):.empty>
|
||||
<div .ff-wrapper>
|
||||
\#{indent aindent}
|
||||
<a.acct-name href="@?{(registerR, [("q", replaceInacct q $ accountQuery acct)])}"
|
||||
<a.acct-name href="@?{(registerR, [("q", replaceInacct qparam $ accountQuery acct)])}"
|
||||
title="Show transactions affecting this account and subaccounts">
|
||||
#{adisplay}
|
||||
$if hasSubAccounts acct
|
||||
<a href="@?{(registerR, [("q", replaceInacct q $ accountOnlyQuery acct)])}" .only.hidden-sm.hidden-xs
|
||||
<a href="@?{(registerR, [("q", replaceInacct qparam $ accountOnlyQuery acct)])}" .only.hidden-sm.hidden-xs
|
||||
title="Show transactions affecting this account but not subaccounts">only
|
||||
<td>
|
||||
^{mixedAmountAsHtml abal}
|
||||
|
@ -17,10 +17,10 @@ $if elem CapView caps
|
||||
<div #message .alert.alert-info>#{m}
|
||||
$if elem CapView caps
|
||||
<form#searchform.input-group method=GET>
|
||||
<input .form-control name=q value=#{q} placeholder="Search"
|
||||
<input .form-control name=q value=#{qparam} placeholder="Search"
|
||||
title="Enter hledger search patterns to filter the data below">
|
||||
<div .input-group-btn>
|
||||
$if not (T.null q)
|
||||
$if not (T.null qparam)
|
||||
<a href=@{here} .btn .btn-default title="Clear search terms">
|
||||
<span .glyphicon .glyphicon-remove-circle>
|
||||
<button .btn .btn-default type=submit title="Apply search terms">
|
||||
|
@ -2,7 +2,7 @@
|
||||
#{header}
|
||||
|
||||
<div .hidden-xs>
|
||||
^{registerChartHtml q balancelabel $ accountTransactionsReportByCommodity items}
|
||||
^{registerChartHtml qparam balancelabel $ accountTransactionsReportByCommodity items}
|
||||
|
||||
<div.table-responsive>
|
||||
<table .table.table-striped.table-condensed>
|
||||
@ -21,7 +21,7 @@
|
||||
$forall (torig, tacct, split, _acct, amt, bal) <- items
|
||||
<tr ##{tindex torig} title="#{showTransaction torig}" style="vertical-align:top;">
|
||||
<td .date>
|
||||
<a href="@?{(JournalR, [("q", T.unwords $ removeInacct q)])}##{transactionFrag torig}">
|
||||
<a href="@?{(JournalR, [("q", T.unwords $ removeInacct qparam)])}##{transactionFrag torig}">
|
||||
#{show (tdate tacct)}
|
||||
<td>
|
||||
#{textElideRight 30 (tdescription tacct)}
|
||||
|
Loading…
Reference in New Issue
Block a user