{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveGeneric #-}
module Codec.Xlsx.Types.AutoFilter where
import Control.Arrow (first)
import Control.DeepSeq (NFData)
#ifdef USE_MICROLENS
import Lens.Micro.TH (makeLenses)
#else
import Control.Lens (makeLenses)
#endif
import Data.Bool (bool)
import Data.ByteString (ByteString)
import Data.Default
import Data.Foldable (asum)
import Data.Map (Map)
import qualified Data.Map as M
import Data.Maybe (catMaybes)
import Data.Monoid ((<>))
import Data.Text (Text)
import qualified Data.Text as T
import GHC.Generics (Generic)
import Text.XML
import Text.XML.Cursor hiding (bool)
import qualified Xeno.DOM as Xeno
import Codec.Xlsx.Parser.Internal
import Codec.Xlsx.Types.Common
import Codec.Xlsx.Types.ConditionalFormatting (IconSetType)
import Codec.Xlsx.Writer.Internal
data FilterColumn
= Filters FilterByBlank [FilterCriterion]
| ColorFilter ColorFilterOptions
| ACustomFilter CustomFilter
| CustomFiltersOr CustomFilter CustomFilter
| CustomFiltersAnd CustomFilter CustomFilter
| DynamicFilter DynFilterOptions
| IconFilter (Maybe Int) IconSetType
| BottomNFilter EdgeFilterOptions
| TopNFilter EdgeFilterOptions
deriving (FilterColumn -> FilterColumn -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FilterColumn -> FilterColumn -> Bool
$c/= :: FilterColumn -> FilterColumn -> Bool
== :: FilterColumn -> FilterColumn -> Bool
$c== :: FilterColumn -> FilterColumn -> Bool
Eq, Int -> FilterColumn -> ShowS
[FilterColumn] -> ShowS
FilterColumn -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [FilterColumn] -> ShowS
$cshowList :: [FilterColumn] -> ShowS
show :: FilterColumn -> [Char]
$cshow :: FilterColumn -> [Char]
showsPrec :: Int -> FilterColumn -> ShowS
$cshowsPrec :: Int -> FilterColumn -> ShowS
Show, forall x. Rep FilterColumn x -> FilterColumn
forall x. FilterColumn -> Rep FilterColumn x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FilterColumn x -> FilterColumn
$cfrom :: forall x. FilterColumn -> Rep FilterColumn x
Generic)
instance NFData FilterColumn
data FilterByBlank
= FilterByBlank
| DontFilterByBlank
deriving (FilterByBlank -> FilterByBlank -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FilterByBlank -> FilterByBlank -> Bool
$c/= :: FilterByBlank -> FilterByBlank -> Bool
== :: FilterByBlank -> FilterByBlank -> Bool
$c== :: FilterByBlank -> FilterByBlank -> Bool
Eq, Int -> FilterByBlank -> ShowS
[FilterByBlank] -> ShowS
FilterByBlank -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [FilterByBlank] -> ShowS
$cshowList :: [FilterByBlank] -> ShowS
show :: FilterByBlank -> [Char]
$cshow :: FilterByBlank -> [Char]
showsPrec :: Int -> FilterByBlank -> ShowS
$cshowsPrec :: Int -> FilterByBlank -> ShowS
Show, forall x. Rep FilterByBlank x -> FilterByBlank
forall x. FilterByBlank -> Rep FilterByBlank x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FilterByBlank x -> FilterByBlank
$cfrom :: forall x. FilterByBlank -> Rep FilterByBlank x
Generic)
instance NFData FilterByBlank
data FilterCriterion
= FilterValue Text
| FilterDateGroup DateGroup
deriving (FilterCriterion -> FilterCriterion -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FilterCriterion -> FilterCriterion -> Bool
$c/= :: FilterCriterion -> FilterCriterion -> Bool
== :: FilterCriterion -> FilterCriterion -> Bool
$c== :: FilterCriterion -> FilterCriterion -> Bool
Eq, Int -> FilterCriterion -> ShowS
[FilterCriterion] -> ShowS
FilterCriterion -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [FilterCriterion] -> ShowS
$cshowList :: [FilterCriterion] -> ShowS
show :: FilterCriterion -> [Char]
$cshow :: FilterCriterion -> [Char]
showsPrec :: Int -> FilterCriterion -> ShowS
$cshowsPrec :: Int -> FilterCriterion -> ShowS
Show, forall x. Rep FilterCriterion x -> FilterCriterion
forall x. FilterCriterion -> Rep FilterCriterion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FilterCriterion x -> FilterCriterion
$cfrom :: forall x. FilterCriterion -> Rep FilterCriterion x
Generic)
instance NFData FilterCriterion
data DateGroup
= DateGroupByYear Int
| DateGroupByMonth Int Int
| DateGroupByDay Int Int Int
| DateGroupByHour Int Int Int Int
| DateGroupByMinute Int Int Int Int Int
| DateGroupBySecond Int Int Int Int Int Int
deriving (DateGroup -> DateGroup -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DateGroup -> DateGroup -> Bool
$c/= :: DateGroup -> DateGroup -> Bool
== :: DateGroup -> DateGroup -> Bool
$c== :: DateGroup -> DateGroup -> Bool
Eq, Int -> DateGroup -> ShowS
[DateGroup] -> ShowS
DateGroup -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [DateGroup] -> ShowS
$cshowList :: [DateGroup] -> ShowS
show :: DateGroup -> [Char]
$cshow :: DateGroup -> [Char]
showsPrec :: Int -> DateGroup -> ShowS
$cshowsPrec :: Int -> DateGroup -> ShowS
Show, forall x. Rep DateGroup x -> DateGroup
forall x. DateGroup -> Rep DateGroup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DateGroup x -> DateGroup
$cfrom :: forall x. DateGroup -> Rep DateGroup x
Generic)
instance NFData DateGroup
data CustomFilter = CustomFilter
{ CustomFilter -> CustomFilterOperator
cfltOperator :: CustomFilterOperator
, CustomFilter -> Text
cfltValue :: Text
} deriving (CustomFilter -> CustomFilter -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomFilter -> CustomFilter -> Bool
$c/= :: CustomFilter -> CustomFilter -> Bool
== :: CustomFilter -> CustomFilter -> Bool
$c== :: CustomFilter -> CustomFilter -> Bool
Eq, Int -> CustomFilter -> ShowS
[CustomFilter] -> ShowS
CustomFilter -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [CustomFilter] -> ShowS
$cshowList :: [CustomFilter] -> ShowS
show :: CustomFilter -> [Char]
$cshow :: CustomFilter -> [Char]
showsPrec :: Int -> CustomFilter -> ShowS
$cshowsPrec :: Int -> CustomFilter -> ShowS
Show, forall x. Rep CustomFilter x -> CustomFilter
forall x. CustomFilter -> Rep CustomFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CustomFilter x -> CustomFilter
$cfrom :: forall x. CustomFilter -> Rep CustomFilter x
Generic)
instance NFData CustomFilter
data CustomFilterOperator
= FltrEqual
| FltrGreaterThan
| FltrGreaterThanOrEqual
| FltrLessThan
| FltrLessThanOrEqual
| FltrNotEqual
deriving (CustomFilterOperator -> CustomFilterOperator -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomFilterOperator -> CustomFilterOperator -> Bool
$c/= :: CustomFilterOperator -> CustomFilterOperator -> Bool
== :: CustomFilterOperator -> CustomFilterOperator -> Bool
$c== :: CustomFilterOperator -> CustomFilterOperator -> Bool
Eq, Int -> CustomFilterOperator -> ShowS
[CustomFilterOperator] -> ShowS
CustomFilterOperator -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [CustomFilterOperator] -> ShowS
$cshowList :: [CustomFilterOperator] -> ShowS
show :: CustomFilterOperator -> [Char]
$cshow :: CustomFilterOperator -> [Char]
showsPrec :: Int -> CustomFilterOperator -> ShowS
$cshowsPrec :: Int -> CustomFilterOperator -> ShowS
Show, forall x. Rep CustomFilterOperator x -> CustomFilterOperator
forall x. CustomFilterOperator -> Rep CustomFilterOperator x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CustomFilterOperator x -> CustomFilterOperator
$cfrom :: forall x. CustomFilterOperator -> Rep CustomFilterOperator x
Generic)
instance NFData CustomFilterOperator
data EdgeFilterOptions = EdgeFilterOptions
{ EdgeFilterOptions -> Bool
_efoUsePercents :: Bool
, EdgeFilterOptions -> Double
_efoVal :: Double
, EdgeFilterOptions -> Maybe Double
_efoFilterVal :: Maybe Double
} deriving (EdgeFilterOptions -> EdgeFilterOptions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EdgeFilterOptions -> EdgeFilterOptions -> Bool
$c/= :: EdgeFilterOptions -> EdgeFilterOptions -> Bool
== :: EdgeFilterOptions -> EdgeFilterOptions -> Bool
$c== :: EdgeFilterOptions -> EdgeFilterOptions -> Bool
Eq, Int -> EdgeFilterOptions -> ShowS
[EdgeFilterOptions] -> ShowS
EdgeFilterOptions -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [EdgeFilterOptions] -> ShowS
$cshowList :: [EdgeFilterOptions] -> ShowS
show :: EdgeFilterOptions -> [Char]
$cshow :: EdgeFilterOptions -> [Char]
showsPrec :: Int -> EdgeFilterOptions -> ShowS
$cshowsPrec :: Int -> EdgeFilterOptions -> ShowS
Show, forall x. Rep EdgeFilterOptions x -> EdgeFilterOptions
forall x. EdgeFilterOptions -> Rep EdgeFilterOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EdgeFilterOptions x -> EdgeFilterOptions
$cfrom :: forall x. EdgeFilterOptions -> Rep EdgeFilterOptions x
Generic)
instance NFData EdgeFilterOptions
data ColorFilterOptions = ColorFilterOptions
{ ColorFilterOptions -> Bool
_cfoCellColor :: Bool
, ColorFilterOptions -> Maybe Int
_cfoDxfId :: Maybe Int
} deriving (ColorFilterOptions -> ColorFilterOptions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ColorFilterOptions -> ColorFilterOptions -> Bool
$c/= :: ColorFilterOptions -> ColorFilterOptions -> Bool
== :: ColorFilterOptions -> ColorFilterOptions -> Bool
$c== :: ColorFilterOptions -> ColorFilterOptions -> Bool
Eq, Int -> ColorFilterOptions -> ShowS
[ColorFilterOptions] -> ShowS
ColorFilterOptions -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [ColorFilterOptions] -> ShowS
$cshowList :: [ColorFilterOptions] -> ShowS
show :: ColorFilterOptions -> [Char]
$cshow :: ColorFilterOptions -> [Char]
showsPrec :: Int -> ColorFilterOptions -> ShowS
$cshowsPrec :: Int -> ColorFilterOptions -> ShowS
Show, forall x. Rep ColorFilterOptions x -> ColorFilterOptions
forall x. ColorFilterOptions -> Rep ColorFilterOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ColorFilterOptions x -> ColorFilterOptions
$cfrom :: forall x. ColorFilterOptions -> Rep ColorFilterOptions x
Generic)
instance NFData ColorFilterOptions
data DynFilterOptions = DynFilterOptions
{ DynFilterOptions -> DynFilterType
_dfoType :: DynFilterType
, DynFilterOptions -> Maybe Double
_dfoVal :: Maybe Double
, DynFilterOptions -> Maybe Double
_dfoMaxVal :: Maybe Double
} deriving (DynFilterOptions -> DynFilterOptions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DynFilterOptions -> DynFilterOptions -> Bool
$c/= :: DynFilterOptions -> DynFilterOptions -> Bool
== :: DynFilterOptions -> DynFilterOptions -> Bool
$c== :: DynFilterOptions -> DynFilterOptions -> Bool
Eq, Int -> DynFilterOptions -> ShowS
[DynFilterOptions] -> ShowS
DynFilterOptions -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [DynFilterOptions] -> ShowS
$cshowList :: [DynFilterOptions] -> ShowS
show :: DynFilterOptions -> [Char]
$cshow :: DynFilterOptions -> [Char]
showsPrec :: Int -> DynFilterOptions -> ShowS
$cshowsPrec :: Int -> DynFilterOptions -> ShowS
Show, forall x. Rep DynFilterOptions x -> DynFilterOptions
forall x. DynFilterOptions -> Rep DynFilterOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DynFilterOptions x -> DynFilterOptions
$cfrom :: forall x. DynFilterOptions -> Rep DynFilterOptions x
Generic)
instance NFData DynFilterOptions
data DynFilterType
= DynFilterAboveAverage
| DynFilterBelowAverage
| DynFilterLastMonth
| DynFilterLastQuarter
| DynFilterLastWeek
| DynFilterLastYear
| DynFilterM1
| DynFilterM10
| DynFilterM11
| DynFilterM12
| DynFilterM2
| DynFilterM3
| DynFilterM4
| DynFilterM5
| DynFilterM6
| DynFilterM7
| DynFilterM8
| DynFilterM9
| DynFilterNextMonth
| DynFilterNextQuarter
| DynFilterNextWeek
| DynFilterNextYear
| DynFilterNull
| DynFilterQ1
| DynFilterQ2
| DynFilterQ3
| DynFilterQ4
| DynFilterThisMonth
| DynFilterThisQuarter
| DynFilterThisWeek
| DynFilterThisYear
| DynFilterToday
| DynFilterTomorrow
| DynFilterYearToDate
| DynFilterYesterday
deriving (DynFilterType -> DynFilterType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DynFilterType -> DynFilterType -> Bool
$c/= :: DynFilterType -> DynFilterType -> Bool
== :: DynFilterType -> DynFilterType -> Bool
$c== :: DynFilterType -> DynFilterType -> Bool
Eq, Int -> DynFilterType -> ShowS
[DynFilterType] -> ShowS
DynFilterType -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [DynFilterType] -> ShowS
$cshowList :: [DynFilterType] -> ShowS
show :: DynFilterType -> [Char]
$cshow :: DynFilterType -> [Char]
showsPrec :: Int -> DynFilterType -> ShowS
$cshowsPrec :: Int -> DynFilterType -> ShowS
Show, forall x. Rep DynFilterType x -> DynFilterType
forall x. DynFilterType -> Rep DynFilterType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DynFilterType x -> DynFilterType
$cfrom :: forall x. DynFilterType -> Rep DynFilterType x
Generic)
instance NFData DynFilterType
data AutoFilter = AutoFilter
{ AutoFilter -> Maybe CellRef
_afRef :: Maybe CellRef
, AutoFilter -> Map Int FilterColumn
_afFilterColumns :: Map Int FilterColumn
} deriving (AutoFilter -> AutoFilter -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AutoFilter -> AutoFilter -> Bool
$c/= :: AutoFilter -> AutoFilter -> Bool
== :: AutoFilter -> AutoFilter -> Bool
$c== :: AutoFilter -> AutoFilter -> Bool
Eq, Int -> AutoFilter -> ShowS
[AutoFilter] -> ShowS
AutoFilter -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [AutoFilter] -> ShowS
$cshowList :: [AutoFilter] -> ShowS
show :: AutoFilter -> [Char]
$cshow :: AutoFilter -> [Char]
showsPrec :: Int -> AutoFilter -> ShowS
$cshowsPrec :: Int -> AutoFilter -> ShowS
Show, forall x. Rep AutoFilter x -> AutoFilter
forall x. AutoFilter -> Rep AutoFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AutoFilter x -> AutoFilter
$cfrom :: forall x. AutoFilter -> Rep AutoFilter x
Generic)
instance NFData AutoFilter
makeLenses ''AutoFilter
instance Default AutoFilter where
def :: AutoFilter
def = Maybe CellRef -> Map Int FilterColumn -> AutoFilter
AutoFilter forall a. Maybe a
Nothing forall k a. Map k a
M.empty
instance FromCursor AutoFilter where
fromCursor :: Cursor -> [AutoFilter]
fromCursor Cursor
cur = do
Maybe CellRef
_afRef <- forall a. FromAttrVal a => Name -> Cursor -> [Maybe a]
maybeAttribute Name
"ref" Cursor
cur
let _afFilterColumns :: Map Int FilterColumn
_afFilterColumns = forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall a b. (a -> b) -> a -> b
$ Cursor
cur forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
n_ Text
"filterColumn") forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \Cursor
c -> do
Int
colId <- forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"colId" Cursor
c
FilterColumn
fcol <- Cursor
c forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Axis
anyElement forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Node -> [FilterColumn]
fltColFromNode forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall node. Cursor node -> node
node
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
colId, FilterColumn
fcol)
forall (m :: * -> *) a. Monad m => a -> m a
return AutoFilter {Maybe CellRef
Map Int FilterColumn
_afFilterColumns :: Map Int FilterColumn
_afRef :: Maybe CellRef
_afFilterColumns :: Map Int FilterColumn
_afRef :: Maybe CellRef
..}
instance FromXenoNode AutoFilter where
fromXenoNode :: Node -> Either Text AutoFilter
fromXenoNode Node
root = do
Maybe CellRef
_afRef <- forall a. Node -> AttrParser a -> Either Text a
parseAttributes Node
root forall a b. (a -> b) -> a -> b
$ forall a. FromAttrBs a => ByteString -> AttrParser (Maybe a)
maybeAttr ByteString
"ref"
Map Int FilterColumn
_afFilterColumns <-
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Node -> ChildCollector a -> Either Text a
collectChildren Node
root forall a b. (a -> b) -> a -> b
$ forall a. FromXenoNode a => ByteString -> ChildCollector [a]
fromChildList ByteString
"filterColumn"
forall (m :: * -> *) a. Monad m => a -> m a
return AutoFilter {Maybe CellRef
Map Int FilterColumn
_afFilterColumns :: Map Int FilterColumn
_afRef :: Maybe CellRef
_afFilterColumns :: Map Int FilterColumn
_afRef :: Maybe CellRef
..}
instance FromXenoNode (Int, FilterColumn) where
fromXenoNode :: Node -> Either Text (Int, FilterColumn)
fromXenoNode Node
root = do
Int
colId <- forall a. Node -> AttrParser a -> Either Text a
parseAttributes Node
root forall a b. (a -> b) -> a -> b
$ forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"colId"
FilterColumn
fCol <-
forall a. Node -> ChildCollector a -> Either Text a
collectChildren Node
root forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum [ChildCollector FilterColumn
filters, ChildCollector FilterColumn
color, ChildCollector FilterColumn
custom, ChildCollector FilterColumn
dynamic, ChildCollector FilterColumn
icon, ChildCollector FilterColumn
top10]
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
colId, FilterColumn
fCol)
where
filters :: ChildCollector FilterColumn
filters =
forall a. ByteString -> (Node -> Either Text a) -> ChildCollector a
requireAndParse ByteString
"filters" forall a b. (a -> b) -> a -> b
$ \Node
node -> do
FilterByBlank
filterBlank <-
forall a. Node -> AttrParser a -> Either Text a
parseAttributes Node
node forall a b. (a -> b) -> a -> b
$ forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"blank" FilterByBlank
DontFilterByBlank
[FilterCriterion]
filterCriteria <- forall a. FromXenoNode a => Node -> Either Text [a]
childListAny Node
node
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ FilterByBlank -> [FilterCriterion] -> FilterColumn
Filters FilterByBlank
filterBlank [FilterCriterion]
filterCriteria
color :: ChildCollector FilterColumn
color =
forall a. ByteString -> (Node -> Either Text a) -> ChildCollector a
requireAndParse ByteString
"colorFilter" forall a b. (a -> b) -> a -> b
$ \Node
node ->
forall a. Node -> AttrParser a -> Either Text a
parseAttributes Node
node forall a b. (a -> b) -> a -> b
$ do
Bool
_cfoCellColor <- forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"cellColor" Bool
True
Maybe Int
_cfoDxfId <- forall a. FromAttrBs a => ByteString -> AttrParser (Maybe a)
maybeAttr ByteString
"dxfId"
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ColorFilterOptions -> FilterColumn
ColorFilter ColorFilterOptions {Bool
Maybe Int
_cfoDxfId :: Maybe Int
_cfoCellColor :: Bool
_cfoDxfId :: Maybe Int
_cfoCellColor :: Bool
..}
custom :: ChildCollector FilterColumn
custom =
forall a. ByteString -> (Node -> Either Text a) -> ChildCollector a
requireAndParse ByteString
"customFilters" forall a b. (a -> b) -> a -> b
$ \Node
node -> do
Bool
isAnd <- forall a. Node -> AttrParser a -> Either Text a
parseAttributes Node
node forall a b. (a -> b) -> a -> b
$ forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"and" Bool
False
[CustomFilter]
cfilters <- forall a. Node -> ChildCollector a -> Either Text a
collectChildren Node
node forall a b. (a -> b) -> a -> b
$ forall a. FromXenoNode a => ByteString -> ChildCollector [a]
fromChildList ByteString
"customFilter"
case [CustomFilter]
cfilters of
[CustomFilter
f] -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ CustomFilter -> FilterColumn
ACustomFilter CustomFilter
f
[CustomFilter
f1, CustomFilter
f2] ->
if Bool
isAnd
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ CustomFilter -> CustomFilter -> FilterColumn
CustomFiltersAnd CustomFilter
f1 CustomFilter
f2
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ CustomFilter -> CustomFilter -> FilterColumn
CustomFiltersOr CustomFilter
f1 CustomFilter
f2
[CustomFilter]
_ ->
forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$
Text
"expected 1 or 2 custom filters but found " forall a. Semigroup a => a -> a -> a
<>
[Char] -> Text
T.pack (forall a. Show a => a -> [Char]
show forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> Int
length [CustomFilter]
cfilters)
dynamic :: ChildCollector FilterColumn
dynamic =
forall a. ByteString -> (Node -> Either Text a) -> ChildCollector a
requireAndParse ByteString
"dynamicFilter" forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Node -> AttrParser a -> Either Text a
parseAttributes forall a b. (a -> b) -> a -> b
$ do
DynFilterType
_dfoType <- forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"type"
Maybe Double
_dfoVal <- forall a. FromAttrBs a => ByteString -> AttrParser (Maybe a)
maybeAttr ByteString
"val"
Maybe Double
_dfoMaxVal <- forall a. FromAttrBs a => ByteString -> AttrParser (Maybe a)
maybeAttr ByteString
"maxVal"
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ DynFilterOptions -> FilterColumn
DynamicFilter DynFilterOptions {Maybe Double
DynFilterType
_dfoMaxVal :: Maybe Double
_dfoVal :: Maybe Double
_dfoType :: DynFilterType
_dfoMaxVal :: Maybe Double
_dfoVal :: Maybe Double
_dfoType :: DynFilterType
..}
icon :: ChildCollector FilterColumn
icon =
forall a. ByteString -> (Node -> Either Text a) -> ChildCollector a
requireAndParse ByteString
"iconFilter" forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Node -> AttrParser a -> Either Text a
parseAttributes forall a b. (a -> b) -> a -> b
$
Maybe Int -> IconSetType -> FilterColumn
IconFilter forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromAttrBs a => ByteString -> AttrParser (Maybe a)
maybeAttr ByteString
"iconId" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"iconSet"
top10 :: ChildCollector FilterColumn
top10 =
forall a. ByteString -> (Node -> Either Text a) -> ChildCollector a
requireAndParse ByteString
"top10" forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Node -> AttrParser a -> Either Text a
parseAttributes forall a b. (a -> b) -> a -> b
$ do
Bool
top <- forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"top" Bool
True
Bool
percent <- forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"percent" Bool
False
Double
val <- forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"val"
Maybe Double
filterVal <- forall a. FromAttrBs a => ByteString -> AttrParser (Maybe a)
maybeAttr ByteString
"filterVal"
let opts :: EdgeFilterOptions
opts = Bool -> Double -> Maybe Double -> EdgeFilterOptions
EdgeFilterOptions Bool
percent Double
val Maybe Double
filterVal
if Bool
top
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ EdgeFilterOptions -> FilterColumn
TopNFilter EdgeFilterOptions
opts
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ EdgeFilterOptions -> FilterColumn
BottomNFilter EdgeFilterOptions
opts
instance FromXenoNode CustomFilter where
fromXenoNode :: Node -> Either Text CustomFilter
fromXenoNode Node
root =
forall a. Node -> AttrParser a -> Either Text a
parseAttributes Node
root forall a b. (a -> b) -> a -> b
$
CustomFilterOperator -> Text -> CustomFilter
CustomFilter forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromAttrBs a => ByteString -> a -> AttrParser a
fromAttrDef ByteString
"operator" CustomFilterOperator
FltrEqual forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"val"
fltColFromNode :: Node -> [FilterColumn]
fltColFromNode :: Node -> [FilterColumn]
fltColFromNode Node
n | Node
n Node -> Name -> Bool
`nodeElNameIs` (Text -> Name
n_ Text
"filters") = do
let filterCriteria :: [FilterCriterion]
filterCriteria = Cursor
cur forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Axis
anyElement forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> forall a. FromCursor a => Cursor -> [a]
fromCursor
FilterByBlank
filterBlank <- forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"blank" FilterByBlank
DontFilterByBlank Cursor
cur
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ FilterByBlank -> [FilterCriterion] -> FilterColumn
Filters FilterByBlank
filterBlank [FilterCriterion]
filterCriteria
| Node
n Node -> Name -> Bool
`nodeElNameIs` (Text -> Name
n_ Text
"colorFilter") = do
Bool
_cfoCellColor <- forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"cellColor" Bool
True Cursor
cur
Maybe Int
_cfoDxfId <- forall a. FromAttrVal a => Name -> Cursor -> [Maybe a]
maybeAttribute Name
"dxfId" Cursor
cur
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ColorFilterOptions -> FilterColumn
ColorFilter ColorFilterOptions {Bool
Maybe Int
_cfoDxfId :: Maybe Int
_cfoCellColor :: Bool
_cfoDxfId :: Maybe Int
_cfoCellColor :: Bool
..}
| Node
n Node -> Name -> Bool
`nodeElNameIs` (Text -> Name
n_ Text
"customFilters") = do
Bool
isAnd <- forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"and" Bool
False Cursor
cur
let cFilters :: [CustomFilter]
cFilters = Cursor
cur forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
n_ Text
"customFilter") forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \Cursor
c -> do
CustomFilterOperator
op <- forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"operator" CustomFilterOperator
FltrEqual Cursor
c
Text
val <- forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"val" Cursor
c
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ CustomFilterOperator -> Text -> CustomFilter
CustomFilter CustomFilterOperator
op Text
val
case [CustomFilter]
cFilters of
[CustomFilter
f] ->
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ CustomFilter -> FilterColumn
ACustomFilter CustomFilter
f
[CustomFilter
f1, CustomFilter
f2] ->
if Bool
isAnd
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ CustomFilter -> CustomFilter -> FilterColumn
CustomFiltersAnd CustomFilter
f1 CustomFilter
f2
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ CustomFilter -> CustomFilter -> FilterColumn
CustomFiltersOr CustomFilter
f1 CustomFilter
f2
[CustomFilter]
_ ->
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"bad custom filter"
| Node
n Node -> Name -> Bool
`nodeElNameIs` (Text -> Name
n_ Text
"dynamicFilter") = do
DynFilterType
_dfoType <- forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"type" Cursor
cur
Maybe Double
_dfoVal <- forall a. FromAttrVal a => Name -> Cursor -> [Maybe a]
maybeAttribute Name
"val" Cursor
cur
Maybe Double
_dfoMaxVal <- forall a. FromAttrVal a => Name -> Cursor -> [Maybe a]
maybeAttribute Name
"maxVal" Cursor
cur
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ DynFilterOptions -> FilterColumn
DynamicFilter DynFilterOptions{Maybe Double
DynFilterType
_dfoMaxVal :: Maybe Double
_dfoVal :: Maybe Double
_dfoType :: DynFilterType
_dfoMaxVal :: Maybe Double
_dfoVal :: Maybe Double
_dfoType :: DynFilterType
..}
| Node
n Node -> Name -> Bool
`nodeElNameIs` (Text -> Name
n_ Text
"iconFilter") = do
Maybe Int
iconId <- forall a. FromAttrVal a => Name -> Cursor -> [Maybe a]
maybeAttribute Name
"iconId" Cursor
cur
IconSetType
iconSet <- forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"iconSet" Cursor
cur
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Maybe Int -> IconSetType -> FilterColumn
IconFilter Maybe Int
iconId IconSetType
iconSet
| Node
n Node -> Name -> Bool
`nodeElNameIs` (Text -> Name
n_ Text
"top10") = do
Bool
top <- forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"top" Bool
True Cursor
cur
let percent :: [Bool]
percent = forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"percent" Bool
False Cursor
cur
val :: [Double]
val = forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"val" Cursor
cur
filterVal :: [Maybe Double]
filterVal = forall a. FromAttrVal a => Name -> Cursor -> [Maybe a]
maybeAttribute Name
"filterVal" Cursor
cur
if Bool
top
then forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EdgeFilterOptions -> FilterColumn
TopNFilter forall a b. (a -> b) -> a -> b
$
Bool -> Double -> Maybe Double -> EdgeFilterOptions
EdgeFilterOptions forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Bool]
percent forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Double]
val forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Maybe Double]
filterVal
else forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EdgeFilterOptions -> FilterColumn
BottomNFilter forall a b. (a -> b) -> a -> b
$
Bool -> Double -> Maybe Double -> EdgeFilterOptions
EdgeFilterOptions forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Bool]
percent forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Double]
val forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Maybe Double]
filterVal
| Bool
otherwise = forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"no matching nodes"
where
cur :: Cursor
cur = Node -> Cursor
fromNode Node
n
instance FromCursor FilterCriterion where
fromCursor :: Cursor -> [FilterCriterion]
fromCursor = Node -> [FilterCriterion]
filterCriterionFromNode forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall node. Cursor node -> node
node
instance FromXenoNode FilterCriterion where
fromXenoNode :: Node -> Either Text FilterCriterion
fromXenoNode Node
root =
case Node -> ByteString
Xeno.name Node
root of
ByteString
"filter" -> forall a. Node -> AttrParser a -> Either Text a
parseAttributes Node
root forall a b. (a -> b) -> a -> b
$ do Text -> FilterCriterion
FilterValue forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"val"
ByteString
"dateGroupItem" ->
forall a. Node -> AttrParser a -> Either Text a
parseAttributes Node
root forall a b. (a -> b) -> a -> b
$ do
ByteString
grouping <- forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"dateTimeGrouping"
DateGroup
group <- case ByteString
grouping of
(ByteString
"year" :: ByteString) ->
Int -> DateGroup
DateGroupByYear forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"year"
ByteString
"month" ->
Int -> Int -> DateGroup
DateGroupByMonth forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"year"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"month"
ByteString
"day" ->
Int -> Int -> Int -> DateGroup
DateGroupByDay forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"year"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"month"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"day"
ByteString
"hour" ->
Int -> Int -> Int -> Int -> DateGroup
DateGroupByHour forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"year"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"month"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"day"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"hour"
ByteString
"minute" ->
Int -> Int -> Int -> Int -> Int -> DateGroup
DateGroupByMinute forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"year"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"month"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"day"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"hour"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"minute"
ByteString
"second" ->
Int -> Int -> Int -> Int -> Int -> Int -> DateGroup
DateGroupBySecond forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"year"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"month"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"day"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"hour"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"minute"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"second"
ByteString
_ -> forall a. Either Text a -> AttrParser a
toAttrParser forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ Text
"Unexpected date grouping"
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ DateGroup -> FilterCriterion
FilterDateGroup DateGroup
group
ByteString
_ -> forall a b. a -> Either a b
Left Text
"Bad FilterCriterion"
filterCriterionFromNode :: Node -> [FilterCriterion]
filterCriterionFromNode :: Node -> [FilterCriterion]
filterCriterionFromNode Node
n
| Node
n Node -> Name -> Bool
`nodeElNameIs` (Text -> Name
n_ Text
"filter") = do
Text
v <- forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"val" Cursor
cur
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> FilterCriterion
FilterValue Text
v
| Node
n Node -> Name -> Bool
`nodeElNameIs` (Text -> Name
n_ Text
"dateGroupItem") = do
Text
g <- forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"dateTimeGrouping" Cursor
cur
let year :: [Int]
year = forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"year" Cursor
cur
month :: [Int]
month = forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"month" Cursor
cur
day :: [Int]
day = forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"day" Cursor
cur
hour :: [Int]
hour = forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"hour" Cursor
cur
minute :: [Int]
minute = forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"minute" Cursor
cur
second :: [Int]
second = forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"second" Cursor
cur
DateGroup -> FilterCriterion
FilterDateGroup forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
case Text
g of
Text
"year" -> Int -> DateGroup
DateGroupByYear forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Int]
year
Text
"month" -> Int -> Int -> DateGroup
DateGroupByMonth forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Int]
year forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Int]
month
Text
"day" -> Int -> Int -> Int -> DateGroup
DateGroupByDay forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Int]
year forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Int]
month forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Int]
day
Text
"hour" -> Int -> Int -> Int -> Int -> DateGroup
DateGroupByHour forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Int]
year forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Int]
month forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Int]
day forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Int]
hour
Text
"minute" ->
Int -> Int -> Int -> Int -> Int -> DateGroup
DateGroupByMinute forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Int]
year forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Int]
month forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Int]
day forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Int]
hour forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Int]
minute
Text
"second" ->
Int -> Int -> Int -> Int -> Int -> Int -> DateGroup
DateGroupBySecond forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Int]
year forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Int]
month forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Int]
day forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Int]
hour forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Int]
minute forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
[Int]
second
Text
_ -> forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail forall a b. (a -> b) -> a -> b
$ [Char]
"unexpected dateTimeGrouping " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (Text
g :: Text)
| Bool
otherwise = forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"no matching nodes"
where
cur :: Cursor
cur = Node -> Cursor
fromNode Node
n
instance FromAttrVal CustomFilterOperator where
fromAttrVal :: Reader CustomFilterOperator
fromAttrVal Text
"equal" = forall a. a -> Either [Char] (a, Text)
readSuccess CustomFilterOperator
FltrEqual
fromAttrVal Text
"greaterThan" = forall a. a -> Either [Char] (a, Text)
readSuccess CustomFilterOperator
FltrGreaterThan
fromAttrVal Text
"greaterThanOrEqual" = forall a. a -> Either [Char] (a, Text)
readSuccess CustomFilterOperator
FltrGreaterThanOrEqual
fromAttrVal Text
"lessThan" = forall a. a -> Either [Char] (a, Text)
readSuccess CustomFilterOperator
FltrLessThan
fromAttrVal Text
"lessThanOrEqual" = forall a. a -> Either [Char] (a, Text)
readSuccess CustomFilterOperator
FltrLessThanOrEqual
fromAttrVal Text
"notEqual" = forall a. a -> Either [Char] (a, Text)
readSuccess CustomFilterOperator
FltrNotEqual
fromAttrVal Text
t = forall a. Text -> Text -> Either [Char] (a, Text)
invalidText Text
"CustomFilterOperator" Text
t
instance FromAttrBs CustomFilterOperator where
fromAttrBs :: ByteString -> Either Text CustomFilterOperator
fromAttrBs ByteString
"equal" = forall (m :: * -> *) a. Monad m => a -> m a
return CustomFilterOperator
FltrEqual
fromAttrBs ByteString
"greaterThan" = forall (m :: * -> *) a. Monad m => a -> m a
return CustomFilterOperator
FltrGreaterThan
fromAttrBs ByteString
"greaterThanOrEqual" = forall (m :: * -> *) a. Monad m => a -> m a
return CustomFilterOperator
FltrGreaterThanOrEqual
fromAttrBs ByteString
"lessThan" = forall (m :: * -> *) a. Monad m => a -> m a
return CustomFilterOperator
FltrLessThan
fromAttrBs ByteString
"lessThanOrEqual" = forall (m :: * -> *) a. Monad m => a -> m a
return CustomFilterOperator
FltrLessThanOrEqual
fromAttrBs ByteString
"notEqual" = forall (m :: * -> *) a. Monad m => a -> m a
return CustomFilterOperator
FltrNotEqual
fromAttrBs ByteString
x = forall a. Text -> ByteString -> Either Text a
unexpectedAttrBs Text
"CustomFilterOperator" ByteString
x
instance FromAttrVal FilterByBlank where
fromAttrVal :: Reader FilterByBlank
fromAttrVal =
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first forall a b. (a -> b) -> a -> b
$ forall a. a -> a -> Bool -> a
bool FilterByBlank
DontFilterByBlank FilterByBlank
FilterByBlank) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. FromAttrVal a => Reader a
fromAttrVal
instance FromAttrBs FilterByBlank where
fromAttrBs :: ByteString -> Either Text FilterByBlank
fromAttrBs = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. a -> a -> Bool -> a
bool FilterByBlank
DontFilterByBlank FilterByBlank
FilterByBlank) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. FromAttrBs a => ByteString -> Either Text a
fromAttrBs
instance FromAttrVal DynFilterType where
fromAttrVal :: Reader DynFilterType
fromAttrVal Text
"aboveAverage" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterAboveAverage
fromAttrVal Text
"belowAverage" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterBelowAverage
fromAttrVal Text
"lastMonth" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterLastMonth
fromAttrVal Text
"lastQuarter" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterLastQuarter
fromAttrVal Text
"lastWeek" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterLastWeek
fromAttrVal Text
"lastYear" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterLastYear
fromAttrVal Text
"M1" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterM1
fromAttrVal Text
"M10" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterM10
fromAttrVal Text
"M11" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterM11
fromAttrVal Text
"M12" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterM12
fromAttrVal Text
"M2" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterM2
fromAttrVal Text
"M3" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterM3
fromAttrVal Text
"M4" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterM4
fromAttrVal Text
"M5" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterM5
fromAttrVal Text
"M6" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterM6
fromAttrVal Text
"M7" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterM7
fromAttrVal Text
"M8" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterM8
fromAttrVal Text
"M9" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterM9
fromAttrVal Text
"nextMonth" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterNextMonth
fromAttrVal Text
"nextQuarter" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterNextQuarter
fromAttrVal Text
"nextWeek" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterNextWeek
fromAttrVal Text
"nextYear" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterNextYear
fromAttrVal Text
"null" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterNull
fromAttrVal Text
"Q1" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterQ1
fromAttrVal Text
"Q2" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterQ2
fromAttrVal Text
"Q3" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterQ3
fromAttrVal Text
"Q4" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterQ4
fromAttrVal Text
"thisMonth" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterThisMonth
fromAttrVal Text
"thisQuarter" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterThisQuarter
fromAttrVal Text
"thisWeek" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterThisWeek
fromAttrVal Text
"thisYear" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterThisYear
fromAttrVal Text
"today" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterToday
fromAttrVal Text
"tomorrow" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterTomorrow
fromAttrVal Text
"yearToDate" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterYearToDate
fromAttrVal Text
"yesterday" = forall a. a -> Either [Char] (a, Text)
readSuccess DynFilterType
DynFilterYesterday
fromAttrVal Text
t = forall a. Text -> Text -> Either [Char] (a, Text)
invalidText Text
"DynFilterType" Text
t
instance FromAttrBs DynFilterType where
fromAttrBs :: ByteString -> Either Text DynFilterType
fromAttrBs ByteString
"aboveAverage" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterAboveAverage
fromAttrBs ByteString
"belowAverage" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterBelowAverage
fromAttrBs ByteString
"lastMonth" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterLastMonth
fromAttrBs ByteString
"lastQuarter" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterLastQuarter
fromAttrBs ByteString
"lastWeek" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterLastWeek
fromAttrBs ByteString
"lastYear" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterLastYear
fromAttrBs ByteString
"M1" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterM1
fromAttrBs ByteString
"M10" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterM10
fromAttrBs ByteString
"M11" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterM11
fromAttrBs ByteString
"M12" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterM12
fromAttrBs ByteString
"M2" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterM2
fromAttrBs ByteString
"M3" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterM3
fromAttrBs ByteString
"M4" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterM4
fromAttrBs ByteString
"M5" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterM5
fromAttrBs ByteString
"M6" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterM6
fromAttrBs ByteString
"M7" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterM7
fromAttrBs ByteString
"M8" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterM8
fromAttrBs ByteString
"M9" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterM9
fromAttrBs ByteString
"nextMonth" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterNextMonth
fromAttrBs ByteString
"nextQuarter" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterNextQuarter
fromAttrBs ByteString
"nextWeek" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterNextWeek
fromAttrBs ByteString
"nextYear" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterNextYear
fromAttrBs ByteString
"null" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterNull
fromAttrBs ByteString
"Q1" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterQ1
fromAttrBs ByteString
"Q2" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterQ2
fromAttrBs ByteString
"Q3" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterQ3
fromAttrBs ByteString
"Q4" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterQ4
fromAttrBs ByteString
"thisMonth" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterThisMonth
fromAttrBs ByteString
"thisQuarter" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterThisQuarter
fromAttrBs ByteString
"thisWeek" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterThisWeek
fromAttrBs ByteString
"thisYear" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterThisYear
fromAttrBs ByteString
"today" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterToday
fromAttrBs ByteString
"tomorrow" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterTomorrow
fromAttrBs ByteString
"yearToDate" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterYearToDate
fromAttrBs ByteString
"yesterday" = forall (m :: * -> *) a. Monad m => a -> m a
return DynFilterType
DynFilterYesterday
fromAttrBs ByteString
x = forall a. Text -> ByteString -> Either Text a
unexpectedAttrBs Text
"DynFilterType" ByteString
x
instance ToElement AutoFilter where
toElement :: Name -> AutoFilter -> Element
toElement Name
nm AutoFilter {Maybe CellRef
Map Int FilterColumn
_afFilterColumns :: Map Int FilterColumn
_afRef :: Maybe CellRef
_afFilterColumns :: AutoFilter -> Map Int FilterColumn
_afRef :: AutoFilter -> Maybe CellRef
..} =
Name -> [(Name, Text)] -> [Element] -> Element
elementList
Name
nm
(forall a. [Maybe a] -> [a]
catMaybes [Name
"ref" forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Maybe CellRef
_afRef])
[ Name -> [(Name, Text)] -> [Element] -> Element
elementList
(Text -> Name
n_ Text
"filterColumn")
[Name
"colId" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
colId]
[FilterColumn -> Element
fltColToElement FilterColumn
fCol]
| (Int
colId, FilterColumn
fCol) <- forall k a. Map k a -> [(k, a)]
M.toList Map Int FilterColumn
_afFilterColumns
]
fltColToElement :: FilterColumn -> Element
fltColToElement :: FilterColumn -> Element
fltColToElement (Filters FilterByBlank
filterBlank [FilterCriterion]
filterCriteria) =
let attrs :: [(Name, Text)]
attrs = forall a. [Maybe a] -> [a]
catMaybes [Name
"blank" forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? forall a. Eq a => a -> a -> Maybe a
justNonDef FilterByBlank
DontFilterByBlank FilterByBlank
filterBlank]
in Name -> [(Name, Text)] -> [Element] -> Element
elementList
(Text -> Name
n_ Text
"filters") [(Name, Text)]
attrs forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map FilterCriterion -> Element
filterCriterionToElement [FilterCriterion]
filterCriteria
fltColToElement (ColorFilter ColorFilterOptions
opts) = forall a. ToElement a => Name -> a -> Element
toElement (Text -> Name
n_ Text
"colorFilter") ColorFilterOptions
opts
fltColToElement (ACustomFilter CustomFilter
f) =
Name -> [Element] -> Element
elementListSimple (Text -> Name
n_ Text
"customFilters") [forall a. ToElement a => Name -> a -> Element
toElement (Text -> Name
n_ Text
"customFilter") CustomFilter
f]
fltColToElement (CustomFiltersOr CustomFilter
f1 CustomFilter
f2) =
Name -> [Element] -> Element
elementListSimple
(Text -> Name
n_ Text
"customFilters")
[forall a. ToElement a => Name -> a -> Element
toElement (Text -> Name
n_ Text
"customFilter") CustomFilter
f | CustomFilter
f <- [CustomFilter
f1, CustomFilter
f2]]
fltColToElement (CustomFiltersAnd CustomFilter
f1 CustomFilter
f2) =
Name -> [(Name, Text)] -> [Element] -> Element
elementList
(Text -> Name
n_ Text
"customFilters")
[Name
"and" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Bool
True]
[forall a. ToElement a => Name -> a -> Element
toElement (Text -> Name
n_ Text
"customFilter") CustomFilter
f | CustomFilter
f <- [CustomFilter
f1, CustomFilter
f2]]
fltColToElement (DynamicFilter DynFilterOptions
opts) = forall a. ToElement a => Name -> a -> Element
toElement (Text -> Name
n_ Text
"dynamicFilter") DynFilterOptions
opts
fltColToElement (IconFilter Maybe Int
iconId IconSetType
iconSet) =
Name -> [(Name, Text)] -> Element
leafElement (Text -> Name
n_ Text
"iconFilter") forall a b. (a -> b) -> a -> b
$
[Name
"iconSet" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= IconSetType
iconSet] forall a. [a] -> [a] -> [a]
++ forall a. [Maybe a] -> [a]
catMaybes [Name
"iconId" forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Maybe Int
iconId]
fltColToElement (BottomNFilter EdgeFilterOptions
opts) = Bool -> EdgeFilterOptions -> Element
edgeFilter Bool
False EdgeFilterOptions
opts
fltColToElement (TopNFilter EdgeFilterOptions
opts) = Bool -> EdgeFilterOptions -> Element
edgeFilter Bool
True EdgeFilterOptions
opts
edgeFilter :: Bool -> EdgeFilterOptions -> Element
edgeFilter :: Bool -> EdgeFilterOptions -> Element
edgeFilter Bool
top EdgeFilterOptions {Bool
Double
Maybe Double
_efoFilterVal :: Maybe Double
_efoVal :: Double
_efoUsePercents :: Bool
_efoFilterVal :: EdgeFilterOptions -> Maybe Double
_efoVal :: EdgeFilterOptions -> Double
_efoUsePercents :: EdgeFilterOptions -> Bool
..} =
Name -> [(Name, Text)] -> Element
leafElement (Text -> Name
n_ Text
"top10") forall a b. (a -> b) -> a -> b
$
[Name
"top" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Bool
top, Name
"percent" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Bool
_efoUsePercents, Name
"val" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Double
_efoVal] forall a. [a] -> [a] -> [a]
++
forall a. [Maybe a] -> [a]
catMaybes [Name
"filterVal" forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Maybe Double
_efoFilterVal]
filterCriterionToElement :: FilterCriterion -> Element
filterCriterionToElement :: FilterCriterion -> Element
filterCriterionToElement (FilterValue Text
v) =
Name -> [(Name, Text)] -> Element
leafElement (Text -> Name
n_ Text
"filter") [Name
"val" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Text
v]
filterCriterionToElement (FilterDateGroup (DateGroupByYear Int
y)) =
Name -> [(Name, Text)] -> Element
leafElement
(Text -> Name
n_ Text
"dateGroupItem")
[Name
"dateTimeGrouping" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= (Text
"year" :: Text), Name
"year" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
y]
filterCriterionToElement (FilterDateGroup (DateGroupByMonth Int
y Int
m)) =
Name -> [(Name, Text)] -> Element
leafElement
(Text -> Name
n_ Text
"dateGroupItem")
[Name
"dateTimeGrouping" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= (Text
"month" :: Text), Name
"year" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
y, Name
"month" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
m]
filterCriterionToElement (FilterDateGroup (DateGroupByDay Int
y Int
m Int
d)) =
Name -> [(Name, Text)] -> Element
leafElement
(Text -> Name
n_ Text
"dateGroupItem")
[Name
"dateTimeGrouping" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= (Text
"day" :: Text), Name
"year" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
y, Name
"month" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
m, Name
"day" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
d]
filterCriterionToElement (FilterDateGroup (DateGroupByHour Int
y Int
m Int
d Int
h)) =
Name -> [(Name, Text)] -> Element
leafElement
(Text -> Name
n_ Text
"dateGroupItem")
[ Name
"dateTimeGrouping" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= (Text
"hour" :: Text)
, Name
"year" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
y
, Name
"month" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
m
, Name
"day" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
d
, Name
"hour" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
h
]
filterCriterionToElement (FilterDateGroup (DateGroupByMinute Int
y Int
m Int
d Int
h Int
mi)) =
Name -> [(Name, Text)] -> Element
leafElement
(Text -> Name
n_ Text
"dateGroupItem")
[ Name
"dateTimeGrouping" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= (Text
"minute" :: Text)
, Name
"year" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
y
, Name
"month" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
m
, Name
"day" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
d
, Name
"hour" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
h
, Name
"minute" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
mi
]
filterCriterionToElement (FilterDateGroup (DateGroupBySecond Int
y Int
m Int
d Int
h Int
mi Int
s)) =
Name -> [(Name, Text)] -> Element
leafElement
(Text -> Name
n_ Text
"dateGroupItem")
[ Name
"dateTimeGrouping" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= (Text
"second" :: Text)
, Name
"year" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
y
, Name
"month" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
m
, Name
"day" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
d
, Name
"hour" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
h
, Name
"minute" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
mi
, Name
"second" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Int
s
]
instance ToElement CustomFilter where
toElement :: Name -> CustomFilter -> Element
toElement Name
nm CustomFilter {Text
CustomFilterOperator
cfltValue :: Text
cfltOperator :: CustomFilterOperator
cfltValue :: CustomFilter -> Text
cfltOperator :: CustomFilter -> CustomFilterOperator
..} =
Name -> [(Name, Text)] -> Element
leafElement Name
nm [Name
"operator" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= CustomFilterOperator
cfltOperator, Name
"val" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Text
cfltValue]
instance ToAttrVal CustomFilterOperator where
toAttrVal :: CustomFilterOperator -> Text
toAttrVal CustomFilterOperator
FltrEqual = Text
"equal"
toAttrVal CustomFilterOperator
FltrGreaterThan = Text
"greaterThan"
toAttrVal CustomFilterOperator
FltrGreaterThanOrEqual = Text
"greaterThanOrEqual"
toAttrVal CustomFilterOperator
FltrLessThan = Text
"lessThan"
toAttrVal CustomFilterOperator
FltrLessThanOrEqual = Text
"lessThanOrEqual"
toAttrVal CustomFilterOperator
FltrNotEqual = Text
"notEqual"
instance ToAttrVal FilterByBlank where
toAttrVal :: FilterByBlank -> Text
toAttrVal FilterByBlank
FilterByBlank = forall a. ToAttrVal a => a -> Text
toAttrVal Bool
True
toAttrVal FilterByBlank
DontFilterByBlank = forall a. ToAttrVal a => a -> Text
toAttrVal Bool
False
instance ToElement ColorFilterOptions where
toElement :: Name -> ColorFilterOptions -> Element
toElement Name
nm ColorFilterOptions {Bool
Maybe Int
_cfoDxfId :: Maybe Int
_cfoCellColor :: Bool
_cfoDxfId :: ColorFilterOptions -> Maybe Int
_cfoCellColor :: ColorFilterOptions -> Bool
..} =
Name -> [(Name, Text)] -> Element
leafElement Name
nm forall a b. (a -> b) -> a -> b
$
forall a. [Maybe a] -> [a]
catMaybes [Name
"cellColor" forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Bool -> Maybe Bool
justFalse Bool
_cfoCellColor, Name
"dxfId" forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Maybe Int
_cfoDxfId]
instance ToElement DynFilterOptions where
toElement :: Name -> DynFilterOptions -> Element
toElement Name
nm DynFilterOptions {Maybe Double
DynFilterType
_dfoMaxVal :: Maybe Double
_dfoVal :: Maybe Double
_dfoType :: DynFilterType
_dfoMaxVal :: DynFilterOptions -> Maybe Double
_dfoVal :: DynFilterOptions -> Maybe Double
_dfoType :: DynFilterOptions -> DynFilterType
..} =
Name -> [(Name, Text)] -> Element
leafElement Name
nm forall a b. (a -> b) -> a -> b
$
[Name
"type" forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= DynFilterType
_dfoType] forall a. [a] -> [a] -> [a]
++
forall a. [Maybe a] -> [a]
catMaybes [Name
"val" forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Maybe Double
_dfoVal, Name
"maxVal" forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Maybe Double
_dfoMaxVal]
instance ToAttrVal DynFilterType where
toAttrVal :: DynFilterType -> Text
toAttrVal DynFilterType
DynFilterAboveAverage = Text
"aboveAverage"
toAttrVal DynFilterType
DynFilterBelowAverage = Text
"belowAverage"
toAttrVal DynFilterType
DynFilterLastMonth = Text
"lastMonth"
toAttrVal DynFilterType
DynFilterLastQuarter = Text
"lastQuarter"
toAttrVal DynFilterType
DynFilterLastWeek = Text
"lastWeek"
toAttrVal DynFilterType
DynFilterLastYear = Text
"lastYear"
toAttrVal DynFilterType
DynFilterM1 = Text
"M1"
toAttrVal DynFilterType
DynFilterM10 = Text
"M10"
toAttrVal DynFilterType
DynFilterM11 = Text
"M11"
toAttrVal DynFilterType
DynFilterM12 = Text
"M12"
toAttrVal DynFilterType
DynFilterM2 = Text
"M2"
toAttrVal DynFilterType
DynFilterM3 = Text
"M3"
toAttrVal DynFilterType
DynFilterM4 = Text
"M4"
toAttrVal DynFilterType
DynFilterM5 = Text
"M5"
toAttrVal DynFilterType
DynFilterM6 = Text
"M6"
toAttrVal DynFilterType
DynFilterM7 = Text
"M7"
toAttrVal DynFilterType
DynFilterM8 = Text
"M8"
toAttrVal DynFilterType
DynFilterM9 = Text
"M9"
toAttrVal DynFilterType
DynFilterNextMonth = Text
"nextMonth"
toAttrVal DynFilterType
DynFilterNextQuarter = Text
"nextQuarter"
toAttrVal DynFilterType
DynFilterNextWeek = Text
"nextWeek"
toAttrVal DynFilterType
DynFilterNextYear = Text
"nextYear"
toAttrVal DynFilterType
DynFilterNull = Text
"null"
toAttrVal DynFilterType
DynFilterQ1 = Text
"Q1"
toAttrVal DynFilterType
DynFilterQ2 = Text
"Q2"
toAttrVal DynFilterType
DynFilterQ3 = Text
"Q3"
toAttrVal DynFilterType
DynFilterQ4 = Text
"Q4"
toAttrVal DynFilterType
DynFilterThisMonth = Text
"thisMonth"
toAttrVal DynFilterType
DynFilterThisQuarter = Text
"thisQuarter"
toAttrVal DynFilterType
DynFilterThisWeek = Text
"thisWeek"
toAttrVal DynFilterType
DynFilterThisYear = Text
"thisYear"
toAttrVal DynFilterType
DynFilterToday = Text
"today"
toAttrVal DynFilterType
DynFilterTomorrow = Text
"tomorrow"
toAttrVal DynFilterType
DynFilterYearToDate = Text
"yearToDate"
toAttrVal DynFilterType
DynFilterYesterday = Text
"yesterday"