2 Module : Gargantext.Database
3 Description : Tools for Database
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Target: just import this module and nothing else to work with
11 Gargantext's database.
13 TODO: configure nodes table in Haskell (Config typenames etc.)
17 module Gargantext.Database.Admin.Config
20 import Control.Lens (view)
21 import Data.List (lookup)
22 import Data.Maybe (fromMaybe)
23 import Data.Text (Text,pack)
24 import Data.Tuple.Extra (swap)
25 import Gargantext.Database.Admin.Types.Node
26 import Gargantext.Database.Schema.Node
27 import Gargantext.Prelude
29 -- TODO put this in config.ini file
30 corpusMasterName :: Text
31 corpusMasterName = "Main"
34 userMaster = "gargantua"
37 userArbitrary = "user1"
39 nodeTypeId :: NodeType -> NodeTypeId
44 NodeFolderPrivate -> 20
45 NodeFolderShared -> 21
47 NodeFolderPublic -> 22
62 -- NodeOccurrences -> 10
73 NodeFrameNotebook -> 993
88 -- NodeFavorites -> 15
90 hasNodeType :: forall a. Node a -> NodeType -> Bool
91 hasNodeType n nt = (view node_typename n) == (nodeTypeId nt)
93 isInNodeTypes :: forall a. Node a -> [NodeType] -> Bool
94 isInNodeTypes n ts = elem (view node_typename n) (map nodeTypeId ts)
96 -- | Nodes are typed in the database according to a specific ID
98 nodeTypeInv :: [(NodeTypeId, NodeType)]
99 nodeTypeInv = map swap nodeTypes
101 nodeTypes :: [(NodeType, NodeTypeId)]
102 nodeTypes = [ (n, nodeTypeId n) | n <- allNodeTypes ]
104 fromNodeTypeId :: NodeTypeId -> NodeType
105 fromNodeTypeId tId = fromMaybe (panic $ pack $ "Type Id " <> show tId <> " does not exist")
106 (lookup tId nodeTypeInv)