lib,ui: Store the original query string in ReportOpts, provide a function for regenerating ReportOpts.
This commit is contained in:
parent
64e3e5c54d
commit
ff0c5bc743
@ -15,6 +15,7 @@ module Hledger.Reports.ReportOptions (
|
|||||||
ValuationType(..),
|
ValuationType(..),
|
||||||
defreportopts,
|
defreportopts,
|
||||||
rawOptsToReportOpts,
|
rawOptsToReportOpts,
|
||||||
|
regenerateReportOpts,
|
||||||
flat_,
|
flat_,
|
||||||
tree_,
|
tree_,
|
||||||
reportOptsToggleStatus,
|
reportOptsToggleStatus,
|
||||||
@ -96,6 +97,7 @@ data ReportOpts = ReportOpts {
|
|||||||
,format_ :: StringFormat
|
,format_ :: StringFormat
|
||||||
,query_ :: Query
|
,query_ :: Query
|
||||||
,queryopts_ :: [QueryOpt]
|
,queryopts_ :: [QueryOpt]
|
||||||
|
,querystring_ :: T.Text
|
||||||
--
|
--
|
||||||
,average_ :: Bool
|
,average_ :: Bool
|
||||||
-- for posting reports (register)
|
-- for posting reports (register)
|
||||||
@ -133,36 +135,38 @@ instance Default ReportOpts where def = defreportopts
|
|||||||
|
|
||||||
defreportopts :: ReportOpts
|
defreportopts :: ReportOpts
|
||||||
defreportopts = ReportOpts
|
defreportopts = ReportOpts
|
||||||
nulldate
|
{ today_ = nulldate
|
||||||
def
|
, period_ = PeriodAll
|
||||||
def
|
, interval_ = NoInterval
|
||||||
def
|
, statuses_ = []
|
||||||
def
|
, value_ = Nothing
|
||||||
def
|
, infer_value_ = False
|
||||||
def
|
, depth_ = Nothing
|
||||||
def
|
, date2_ = False
|
||||||
def
|
, empty_ = False
|
||||||
def
|
, no_elide_ = False
|
||||||
def
|
, real_ = False
|
||||||
def
|
, format_ = def
|
||||||
def
|
, query_ = Any
|
||||||
def
|
, queryopts_ = []
|
||||||
def
|
, querystring_ = ""
|
||||||
def
|
, average_ = False
|
||||||
def
|
, related_ = False
|
||||||
def
|
, txn_dates_ = False
|
||||||
def
|
, balancetype_ = def
|
||||||
def
|
, accountlistmode_ = ALFlat
|
||||||
def
|
, drop_ = 0
|
||||||
def
|
, row_total_ = False
|
||||||
def
|
, no_total_ = False
|
||||||
def
|
, pretty_tables_ = False
|
||||||
def
|
, sort_amount_ = False
|
||||||
def
|
, percent_ = False
|
||||||
def
|
, invert_ = False
|
||||||
def
|
, normalbalance_ = Nothing
|
||||||
def
|
, color_ = False
|
||||||
def
|
, forecast_ = Nothing
|
||||||
|
, transpose_ = False
|
||||||
|
}
|
||||||
|
|
||||||
rawOptsToReportOpts :: RawOpts -> IO ReportOpts
|
rawOptsToReportOpts :: RawOpts -> IO ReportOpts
|
||||||
rawOptsToReportOpts rawopts = do
|
rawOptsToReportOpts rawopts = do
|
||||||
@ -197,6 +201,7 @@ rawOptsToReportOpts rawopts = do
|
|||||||
,format_ = format
|
,format_ = format
|
||||||
,query_ = simplifyQuery $ And [queryFromFlags reportopts, argsquery]
|
,query_ = simplifyQuery $ And [queryFromFlags reportopts, argsquery]
|
||||||
,queryopts_ = queryopts
|
,queryopts_ = queryopts
|
||||||
|
,querystring_ = querystring
|
||||||
,average_ = boolopt "average" rawopts
|
,average_ = boolopt "average" rawopts
|
||||||
,related_ = boolopt "related" rawopts
|
,related_ = boolopt "related" rawopts
|
||||||
,txn_dates_ = boolopt "txn-dates" rawopts
|
,txn_dates_ = boolopt "txn-dates" rawopts
|
||||||
@ -216,9 +221,14 @@ rawOptsToReportOpts rawopts = do
|
|||||||
,forecast_ = forecastPeriodFromRawOpts d rawopts
|
,forecast_ = forecastPeriodFromRawOpts d rawopts
|
||||||
,transpose_ = boolopt "transpose" rawopts
|
,transpose_ = boolopt "transpose" rawopts
|
||||||
}
|
}
|
||||||
|
|
||||||
return reportopts
|
return reportopts
|
||||||
|
|
||||||
|
-- | Regenerate a ReportOpts on a different day with a different query string.
|
||||||
|
regenerateReportOpts :: Day -> T.Text -> ReportOpts -> Either String ReportOpts
|
||||||
|
regenerateReportOpts d querystring ropts = do
|
||||||
|
(q,o) <- parseQuery d querystring
|
||||||
|
return ropts{today_=d, query_=q, queryopts_=o, querystring_=querystring}
|
||||||
|
|
||||||
accountlistmodeopt :: RawOpts -> AccountListMode
|
accountlistmodeopt :: RawOpts -> AccountListMode
|
||||||
accountlistmodeopt =
|
accountlistmodeopt =
|
||||||
fromMaybe ALFlat . choiceopt parse where
|
fromMaybe ALFlat . choiceopt parse where
|
||||||
|
|||||||
@ -117,7 +117,7 @@ asInit d reset ui@UIState{
|
|||||||
asInit _ _ _ = error "init function called with wrong screen type, should not happen" -- PARTIAL:
|
asInit _ _ _ = error "init function called with wrong screen type, should not happen" -- PARTIAL:
|
||||||
|
|
||||||
asDraw :: UIState -> [Widget Name]
|
asDraw :: UIState -> [Widget Name]
|
||||||
asDraw UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts},querystring_=query}
|
asDraw UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
|
||||||
,ajournal=j
|
,ajournal=j
|
||||||
,aScreen=s@AccountsScreen{}
|
,aScreen=s@AccountsScreen{}
|
||||||
,aMode=mode
|
,aMode=mode
|
||||||
@ -172,7 +172,7 @@ asDraw UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts},que
|
|||||||
<+> toggles
|
<+> toggles
|
||||||
<+> str (" account " ++ if ishistorical then "balances" else "changes")
|
<+> str (" account " ++ if ishistorical then "balances" else "changes")
|
||||||
<+> borderPeriodStr (if ishistorical then "at end of" else "in") (period_ ropts)
|
<+> borderPeriodStr (if ishistorical then "at end of" else "in") (period_ ropts)
|
||||||
<+> borderQueryStr query
|
<+> borderQueryStr (T.unpack $ querystring_ ropts)
|
||||||
<+> borderDepthStr mdepth
|
<+> borderDepthStr mdepth
|
||||||
<+> str (" ("++curidx++"/"++totidx++")")
|
<+> str (" ("++curidx++"/"++totidx++")")
|
||||||
<+> (if ignore_assertions_ $ inputopts_ copts
|
<+> (if ignore_assertions_ $ inputopts_ copts
|
||||||
|
|||||||
@ -138,7 +138,7 @@ rsInit d reset ui@UIState{aopts=_uopts@UIOpts{cliopts_=CliOpts{reportopts_=ropts
|
|||||||
rsInit _ _ _ = error "init function called with wrong screen type, should not happen" -- PARTIAL:
|
rsInit _ _ _ = error "init function called with wrong screen type, should not happen" -- PARTIAL:
|
||||||
|
|
||||||
rsDraw :: UIState -> [Widget Name]
|
rsDraw :: UIState -> [Widget Name]
|
||||||
rsDraw UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts},querystring_=query}
|
rsDraw UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
|
||||||
,aScreen=RegisterScreen{..}
|
,aScreen=RegisterScreen{..}
|
||||||
,aMode=mode
|
,aMode=mode
|
||||||
} =
|
} =
|
||||||
@ -201,7 +201,7 @@ rsDraw UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts},que
|
|||||||
<+> togglefilters
|
<+> togglefilters
|
||||||
<+> str " transactions"
|
<+> str " transactions"
|
||||||
-- <+> str (if ishistorical then " historical total" else " period total")
|
-- <+> str (if ishistorical then " historical total" else " period total")
|
||||||
<+> borderQueryStr query
|
<+> borderQueryStr (T.unpack $ querystring_ ropts)
|
||||||
-- <+> str " and subs"
|
-- <+> str " and subs"
|
||||||
<+> borderPeriodStr "in" (period_ ropts)
|
<+> borderPeriodStr "in" (period_ ropts)
|
||||||
<+> str " ("
|
<+> str " ("
|
||||||
|
|||||||
@ -58,7 +58,7 @@ tsInit _d _reset ui@UIState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=_ropts}}
|
|||||||
tsInit _ _ _ = error "init function called with wrong screen type, should not happen" -- PARTIAL:
|
tsInit _ _ _ = error "init function called with wrong screen type, should not happen" -- PARTIAL:
|
||||||
|
|
||||||
tsDraw :: UIState -> [Widget Name]
|
tsDraw :: UIState -> [Widget Name]
|
||||||
tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts},querystring_=query}
|
tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
|
||||||
,ajournal=j
|
,ajournal=j
|
||||||
,aScreen=TransactionScreen{tsTransaction=(i,t)
|
,aScreen=TransactionScreen{tsTransaction=(i,t)
|
||||||
,tsTransactions=nts
|
,tsTransactions=nts
|
||||||
@ -97,7 +97,7 @@ tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts},querystrin
|
|||||||
<+> withAttr ("border" <> "bold") (str $ show i)
|
<+> withAttr ("border" <> "bold") (str $ show i)
|
||||||
<+> str (" of "++show (length nts))
|
<+> str (" of "++show (length nts))
|
||||||
<+> togglefilters
|
<+> togglefilters
|
||||||
<+> borderQueryStr query
|
<+> borderQueryStr (T.unpack $ querystring_ ropts)
|
||||||
<+> str (" in "++T.unpack (replaceHiddenAccountsNameWith "All" acct)++")")
|
<+> str (" in "++T.unpack (replaceHiddenAccountsNameWith "All" acct)++")")
|
||||||
<+> (if ignore_assertions_ $ inputopts_ copts then withAttr ("border" <> "query") (str " ignoring balance assertions") else str "")
|
<+> (if ignore_assertions_ $ inputopts_ copts then withAttr ("border" <> "query") (str " ignoring balance assertions") else str "")
|
||||||
where
|
where
|
||||||
|
|||||||
@ -61,14 +61,13 @@ data UIOpts = UIOpts {
|
|||||||
watch_ :: Bool
|
watch_ :: Bool
|
||||||
,change_ :: Bool
|
,change_ :: Bool
|
||||||
,cliopts_ :: CliOpts
|
,cliopts_ :: CliOpts
|
||||||
,querystring_ :: String
|
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
defuiopts = UIOpts
|
defuiopts = UIOpts
|
||||||
def
|
{ watch_ = False
|
||||||
def
|
, change_ = False
|
||||||
def
|
, cliopts_ = def
|
||||||
""
|
}
|
||||||
|
|
||||||
-- instance Default CliOpts where def = defcliopts
|
-- instance Default CliOpts where def = defcliopts
|
||||||
|
|
||||||
@ -79,7 +78,6 @@ rawOptsToUIOpts rawopts = checkUIOpts <$> do
|
|||||||
watch_ = boolopt "watch" rawopts
|
watch_ = boolopt "watch" rawopts
|
||||||
,change_ = boolopt "change" rawopts
|
,change_ = boolopt "change" rawopts
|
||||||
,cliopts_ = cliopts
|
,cliopts_ = cliopts
|
||||||
,querystring_ = unwords . map quoteIfNeeded $ listofstringopt "args" rawopts
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkUIOpts :: UIOpts -> UIOpts
|
checkUIOpts :: UIOpts -> UIOpts
|
||||||
|
|||||||
@ -240,8 +240,9 @@ resetReportPeriod = setReportPeriod PeriodAll
|
|||||||
-- | Apply a new filter query.
|
-- | Apply a new filter query.
|
||||||
setFilter :: String -> UIState -> UIState
|
setFilter :: String -> UIState -> UIState
|
||||||
setFilter s ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}} =
|
setFilter s ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}} =
|
||||||
ui{aopts=uopts{cliopts_=copts{reportopts_=ropts{query_=q}},querystring_=s}}
|
ui{aopts=uopts{cliopts_=copts{reportopts_=newRopts}}}
|
||||||
where q = either (const None) fst . parseQuery undefined $ T.pack s
|
where
|
||||||
|
newRopts = either (const ropts) id $ regenerateReportOpts (today_ ropts) (T.pack s) ropts
|
||||||
|
|
||||||
-- | Reset some filters & toggles.
|
-- | Reset some filters & toggles.
|
||||||
resetFilter :: UIState -> UIState
|
resetFilter :: UIState -> UIState
|
||||||
@ -307,7 +308,7 @@ showMinibuffer :: UIState -> UIState
|
|||||||
showMinibuffer ui = setMode (Minibuffer e) ui
|
showMinibuffer ui = setMode (Minibuffer e) ui
|
||||||
where
|
where
|
||||||
e = applyEdit gotoEOL $ editor MinibufferEditor (Just 1) oldq
|
e = applyEdit gotoEOL $ editor MinibufferEditor (Just 1) oldq
|
||||||
oldq = querystring_ $ aopts ui
|
oldq = T.unpack . querystring_ . reportopts_ . cliopts_ $ aopts ui
|
||||||
|
|
||||||
-- | Close the minibuffer, discarding any edit in progress.
|
-- | Close the minibuffer, discarding any edit in progress.
|
||||||
closeMinibuffer :: UIState -> UIState
|
closeMinibuffer :: UIState -> UIState
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user