lib: Minor refactor.

This commit is contained in:
Stephen Morgan 2020-07-02 13:47:59 +10:00 committed by Simon Michael
parent 765fb732c9
commit c96947284e
2 changed files with 14 additions and 21 deletions

View File

@ -509,8 +509,7 @@ latestMaybeDate' = maximumByDef Nothing compareNothingMax
-- | The depth limit this query specifies, or a large number if none.
queryDepth :: Query -> Int
queryDepth q = case queryDepth' q of [] -> 99999
ds -> minimum ds
queryDepth = minimumDef maxBound . queryDepth'
where
queryDepth' (Depth d) = [d]
queryDepth' (Or qs) = concatMap queryDepth' qs

View File

@ -442,33 +442,27 @@ journalSelectingAmountFromOpts opts =
-- | Convert report options and arguments to a query.
queryFromOpts :: Day -> ReportOpts -> Query
queryFromOpts d ReportOpts{..} = simplifyQuery $ And $ [flagsq, argsq]
queryFromOpts d ropts = simplifyQuery . And $ [flagsq, argsq]
where
flagsq = And $
[(if date2_ then Date2 else Date) $ periodAsDateSpan period_]
++ (if real_ then [Real True] else [])
++ (if empty_ then [Empty True] else []) -- ?
++ [Or $ map StatusQ statuses_]
++ (maybe [] ((:[]) . Depth) depth_)
argsq = fst $ parseQuery d (T.pack query_)
flagsq = queryFromOptsOnly d ropts
argsq = fst $ parseQuery d (T.pack $ query_ ropts)
-- | Convert report options to a query, ignoring any non-flag command line arguments.
queryFromOptsOnly :: Day -> ReportOpts -> Query
queryFromOptsOnly _d ReportOpts{..} = simplifyQuery flagsq
queryFromOptsOnly _d ReportOpts{..} = simplifyQuery $ And flagsq
where
flagsq = And $
[(if date2_ then Date2 else Date) $ periodAsDateSpan period_]
++ (if real_ then [Real True] else [])
++ (if empty_ then [Empty True] else []) -- ?
++ [Or $ map StatusQ statuses_]
++ (maybe [] ((:[]) . Depth) depth_)
flagsq = consIf Real real_
. consIf Empty empty_
. consJust Depth depth_
$ [ (if date2_ then Date2 else Date) $ periodAsDateSpan period_
, Or $ map StatusQ statuses_
]
consIf f b = if b then (f True:) else id
consJust f = maybe id ((:) . f)
-- | Convert report options and arguments to query options.
queryOptsFromOpts :: Day -> ReportOpts -> [QueryOpt]
queryOptsFromOpts d ReportOpts{..} = flagsqopts ++ argsqopts
where
flagsqopts = []
argsqopts = snd $ parseQuery d (T.pack query_)
queryOptsFromOpts d = snd . parseQuery d . T.pack . query_
-- Report dates.