view, vfilter: Add support for filtering tags and values out of a view, using !tag and field!=value.

Note that negated globs are not supported. Would have complicated the code
to add them, without changing the data type serialization in a
non-backwards-compatable way.

This commit was sponsored by Denver Gingerich.
This commit is contained in:
Joey Hess 2014-03-02 14:53:19 -04:00
parent 2432ecbdcc
commit c2e8c21ca6
8 changed files with 82 additions and 40 deletions

View file

@ -38,14 +38,20 @@ instance Arbitrary ViewComponent where
data ViewFilter
= FilterValues (S.Set MetaValue)
| FilterGlob String
| ExcludeValues (S.Set MetaValue)
deriving (Eq, Read, Show)
instance Arbitrary ViewFilter where
arbitrary = do
size <- arbitrarySizedBoundedIntegral `suchThat` (< 100)
FilterValues . S.fromList <$> vector size
s <- S.fromList <$> vector size
ifM arbitrary
( return (FilterValues s)
, return (ExcludeValues s)
)
{- Can a ViewFilter match multiple different MetaValues? -}
multiValue :: ViewFilter -> Bool
multiValue (FilterValues s) = S.size s > 1
multiValue (FilterGlob _) = True
multiValue (ExcludeValues _) = False