;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
|
b | balancetype_ ropts == HistoricalBalance = PeriodChange
|
||||||
| otherwise = HistoricalBalance
|
| otherwise = HistoricalBalance
|
||||||
|
|
||||||
-- | Toggle hledger-ui's "forecast mode". In forecast mode, periodic
|
-- | Toggle hledger-ui's "forecast/future mode". When this mode is enabled,
|
||||||
-- transactions (generated by periodic rules) are enabled (as with
|
-- hledger-shows regular transactions which have future dates, and
|
||||||
-- hledger --forecast), and also future transactions in general
|
-- "forecast" transactions generated by periodic transaction rules
|
||||||
-- (including non-periodic ones) are displayed. In normal mode, all
|
-- (which are usually but not necessarily future-dated).
|
||||||
-- future transactions (periodic or not) are suppressed (unlike
|
-- In normal mode, both of these are hidden.
|
||||||
-- 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.
|
|
||||||
--
|
|
||||||
toggleForecast :: Day -> UIState -> UIState
|
toggleForecast :: Day -> UIState -> UIState
|
||||||
toggleForecast d ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec@ReportSpec{rsOpts=ropts}}}} =
|
toggleForecast d ui@UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportspec_=ReportSpec{rsOpts=ropts}}}} =
|
||||||
ui{aopts=uopts{cliopts_=copts'}}
|
uiSetForecast ui $
|
||||||
where
|
case forecast_ ropts of
|
||||||
copts' = copts{reportspec_=rspec{rsOpts=ropts{forecast_=forecast'}}}
|
Just _ -> Nothing
|
||||||
forecast' =
|
Nothing -> Just $ fromMaybe nulldatespan $ forecastPeriodFromRawOpts d $ rawopts_ copts
|
||||||
case forecast_ ropts of
|
|
||||||
Just _ -> Nothing
|
-- | Helper: set forecast mode (with the given forecast period) on or off in the UI state.
|
||||||
Nothing -> Just $ fromMaybe nulldatespan $ forecastPeriodFromRawOpts d $ rawopts_ copts
|
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.
|
-- | Toggle between showing all and showing only real (non-virtual) items.
|
||||||
toggleReal :: UIState -> UIState
|
toggleReal :: UIState -> UIState
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user