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