;ui: refactor toggleForecast
This commit is contained in:
parent
a10f9f4ea9
commit
481c40ca2f
@ -163,28 +163,25 @@ toggleHistorical ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportspec
|
||||
b | balancetype_ ropts == HistoricalBalance = PeriodChange
|
||||
| otherwise = HistoricalBalance
|
||||
|
||||
-- | Toggle hledger-ui's "forecast mode". In forecast mode, periodic
|
||||
-- transactions (generated by periodic rules) are enabled (as with
|
||||
-- hledger --forecast), and also future transactions in general
|
||||
-- (including non-periodic ones) are displayed. In normal mode, all
|
||||
-- future transactions (periodic or not) are suppressed (unlike
|
||||
-- command-line hledger).
|
||||
--
|
||||
-- After toggling this, we do a full reload of the journal from disk
|
||||
-- to make it take effect; currently that's done in the callers (cf
|
||||
-- AccountsScreen, RegisterScreen) where it's easier. This is
|
||||
-- overkill, probably we should just hide/show the periodic
|
||||
-- transactions with a query for their special tag.
|
||||
--
|
||||
-- | Toggle hledger-ui's "forecast/future mode". When this mode is enabled,
|
||||
-- hledger-shows regular transactions which have future dates, and
|
||||
-- "forecast" transactions generated by periodic transaction rules
|
||||
-- (which are usually but not necessarily future-dated).
|
||||
-- In normal mode, both of these are hidden.
|
||||
toggleForecast :: Day -> UIState -> UIState
|
||||
toggleForecast d ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec@ReportSpec{rsOpts=ropts}}}} =
|
||||
ui{aopts=uopts{cliopts_=copts'}}
|
||||
where
|
||||
copts' = copts{reportspec_=rspec{rsOpts=ropts{forecast_=forecast'}}}
|
||||
forecast' =
|
||||
case forecast_ ropts of
|
||||
Just _ -> Nothing
|
||||
Nothing -> Just $ fromMaybe nulldatespan $ forecastPeriodFromRawOpts d $ rawopts_ copts
|
||||
toggleForecast d ui@UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportspec_=ReportSpec{rsOpts=ropts}}}} =
|
||||
uiSetForecast ui $
|
||||
case forecast_ ropts of
|
||||
Just _ -> Nothing
|
||||
Nothing -> Just $ fromMaybe nulldatespan $ forecastPeriodFromRawOpts d $ rawopts_ copts
|
||||
|
||||
-- | Helper: set forecast mode (with the given forecast period) on or off in the UI state.
|
||||
uiSetForecast :: UIState -> Maybe DateSpan -> UIState
|
||||
uiSetForecast
|
||||
ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec@ReportSpec{rsOpts=ropts}}}}
|
||||
mforecast =
|
||||
-- we assume forecast mode has no effect on ReportSpec's derived fields
|
||||
ui{aopts=uopts{cliopts_=copts{reportspec_=rspec{rsOpts=ropts{forecast_=mforecast}}}}}
|
||||
|
||||
-- | Toggle between showing all and showing only real (non-virtual) items.
|
||||
toggleReal :: UIState -> UIState
|
||||
|
||||
Loading…
Reference in New Issue
Block a user