ui: simpler forecast toggle: just visibility, no reload (#1193)
This commit is contained in:
		
							parent
							
								
									4eba930a5c
								
							
						
					
					
						commit
						3bee9a96c9
					
				| @ -83,12 +83,14 @@ asInit d reset ui@UIState{ | |||||||
|     uopts' = uopts{cliopts_=copts{reportopts_=ropts'}} |     uopts' = uopts{cliopts_=copts{reportopts_=ropts'}} | ||||||
|     ropts' = ropts{accountlistmode_=if tree_ ropts then ALTree else ALFlat} |     ropts' = ropts{accountlistmode_=if tree_ ropts then ALTree else ALFlat} | ||||||
| 
 | 
 | ||||||
|     q = And [queryFromOpts d ropts |     q = And [queryFromOpts d ropts, excludeforecastq (forecast_ ropts)] | ||||||
|             -- Exclude future transactions except in forecast mode |       where | ||||||
|             -- XXX this necessitates special handling in multiBalanceReport, at least |         -- Except in forecast mode, exclude future/forecast transactions. | ||||||
|             ,if forecast_ ropts |         excludeforecastq True = Any | ||||||
|              then Any |         excludeforecastq False =  -- not:date:tomorrow- not:tag:generated-transaction | ||||||
|              else Date $ DateSpan Nothing (Just $ addDays 1 d) |           And [ | ||||||
|  |              Not (Date $ DateSpan (Just $ addDays 1 d) Nothing) | ||||||
|  |             ,Not (Tag "generated-transaction" Nothing) | ||||||
|           ] |           ] | ||||||
| 
 | 
 | ||||||
|     -- run the report |     -- run the report | ||||||
| @ -337,9 +339,7 @@ asHandle ui0@UIState{ | |||||||
|         VtyEvent (EvKey (KChar 'U') []) -> asCenterAndContinue $ regenerateScreens j d $ toggleUnmarked ui |         VtyEvent (EvKey (KChar 'U') []) -> asCenterAndContinue $ regenerateScreens j d $ toggleUnmarked ui | ||||||
|         VtyEvent (EvKey (KChar 'P') []) -> asCenterAndContinue $ regenerateScreens j d $ togglePending ui |         VtyEvent (EvKey (KChar 'P') []) -> asCenterAndContinue $ regenerateScreens j d $ togglePending ui | ||||||
|         VtyEvent (EvKey (KChar 'C') []) -> asCenterAndContinue $ regenerateScreens j d $ toggleCleared ui |         VtyEvent (EvKey (KChar 'C') []) -> asCenterAndContinue $ regenerateScreens j d $ toggleCleared ui | ||||||
|         VtyEvent (EvKey (KChar 'F') []) -> |         VtyEvent (EvKey (KChar 'F') []) -> continue $ regenerateScreens j d $ toggleForecast ui | ||||||
|           let ui'@UIState{aopts=UIOpts{cliopts_=copts'}} = toggleForecast ui |  | ||||||
|           in liftIO (uiReloadJournal copts' d ui') >>= continue |  | ||||||
| 
 | 
 | ||||||
|         VtyEvent (EvKey (KDown)     [MShift]) -> continue $ regenerateScreens j d $ shrinkReportPeriod d ui |         VtyEvent (EvKey (KDown)     [MShift]) -> continue $ regenerateScreens j d $ shrinkReportPeriod d ui | ||||||
|         VtyEvent (EvKey (KUp)       [MShift]) -> continue $ regenerateScreens j d $ growReportPeriod d ui |         VtyEvent (EvKey (KUp)       [MShift]) -> continue $ regenerateScreens j d $ growReportPeriod d ui | ||||||
|  | |||||||
| @ -62,15 +62,18 @@ writeChan = BC.writeBChan | |||||||
| 
 | 
 | ||||||
| main :: IO () | main :: IO () | ||||||
| main = do | main = do | ||||||
|   opts <- getHledgerUIOpts |   opts@UIOpts{cliopts_=copts@CliOpts{inputopts_=_iopts,reportopts_=ropts,rawopts_=rawopts}} <- getHledgerUIOpts | ||||||
|   -- when (debug_ $ cliopts_ opts) $ printf "%s\n" prognameandversion >> printf "opts: %s\n" (show opts) |   -- when (debug_ $ cliopts_ opts) $ printf "%s\n" prognameandversion >> printf "opts: %s\n" (show opts) | ||||||
|   run opts | 
 | ||||||
|     where |   -- always include forecasted periodic transactions when loading data; | ||||||
|       run opts |   -- they will be toggled on and off in the UI. | ||||||
|         | "help"            `inRawOpts` (rawopts_ $ cliopts_ opts) = putStr (showModeUsage uimode) >> exitSuccess |   let copts' = copts{reportopts_=ropts{forecast_=True}} | ||||||
|         | "version"         `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn prognameandversion >> exitSuccess | 
 | ||||||
|         | "binary-filename" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn (binaryfilename progname) |   case True of | ||||||
|         | otherwise                                                = withJournalDo (cliopts_ opts) (runBrickUi opts) |     _ | "help"            `inRawOpts` rawopts -> putStr (showModeUsage uimode) >> exitSuccess | ||||||
|  |     _ | "version"         `inRawOpts` rawopts -> putStrLn prognameandversion >> exitSuccess | ||||||
|  |     _ | "binary-filename" `inRawOpts` rawopts -> putStrLn (binaryfilename progname) | ||||||
|  |     _                                         -> withJournalDo copts' (runBrickUi opts) | ||||||
| 
 | 
 | ||||||
| runBrickUi :: UIOpts -> Journal -> IO () | runBrickUi :: UIOpts -> Journal -> IO () | ||||||
| runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{inputopts_=_iopts,reportopts_=ropts}} j = do | runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{inputopts_=_iopts,reportopts_=ropts}} j = do | ||||||
|  | |||||||
| @ -69,14 +69,15 @@ rsInit d reset ui@UIState{aopts=_uopts@UIOpts{cliopts_=CliOpts{reportopts_=ropts | |||||||
|     ropts' = ropts{ |     ropts' = ropts{ | ||||||
|                depth_=Nothing |                depth_=Nothing | ||||||
|               } |               } | ||||||
|     q = And [queryFromOpts d ropts' |     q = And [queryFromOpts d ropts, excludeforecastq (forecast_ ropts)] | ||||||
|             -- Exclude future transactions except in forecast mode |       where | ||||||
|             -- XXX this necessitates special handling in multiBalanceReport, at least |         -- Except in forecast mode, exclude future/forecast transactions. | ||||||
|             ,if forecast_ ropts |         excludeforecastq True = Any | ||||||
|              then Any |         excludeforecastq False =  -- not:date:tomorrow- not:tag:generated-transaction | ||||||
|              else Date $ DateSpan Nothing (Just $ addDays 1 d) |           And [ | ||||||
|  |              Not (Date $ DateSpan (Just $ addDays 1 d) Nothing) | ||||||
|  |             ,Not (Tag "generated-transaction" Nothing) | ||||||
|           ] |           ] | ||||||
| --    reportq = filterQuery (not . queryIsDepth) q |  | ||||||
| 
 | 
 | ||||||
|     (_label,items) = accountTransactionsReport ropts' j q thisacctq |     (_label,items) = accountTransactionsReport ropts' j q thisacctq | ||||||
|     items' = (if empty_ ropts' then id else filter (not . isZeroMixedAmount . fifth6)) $  -- without --empty, exclude no-change txns |     items' = (if empty_ ropts' then id else filter (not . isZeroMixedAmount . fifth6)) $  -- without --empty, exclude no-change txns | ||||||
| @ -335,9 +336,7 @@ rsHandle ui@UIState{ | |||||||
|         VtyEvent (EvKey (KChar 'U') []) -> rsCenterAndContinue $ regenerateScreens j d $ toggleUnmarked ui |         VtyEvent (EvKey (KChar 'U') []) -> rsCenterAndContinue $ regenerateScreens j d $ toggleUnmarked ui | ||||||
|         VtyEvent (EvKey (KChar 'P') []) -> rsCenterAndContinue $ regenerateScreens j d $ togglePending ui |         VtyEvent (EvKey (KChar 'P') []) -> rsCenterAndContinue $ regenerateScreens j d $ togglePending ui | ||||||
|         VtyEvent (EvKey (KChar 'C') []) -> rsCenterAndContinue $ regenerateScreens j d $ toggleCleared ui |         VtyEvent (EvKey (KChar 'C') []) -> rsCenterAndContinue $ regenerateScreens j d $ toggleCleared ui | ||||||
|         VtyEvent (EvKey (KChar 'F') []) -> |         VtyEvent (EvKey (KChar 'F') []) -> rsCenterAndContinue $ regenerateScreens j d $ toggleForecast ui | ||||||
|           let ui'@UIState{aopts=UIOpts{cliopts_=copts'}} = toggleForecast ui |  | ||||||
|           in liftIO (uiReloadJournal copts' d ui') >>= rsCenterAndContinue |  | ||||||
| 
 | 
 | ||||||
|         VtyEvent (EvKey (KChar '/') []) -> continue $ regenerateScreens j d $ showMinibuffer ui |         VtyEvent (EvKey (KChar '/') []) -> continue $ regenerateScreens j d $ showMinibuffer ui | ||||||
|         VtyEvent (EvKey (KDown)     [MShift]) -> continue $ regenerateScreens j d $ shrinkReportPeriod d ui |         VtyEvent (EvKey (KDown)     [MShift]) -> continue $ regenerateScreens j d $ shrinkReportPeriod d ui | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user