ui: refactor draw functions

This commit is contained in:
Simon Michael 2016-08-02 07:09:08 -07:00
parent 06a567fe0a
commit 0cb5703ad1
4 changed files with 138 additions and 130 deletions

View File

@ -110,42 +110,6 @@ asDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
-- Minibuffer e -> [minibuffer e, maincontent]
_ -> [maincontent]
where
toplabel =
files
<+> nonzero
<+> str " accounts"
<+> withAttr (borderAttr <> "query") (str (if flat_ ropts then " (flat)" else ""))
<+> borderQueryStr querystr
<+> togglefilters
<+> borderDepthStr mdepth
<+> str " ("
<+> cur
<+> str "/"
<+> total
<+> str ")"
<+> (if ignore_assertions_ copts
then withAttr (borderAttr <> "query") (str " ignoring balance assertions")
else str "")
files = case journalFilePaths j of
[] -> str ""
f:_ -> withAttr ("border" <> "bold") $ str $ takeFileName f
-- [f,_:[]] -> (withAttr ("border" <> "bold") $ str $ takeFileName f) <+> str " (& 1 included file)"
-- f:fs -> (withAttr ("border" <> "bold") $ str $ takeFileName f) <+> str (" (& " ++ show (length fs) ++ " included files)")
querystr = query_ ropts
mdepth = depth_ ropts
togglefilters =
case concat [
uiShowClearedStatus $ clearedstatus_ ropts
,if real_ ropts then ["real"] else []
] of
[] -> str ""
fs -> str " with " <+> withAttr (borderAttr <> "query") (str $ intercalate ", " fs) <+> str " txns"
nonzero | empty_ ropts = str ""
| otherwise = withAttr (borderAttr <> "query") (str " nonzero")
cur = str (case _asList s ^. listSelectedL of
Nothing -> "-"
Just i -> show (i + 1))
total = str $ show $ V.length $ s ^. asList . listElementsL
maincontent = Widget Greedy Greedy $ do
c <- getContext
let
@ -184,9 +148,48 @@ asDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
render $ defaultLayout toplabel bottomlabel $ renderList (asDrawItem colwidths) True (_asList s)
where
toplabel =
files
<+> nonzero
<+> str " accounts"
<+> withAttr (borderAttr <> "query") (str (if flat_ ropts then " (flat)" else ""))
<+> borderQueryStr querystr
<+> togglefilters
<+> borderDepthStr mdepth
<+> str " ("
<+> cur
<+> str "/"
<+> total
<+> str ")"
<+> (if ignore_assertions_ copts
then withAttr (borderAttr <> "query") (str " ignoring balance assertions")
else str "")
where
files = case journalFilePaths j of
[] -> str ""
f:_ -> withAttr ("border" <> "bold") $ str $ takeFileName f
-- [f,_:[]] -> (withAttr ("border" <> "bold") $ str $ takeFileName f) <+> str " (& 1 included file)"
-- f:fs -> (withAttr ("border" <> "bold") $ str $ takeFileName f) <+> str (" (& " ++ show (length fs) ++ " included files)")
querystr = query_ ropts
mdepth = depth_ ropts
togglefilters =
case concat [
uiShowClearedStatus $ clearedstatus_ ropts
,if real_ ropts then ["real"] else []
] of
[] -> str ""
fs -> str " with " <+> withAttr (borderAttr <> "query") (str $ intercalate ", " fs) <+> str " txns"
nonzero | empty_ ropts = str ""
| otherwise = withAttr (borderAttr <> "query") (str " nonzero")
cur = str (case _asList s ^. listSelectedL of
Nothing -> "-"
Just i -> show (i + 1))
total = str $ show $ V.length $ s ^. asList . listElementsL
bottomlabel = case mode of
Minibuffer ed -> minibuffer ed
_ -> quickhelp
where
quickhelp = borderKeysStr [
("?", "help")
,("right", "register")

View File

@ -46,17 +46,18 @@ esDraw UIState{ --aopts=UIOpts{cliopts_=copts@CliOpts{}}
Help -> [helpDialog, maincontent]
-- Minibuffer e -> [minibuffer e, maincontent]
_ -> [maincontent]
where
maincontent = Widget Greedy Greedy $ do
render $ defaultLayout toplabel bottomlabel $ withAttr "error" $ str $ esError
where
toplabel =
withAttr ("border" <> "bold") (str "Oops. Please fix this problem then press g to reload")
-- <+> (if ignore_assertions_ copts then withAttr (borderAttr <> "query") (str " ignoring") else str " not ignoring")
maincontent = Widget Greedy Greedy $ do
render $ defaultLayout toplabel bottomlabel $ withAttr "error" $ str $ esError
where
bottomlabel = case mode of
-- Minibuffer ed -> minibuffer ed
_ -> quickhelp
where
quickhelp = borderKeysStr [
("h", "help")
,("ESC", "cancel/top")

View File

@ -113,36 +113,7 @@ rsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
-- Minibuffer e -> [minibuffer e, maincontent]
_ -> [maincontent]
where
inclusive = not (flat_ ropts) || rsForceInclusive
toplabel =
withAttr ("border" <> "bold") (str $ T.unpack $ replaceHiddenAccountsNameWith "All" rsAccount)
<+> withAttr (borderAttr <> "query") (str $ if inclusive then "" else " (exclusive)")
<+> togglefilters
<+> str " transactions"
<+> borderQueryStr (query_ ropts)
-- <+> str " and subs"
<+> str " ("
<+> cur
<+> str "/"
<+> total
<+> str ")"
<+> (if ignore_assertions_ copts then withAttr (borderAttr <> "query") (str " ignoring balance assertions") else str "")
togglefilters =
case concat [
uiShowClearedStatus $ clearedstatus_ ropts
,if real_ ropts then ["real"] else []
,if empty_ ropts then [] else ["nonzero"]
] of
[] -> str ""
fs -> withAttr (borderAttr <> "query") (str $ " " ++ intercalate ", " fs)
cur = str $ case rsList ^. listSelectedL of
Nothing -> "-"
Just i -> show (i + 1)
total = str $ show $ length displayitems
displayitems = V.toList $ rsList ^. listElementsL
-- query = query_ $ reportopts_ $ cliopts_ opts
maincontent = Widget Greedy Greedy $ do
-- calculate column widths, based on current available width
c <- getContext
@ -187,9 +158,40 @@ rsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
render $ defaultLayout toplabel bottomlabel $ renderList (rsDrawItem colwidths) True rsList
where
toplabel =
withAttr ("border" <> "bold") (str $ T.unpack $ replaceHiddenAccountsNameWith "All" rsAccount)
<+> withAttr (borderAttr <> "query") (str $ if inclusive then "" else " (exclusive)")
<+> togglefilters
<+> str " transactions"
<+> borderQueryStr (query_ ropts)
-- <+> str " and subs"
<+> str " ("
<+> cur
<+> str "/"
<+> total
<+> str ")"
<+> (if ignore_assertions_ copts then withAttr (borderAttr <> "query") (str " ignoring balance assertions") else str "")
where
inclusive = not (flat_ ropts) || rsForceInclusive
togglefilters =
case concat [
uiShowClearedStatus $ clearedstatus_ ropts
,if real_ ropts then ["real"] else []
,if empty_ ropts then [] else ["nonzero"]
] of
[] -> str ""
fs -> withAttr (borderAttr <> "query") (str $ " " ++ intercalate ", " fs)
cur = str $ case rsList ^. listSelectedL of
Nothing -> "-"
Just i -> show (i + 1)
total = str $ show $ length displayitems
-- query = query_ $ reportopts_ $ cliopts_ opts
bottomlabel = case mode of
Minibuffer ed -> minibuffer ed
_ -> quickhelp
where
quickhelp = borderKeysStr [
("?", "help")
,("left", "back")

View File

@ -57,7 +57,12 @@ tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
-- Minibuffer e -> [minibuffer e, maincontent]
_ -> [maincontent]
where
-- datedesc = show (tdate t) ++ " " ++ tdescription t
maincontent = Widget Greedy Greedy $ do
render $ defaultLayout toplabel bottomlabel $ str $
showTransactionUnelidedOneLineAmounts $
-- (if real_ ropts then filterTransactionPostings (Real True) else id) -- filter postings by --real
t
where
toplabel =
str "Transaction "
-- <+> withAttr ("border" <> "bold") (str $ "#" ++ show (tindex t))
@ -70,6 +75,7 @@ tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
<+> borderQueryStr (query_ ropts)
<+> str (" in "++T.unpack (replaceHiddenAccountsNameWith "All" acct)++")")
<+> (if ignore_assertions_ copts then withAttr (borderAttr <> "query") (str " ignoring balance assertions") else str "")
where
togglefilters =
case concat [
uiShowClearedStatus $ clearedstatus_ ropts
@ -78,15 +84,11 @@ tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
] of
[] -> str ""
fs -> withAttr (borderAttr <> "query") (str $ " " ++ intercalate ", " fs)
maincontent = Widget Greedy Greedy $ do
render $ defaultLayout toplabel bottomlabel $ str $
showTransactionUnelidedOneLineAmounts $
-- (if real_ ropts then filterTransactionPostings (Real True) else id) -- filter postings by --real
t
where
bottomlabel = case mode of
-- Minibuffer ed -> minibuffer ed
_ -> quickhelp
where
quickhelp = borderKeysStr [
("?", "help")
,("left", "back")