2014-02-17 04:18:57 +00:00
|
|
|
{- types for metadata based branch views
|
|
|
|
-
|
2023-02-07 20:28:46 +00:00
|
|
|
- Copyright 2014-2023 Joey Hess <id@joeyh.name>
|
2014-02-17 04:18:57 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2014-02-17 04:18:57 +00:00
|
|
|
-}
|
|
|
|
|
2020-04-07 17:27:11 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2014-02-17 04:18:57 +00:00
|
|
|
module Types.View where
|
|
|
|
|
|
|
|
import Types.MetaData
|
|
|
|
import Utility.QuickCheck
|
2023-02-07 20:28:46 +00:00
|
|
|
import Utility.Monad
|
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
|
2020-06-23 20:40:41 +00:00
|
|
|
arbitrary = View (Git.Ref "foo")
|
2019-01-21 17:40:11 +00:00
|
|
|
<$> resize 10 (listOf 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)
|
2023-02-07 20:28:46 +00:00
|
|
|
| FilterValuesOrUnset (S.Set MetaValue) ViewUnset
|
|
|
|
| FilterGlobOrUnset String ViewUnset
|
|
|
|
deriving (Eq, Read, Show)
|
|
|
|
|
|
|
|
newtype ViewUnset = ViewUnset String
|
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
|
2019-01-21 17:40:11 +00:00
|
|
|
s <- S.fromList <$> resize 10 (listOf arbitrary)
|
2014-03-02 18:53:19 +00:00
|
|
|
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
|
2023-02-07 20:28:46 +00:00
|
|
|
multiValue (FilterValuesOrUnset _ _) = True
|
|
|
|
multiValue (FilterGlobOrUnset _ _) = True
|