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 {-# OPTIONS_GHC -fno-warn-orphans #-}
19 module Gargantext.Database.Admin.Config
22 import Control.Lens (view)
23 import Data.List (lookup)
24 import Data.Maybe (fromMaybe)
25 import Data.Text (Text,pack)
26 import Data.Tuple.Extra (swap)
27 import Gargantext.Core (HasDBid(..))
28 import Gargantext.Database.Admin.Types.Node
29 import Gargantext.Database.Schema.Node
30 import Gargantext.Prelude
32 -- TODO put this in config.ini file
33 corpusMasterName :: Text
34 corpusMasterName = "Main"
37 userMaster = "gargantua"
40 userArbitrary = "user1"
42 instance HasDBid NodeType where
44 fromDBid = fromNodeTypeId
47 nodeTypeId :: NodeType -> NodeTypeId
52 NodeFolderPrivate -> 20
53 NodeFolderShared -> 21
55 NodeFolderPublic -> 22
70 -- NodeOccurrences -> 10
81 NodeFrameNotebook -> 993
97 -- NodeFavorites -> 15
99 hasNodeType :: forall a. Node a -> NodeType -> Bool
100 hasNodeType n nt = (view node_typename n) == (toDBid nt)
102 isInNodeTypes :: forall a. Node a -> [NodeType] -> Bool
103 isInNodeTypes n ts = elem (view node_typename n) (map toDBid ts)
105 -- | Nodes are typed in the database according to a specific ID
107 nodeTypeInv :: [(NodeTypeId, NodeType)]
108 nodeTypeInv = map swap nodeTypes
110 nodeTypes :: [(NodeType, NodeTypeId)]
111 nodeTypes = [ (n, toDBid n) | n <- allNodeTypes ]
113 fromNodeTypeId :: NodeTypeId -> NodeType
114 fromNodeTypeId tId = fromMaybe (panic $ pack $ "Type Id " <> show tId <> " does not exist")
115 (lookup tId nodeTypeInv)