-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+
module Gargantext.Database.Admin.Config
where
import Data.Maybe (fromMaybe)
import Data.Text (Text,pack)
import Data.Tuple.Extra (swap)
+import Gargantext.Core (HasDBid(..))
import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Schema.Node
import Gargantext.Prelude
userArbitrary :: Text
userArbitrary = "user1"
+instance HasDBid NodeType where
+ toDBid = nodeTypeId
+ fromDBid = fromNodeTypeId
+
+
nodeTypeId :: NodeType -> NodeTypeId
nodeTypeId n =
case n of
NodeFile -> 101
- NodeFrameWrite -> 991
- NodeFrameCalc -> 992
+ NodeFrameWrite -> 991
+ NodeFrameCalc -> 992
+ NodeFrameNotebook -> 993
+ NodeFrameVisio -> 994
-- Cooccurrences -> 9
--
-- NodeFavorites -> 15
hasNodeType :: forall a. Node a -> NodeType -> Bool
-hasNodeType n nt = (view node_typename n) == (nodeTypeId nt)
+hasNodeType n nt = (view node_typename n) == (toDBid nt)
isInNodeTypes :: forall a. Node a -> [NodeType] -> Bool
-isInNodeTypes n ts = elem (view node_typename n) (map nodeTypeId ts)
+isInNodeTypes n ts = elem (view node_typename n) (map toDBid ts)
-- | Nodes are typed in the database according to a specific ID
--
nodeTypeInv = map swap nodeTypes
nodeTypes :: [(NodeType, NodeTypeId)]
-nodeTypes = [ (n, nodeTypeId n) | n <- allNodeTypes ]
+nodeTypes = [ (n, toDBid n) | n <- allNodeTypes ]
fromNodeTypeId :: NodeTypeId -> NodeType
fromNodeTypeId tId = fromMaybe (panic $ pack $ "Type Id " <> show tId <> " does not exist")