ui: display depth and other filters independently
As the comment says:
In hledger,
- reportopts{depth_} indicates --depth options
- reportopts{query_} is the query arguments as a string
- the report query is based on both of these.
For hledger-ui, currently, we move depth: arguments out of reportopts{query_}
and into reportopts{depth_}, so that depth and other kinds of filter query
can be displayed (and controlled) independently.
			
			
This commit is contained in:
		
							parent
							
								
									5fa06453f1
								
							
						
					
					
						commit
						cc0c981d29
					
				@ -40,40 +40,62 @@ screen = AccountsScreen{
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
initAccountsScreen :: Maybe AccountName -> Day -> AppState -> AppState
 | 
					initAccountsScreen :: Maybe AccountName -> Day -> AppState -> AppState
 | 
				
			||||||
initAccountsScreen mselacct d st@AppState{aopts=opts, ajournal=j, aScreen=s@AccountsScreen{}} =
 | 
					initAccountsScreen mselacct d st@AppState{
 | 
				
			||||||
  st{aScreen=s{asState=is''}}
 | 
					  aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}},
 | 
				
			||||||
 | 
					  ajournal=j,
 | 
				
			||||||
 | 
					  aScreen=s@AccountsScreen{}
 | 
				
			||||||
 | 
					  } =
 | 
				
			||||||
 | 
					  st{aopts=opts', aScreen=s{asState=l'}}
 | 
				
			||||||
   where
 | 
					   where
 | 
				
			||||||
    is' = list (Name "accounts") (V.fromList items) 1
 | 
					    l = list (Name "accounts") (V.fromList items) 1
 | 
				
			||||||
    -- crazy hacks dept.
 | 
					
 | 
				
			||||||
    -- when we're adjusting depth, mselacct is the account that was selected previously,
 | 
					    -- hacky: when we're adjusting depth, mselacct is the account that was selected previously,
 | 
				
			||||||
    -- in which case try and keep the selection near where it was
 | 
					    -- in which case try and keep the selection near where it was
 | 
				
			||||||
    is'' = case mselacct of
 | 
					    l' = case mselacct of
 | 
				
			||||||
             Nothing -> is'
 | 
					             Nothing -> l
 | 
				
			||||||
             Just a  -> -- vScrollToBeginning $ viewportScroll "accounts"
 | 
					             Just a  -> -- vScrollToBeginning $ viewportScroll "accounts"
 | 
				
			||||||
                           maybe is' (flip listMoveTo is') mi
 | 
					                           maybe l (flip listMoveTo l) mi
 | 
				
			||||||
               where
 | 
					               where
 | 
				
			||||||
                 mi = findIndex (\((acct,_,_),_) -> acct==a') items
 | 
					                 mi = findIndex (\((acct,_,_),_) -> acct==a') items
 | 
				
			||||||
                 a' = maybe a (flip clipAccountName a) $ depth_ ropts
 | 
					                 a' = maybe a (flip clipAccountName a) $ depth_ ropts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    -- XXX messing around with depth, which is different from other queries
 | 
				
			||||||
 | 
					    -- In hledger,
 | 
				
			||||||
 | 
					    -- - reportopts{depth_} indicates --depth options
 | 
				
			||||||
 | 
					    -- - reportopts{query_} is the query arguments as a string
 | 
				
			||||||
 | 
					    -- - the report query is based on both of these.
 | 
				
			||||||
 | 
					    -- For hledger-ui, currently, we move depth: arguments out of reportopts{query_}
 | 
				
			||||||
 | 
					    -- and into reportopts{depth_}, so that depth and other kinds of filter query
 | 
				
			||||||
 | 
					    -- can be displayed independently.
 | 
				
			||||||
 | 
					    opts' = uopts{cliopts_=copts{reportopts_=ropts'}}
 | 
				
			||||||
    q = queryFromOpts d ropts
 | 
					    q = queryFromOpts d ropts
 | 
				
			||||||
         -- query_="cur:\\$"} -- XXX limit to one commodity to ensure one-line items
 | 
					    ropts' = ropts
 | 
				
			||||||
         --{query_=unwords' $ locArgs l}
 | 
					 | 
				
			||||||
    ropts = (reportopts_ cliopts)
 | 
					 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
              balancetype_=HistoricalBalance -- XXX balanceReport doesn't respect this yet
 | 
					              -- ensure depth_ also reflects depth: args
 | 
				
			||||||
 | 
					              depth_=depthfromoptsandargs,
 | 
				
			||||||
 | 
					              -- remove depth: args from query_
 | 
				
			||||||
 | 
					              query_=ltrace "b" $ unwords $ -- as in ReportOptions, with same limitations
 | 
				
			||||||
 | 
					                     [v | (k,v) <- rawopts_ copts, k=="args", not $ "depth" `isPrefixOf` v],
 | 
				
			||||||
 | 
					              -- XXX balanceReport doesn't respect this yet
 | 
				
			||||||
 | 
					              balancetype_=HistoricalBalance
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
    cliopts = cliopts_ opts
 | 
					      where
 | 
				
			||||||
    convert | value_ ropts = balanceReportValue j valuedate
 | 
					        depthfromoptsandargs = case queryDepth q of 99999 -> Nothing
 | 
				
			||||||
 | 
					                                                    d     -> Just d
 | 
				
			||||||
 | 
					    -- maybe convert balances to market value
 | 
				
			||||||
 | 
					    convert | value_ ropts' = balanceReportValue j valuedate
 | 
				
			||||||
            | otherwise    = id
 | 
					            | otherwise    = id
 | 
				
			||||||
      where
 | 
					      where
 | 
				
			||||||
        valuedate = fromMaybe d $ queryEndDate False q
 | 
					        valuedate = fromMaybe d $ queryEndDate False q
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (items,_total) = convert $ balanceReport ropts q j
 | 
					    -- run the report
 | 
				
			||||||
 | 
					    (items,_total) = convert $ balanceReport ropts' q j
 | 
				
			||||||
 | 
					
 | 
				
			||||||
initAccountsScreen _ _ _ = error "init function called with wrong screen type, should not happen"
 | 
					initAccountsScreen _ _ _ = error "init function called with wrong screen type, should not happen"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
drawAccountsScreen :: AppState -> [Widget]
 | 
					drawAccountsScreen :: AppState -> [Widget]
 | 
				
			||||||
drawAccountsScreen st@AppState{aopts=uopts, ajournal=j, aScreen=AccountsScreen{asState=is}} = [ui]
 | 
					drawAccountsScreen st@AppState{aopts=uopts, ajournal=j, aScreen=AccountsScreen{asState=is}} =
 | 
				
			||||||
 | 
					  [ui]
 | 
				
			||||||
    where
 | 
					    where
 | 
				
			||||||
      toplabel = files
 | 
					      toplabel = files
 | 
				
			||||||
              <+> str " accounts"
 | 
					              <+> str " accounts"
 | 
				
			||||||
@ -91,6 +113,9 @@ drawAccountsScreen st@AppState{aopts=uopts, ajournal=j, aScreen=AccountsScreen{a
 | 
				
			|||||||
                     f:fs -> (withAttr ("border" <> "bold") $ str $ takeFileName f) <+> str (" (& " ++ show (length fs) ++ " included files)")
 | 
					                     f:fs -> (withAttr ("border" <> "bold") $ str $ takeFileName f) <+> str (" (& " ++ show (length fs) ++ " included files)")
 | 
				
			||||||
      querystr = query_ $ reportopts_ $ cliopts_ uopts
 | 
					      querystr = query_ $ reportopts_ $ cliopts_ uopts
 | 
				
			||||||
      depth = depth_ $ reportopts_ $ cliopts_ uopts
 | 
					      depth = depth_ $ reportopts_ $ cliopts_ uopts
 | 
				
			||||||
 | 
					      -- ropts = reportopts_ $ cliopts_ uopts
 | 
				
			||||||
 | 
					      -- q = queryFromOpts d ropts
 | 
				
			||||||
 | 
					      -- depth = queryDepth q
 | 
				
			||||||
      cur = str (case is^.listSelectedL of
 | 
					      cur = str (case is^.listSelectedL of
 | 
				
			||||||
                  Nothing -> "-"
 | 
					                  Nothing -> "-"
 | 
				
			||||||
                  Just i -> show (i + 1))
 | 
					                  Just i -> show (i + 1))
 | 
				
			||||||
 | 
				
			|||||||
@ -49,7 +49,7 @@ initRegisterScreen d st@AppState{aopts=opts, ajournal=j, aScreen=s@RegisterScree
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
    -- XXX temp
 | 
					    -- XXX temp
 | 
				
			||||||
    thisacctq = Acct $ accountNameToAccountRegex acct -- includes subs
 | 
					    thisacctq = Acct $ accountNameToAccountRegex acct -- includes subs
 | 
				
			||||||
    q = queryFromOpts d ropts
 | 
					    q = filterQuery (not . queryIsDepth) $ queryFromOpts d ropts
 | 
				
			||||||
         -- query_="cur:\\$"} -- XXX limit to one commodity to ensure one-line items
 | 
					         -- query_="cur:\\$"} -- XXX limit to one commodity to ensure one-line items
 | 
				
			||||||
         --{query_=unwords' $ locArgs l}
 | 
					         --{query_=unwords' $ locArgs l}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,7 @@ import Hledger.UI.Options
 | 
				
			|||||||
-- | hledger-ui's application state. This is part of, but distinct
 | 
					-- | hledger-ui's application state. This is part of, but distinct
 | 
				
			||||||
-- from, brick's App.
 | 
					-- from, brick's App.
 | 
				
			||||||
data AppState = AppState {
 | 
					data AppState = AppState {
 | 
				
			||||||
   aopts :: UIOpts          -- ^ command-line options at startup
 | 
					   aopts :: UIOpts          -- ^ command-line options, query, depth etc. currently in effect.
 | 
				
			||||||
  -- ,aargs :: [String]        -- ^ command-line arguments at startup
 | 
					  -- ,aargs :: [String]        -- ^ command-line arguments at startup
 | 
				
			||||||
  ,ajournal :: Journal      -- ^ the parsed journal
 | 
					  ,ajournal :: Journal      -- ^ the parsed journal
 | 
				
			||||||
  ,aScreen :: Screen        -- ^ the currently active screen
 | 
					  ,aScreen :: Screen        -- ^ the currently active screen
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user