2014-02-17 04:18:57 +00:00
|
|
|
{- types for metadata based branch views
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
2014-02-17 04:18:57 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Types.View where
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2014-02-17 04:18:57 +00:00
|
|
|
import Types.MetaData
|
|
|
|
import Utility.QuickCheck
|
2014-02-18 21:38:23 +00:00
|
|
|
import qualified Git
|
2014-02-17 04:18:57 +00:00
|
|
|
|
|
|
|
import qualified Data.Set as S
|
|
|
|
|
2014-02-18 21:38:23 +00:00
|
|
|
{- A view is a list of fields with filters on their allowed values,
|
|
|
|
- which are applied to files in a parent git branch. -}
|
|
|
|
data View = View
|
|
|
|
{ viewParentBranch :: Git.Branch
|
|
|
|
, viewComponents :: [ViewComponent]
|
|
|
|
}
|
2014-02-19 05:09:17 +00:00
|
|
|
deriving (Eq, Read, Show)
|
2014-02-17 04:18:57 +00:00
|
|
|
|
2014-02-18 21:38:23 +00:00
|
|
|
instance Arbitrary View where
|
|
|
|
arbitrary = View <$> pure (Git.Ref "master") <*> arbitrary
|
2014-02-17 04:38:33 +00:00
|
|
|
|
|
|
|
data ViewComponent = ViewComponent
|
|
|
|
{ viewField :: MetaField
|
|
|
|
, viewFilter :: ViewFilter
|
add tip about metadata driven views (and more flexible view filtering)
While writing this documentation, I realized that there needed to be a way
to stay in a view like tag=* while adding a filter like tag=work that
applies to the same field.
So, there are really two ways a view can be refined. It can have a new
"field=explicitvalue" filter added to it, which does not change the
"shape" of the view, but narrows the files it shows.
Or, it can have a new view added, which adds another level of
subdirectories.
So, added a vfilter command, which takes explicit values to add to the
filter, and rejects changes that would change the shape of the view.
And, made vadd only accept changes that change the shape of the view.
And, changed the View data type slightly; now components that can match
multiple metadata values can be visible, or not visible.
This commit was sponsored by Stelian Iancu.
2014-02-19 19:10:18 +00:00
|
|
|
, viewVisible :: Bool
|
2014-02-17 04:38:33 +00:00
|
|
|
}
|
2014-02-19 05:09:17 +00:00
|
|
|
deriving (Eq, Read, Show)
|
2014-02-17 04:38:33 +00:00
|
|
|
|
|
|
|
instance Arbitrary ViewComponent where
|
add tip about metadata driven views (and more flexible view filtering)
While writing this documentation, I realized that there needed to be a way
to stay in a view like tag=* while adding a filter like tag=work that
applies to the same field.
So, there are really two ways a view can be refined. It can have a new
"field=explicitvalue" filter added to it, which does not change the
"shape" of the view, but narrows the files it shows.
Or, it can have a new view added, which adds another level of
subdirectories.
So, added a vfilter command, which takes explicit values to add to the
filter, and rejects changes that would change the shape of the view.
And, made vadd only accept changes that change the shape of the view.
And, changed the View data type slightly; now components that can match
multiple metadata values can be visible, or not visible.
This commit was sponsored by Stelian Iancu.
2014-02-19 19:10:18 +00:00
|
|
|
arbitrary = ViewComponent <$> arbitrary <*> arbitrary <*> arbitrary
|
2014-02-17 04:18:57 +00:00
|
|
|
|
|
|
|
data ViewFilter
|
|
|
|
= FilterValues (S.Set MetaValue)
|
2014-02-18 21:38:23 +00:00
|
|
|
| FilterGlob String
|
2014-03-02 18:53:19 +00:00
|
|
|
| ExcludeValues (S.Set MetaValue)
|
2014-02-19 05:09:17 +00:00
|
|
|
deriving (Eq, Read, Show)
|
2014-02-17 04:18:57 +00:00
|
|
|
|
|
|
|
instance Arbitrary ViewFilter where
|
|
|
|
arbitrary = do
|
|
|
|
size <- arbitrarySizedBoundedIntegral `suchThat` (< 100)
|
2014-03-02 18:53:19 +00:00
|
|
|
s <- S.fromList <$> vector size
|
|
|
|
ifM arbitrary
|
|
|
|
( return (FilterValues s)
|
|
|
|
, return (ExcludeValues s)
|
|
|
|
)
|
2014-02-17 04:18:57 +00:00
|
|
|
|
2014-03-02 19:36:45 +00:00
|
|
|
mkViewComponent :: MetaField -> ViewFilter -> ViewComponent
|
|
|
|
mkViewComponent f vf = ViewComponent f vf (multiValue vf)
|
|
|
|
|
2014-02-18 21:38:23 +00:00
|
|
|
{- Can a ViewFilter match multiple different MetaValues? -}
|
|
|
|
multiValue :: ViewFilter -> Bool
|
|
|
|
multiValue (FilterValues s) = S.size s > 1
|
|
|
|
multiValue (FilterGlob _) = True
|
2014-03-02 18:53:19 +00:00
|
|
|
multiValue (ExcludeValues _) = False
|