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(..), | ||||
|   defreportopts, | ||||
|   rawOptsToReportOpts, | ||||
|   regenerateReportOpts, | ||||
|   flat_, | ||||
|   tree_, | ||||
|   reportOptsToggleStatus, | ||||
| @ -96,6 +97,7 @@ data ReportOpts = ReportOpts { | ||||
|     ,format_         :: StringFormat | ||||
|     ,query_          :: Query | ||||
|     ,queryopts_      :: [QueryOpt] | ||||
|     ,querystring_    :: T.Text | ||||
|     -- | ||||
|     ,average_        :: Bool | ||||
|     -- for posting reports (register) | ||||
| @ -133,36 +135,38 @@ instance Default ReportOpts where def = defreportopts | ||||
| 
 | ||||
| defreportopts :: ReportOpts | ||||
| defreportopts = ReportOpts | ||||
|     nulldate | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     { today_           = nulldate | ||||
|     , period_          = PeriodAll | ||||
|     , interval_        = NoInterval | ||||
|     , statuses_        = [] | ||||
|     , value_           = Nothing | ||||
|     , infer_value_     = False | ||||
|     , depth_           = Nothing | ||||
|     , date2_           = False | ||||
|     , empty_           = False | ||||
|     , no_elide_        = False | ||||
|     , real_            = False | ||||
|     , format_          = def | ||||
|     , query_           = Any | ||||
|     , queryopts_       = [] | ||||
|     , querystring_     = "" | ||||
|     , average_         = False | ||||
|     , related_         = False | ||||
|     , txn_dates_       = False | ||||
|     , balancetype_     = def | ||||
|     , accountlistmode_ = ALFlat | ||||
|     , drop_            = 0 | ||||
|     , row_total_       = False | ||||
|     , no_total_        = False | ||||
|     , pretty_tables_   = False | ||||
|     , sort_amount_     = False | ||||
|     , percent_         = False | ||||
|     , invert_          = False | ||||
|     , normalbalance_   = Nothing | ||||
|     , color_           = False | ||||
|     , forecast_        = Nothing | ||||
|     , transpose_       = False | ||||
|     } | ||||
| 
 | ||||
| rawOptsToReportOpts :: RawOpts -> IO ReportOpts | ||||
| rawOptsToReportOpts rawopts = do | ||||
| @ -197,6 +201,7 @@ rawOptsToReportOpts rawopts = do | ||||
|           ,format_      = format | ||||
|           ,query_       = simplifyQuery $ And [queryFromFlags reportopts, argsquery] | ||||
|           ,queryopts_   = queryopts | ||||
|           ,querystring_ = querystring | ||||
|           ,average_     = boolopt "average" rawopts | ||||
|           ,related_     = boolopt "related" rawopts | ||||
|           ,txn_dates_   = boolopt "txn-dates" rawopts | ||||
| @ -216,9 +221,14 @@ rawOptsToReportOpts rawopts = do | ||||
|           ,forecast_    = forecastPeriodFromRawOpts d rawopts | ||||
|           ,transpose_   = boolopt "transpose" rawopts | ||||
|           } | ||||
| 
 | ||||
|     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 = | ||||
|   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: | ||||
| 
 | ||||
| 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 | ||||
|               ,aScreen=s@AccountsScreen{} | ||||
|               ,aMode=mode | ||||
| @ -172,7 +172,7 @@ asDraw UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts},que | ||||
|           <+> toggles | ||||
|           <+> str (" account " ++ if ishistorical then "balances" else "changes") | ||||
|           <+> borderPeriodStr (if ishistorical then "at end of" else "in") (period_ ropts) | ||||
|           <+> borderQueryStr query | ||||
|           <+> borderQueryStr (T.unpack $ querystring_ ropts) | ||||
|           <+> borderDepthStr mdepth | ||||
|           <+> str (" ("++curidx++"/"++totidx++")") | ||||
|           <+> (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: | ||||
| 
 | ||||
| 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{..} | ||||
|               ,aMode=mode | ||||
|               } = | ||||
| @ -201,7 +201,7 @@ rsDraw UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts},que | ||||
|           <+> togglefilters | ||||
|           <+> str " transactions" | ||||
|           -- <+> str (if ishistorical then " historical total" else " period total") | ||||
|           <+> borderQueryStr query | ||||
|           <+> borderQueryStr (T.unpack $ querystring_ ropts) | ||||
|           -- <+> str " and subs" | ||||
|           <+> borderPeriodStr "in" (period_ ropts) | ||||
|           <+> 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: | ||||
| 
 | ||||
| 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 | ||||
|               ,aScreen=TransactionScreen{tsTransaction=(i,t) | ||||
|                                         ,tsTransactions=nts | ||||
| @ -97,7 +97,7 @@ tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts},querystrin | ||||
|           <+> withAttr ("border" <> "bold") (str $ show i) | ||||
|           <+> str (" of "++show (length nts)) | ||||
|           <+> togglefilters | ||||
|           <+> borderQueryStr query | ||||
|           <+> borderQueryStr (T.unpack $ querystring_ ropts) | ||||
|           <+> str (" in "++T.unpack (replaceHiddenAccountsNameWith "All" acct)++")") | ||||
|           <+> (if ignore_assertions_ $ inputopts_ copts then withAttr ("border" <> "query") (str " ignoring balance assertions") else str "") | ||||
|           where | ||||
|  | ||||
| @ -61,14 +61,13 @@ data UIOpts = UIOpts { | ||||
|      watch_       :: Bool | ||||
|     ,change_      :: Bool | ||||
|     ,cliopts_     :: CliOpts | ||||
|     ,querystring_ :: String | ||||
|  } deriving (Show) | ||||
| 
 | ||||
| defuiopts = UIOpts | ||||
|     def | ||||
|     def | ||||
|     def | ||||
|     "" | ||||
|   { watch_   = False | ||||
|   , change_  = False | ||||
|   , cliopts_ = def | ||||
|   } | ||||
| 
 | ||||
| -- instance Default CliOpts where def = defcliopts | ||||
| 
 | ||||
| @ -79,7 +78,6 @@ rawOptsToUIOpts rawopts = checkUIOpts <$> do | ||||
|               watch_       = boolopt "watch" rawopts | ||||
|              ,change_      = boolopt "change" rawopts | ||||
|              ,cliopts_     = cliopts | ||||
|              ,querystring_ = unwords . map quoteIfNeeded $ listofstringopt "args" rawopts | ||||
|              } | ||||
| 
 | ||||
| checkUIOpts :: UIOpts -> UIOpts | ||||
|  | ||||
| @ -240,8 +240,9 @@ resetReportPeriod = setReportPeriod PeriodAll | ||||
| -- | Apply a new filter query. | ||||
| setFilter :: String -> UIState -> UIState | ||||
| setFilter s ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}} = | ||||
|     ui{aopts=uopts{cliopts_=copts{reportopts_=ropts{query_=q}},querystring_=s}} | ||||
|   where q = either (const None) fst . parseQuery undefined $ T.pack s | ||||
|     ui{aopts=uopts{cliopts_=copts{reportopts_=newRopts}}} | ||||
|   where | ||||
|     newRopts = either (const ropts) id $ regenerateReportOpts (today_ ropts) (T.pack s) ropts | ||||
| 
 | ||||
| -- | Reset some filters & toggles. | ||||
| resetFilter :: UIState -> UIState | ||||
| @ -307,7 +308,7 @@ showMinibuffer :: UIState -> UIState | ||||
| showMinibuffer ui = setMode (Minibuffer e) ui | ||||
|   where | ||||
|     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. | ||||
| closeMinibuffer :: UIState -> UIState | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user