]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Admin/Config.hs
[MIGRATION] gargantext-upgrade can be used.
[gargantext.git] / src / Gargantext / Database / Admin / Config.hs
1 {-|
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
8 Portability : POSIX
9
10 Target: just import this module and nothing else to work with
11 Gargantext's database.
12
13 TODO: configure nodes table in Haskell (Config typenames etc.)
14 -}
15
16
17 {-# OPTIONS_GHC -fno-warn-orphans #-}
18
19 module Gargantext.Database.Admin.Config
20 where
21
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
31
32 -- TODO put this in config.ini file
33 corpusMasterName :: Text
34 corpusMasterName = "Main"
35
36 userMaster :: Text
37 userMaster = "gargantua"
38
39 userArbitrary :: Text
40 userArbitrary = "user1"
41
42 instance HasDBid NodeType where
43 toDBid = nodeTypeId
44 fromDBid = fromNodeTypeId
45
46
47 nodeTypeId :: NodeType -> NodeTypeId
48 nodeTypeId n =
49 case n of
50 NodeUser -> 1
51 NodeFolder -> 2
52 NodeFolderPrivate -> 20
53 NodeFolderShared -> 21
54 NodeTeam -> 210
55 NodeFolderPublic -> 22
56 NodeCorpusV3 -> 3
57 NodeCorpus -> 30
58 NodeAnnuaire -> 31
59 NodeTexts -> 40
60 NodeDocument -> 4
61 NodeContact -> 41
62 --NodeSwap -> 19
63
64 ---- Lists
65 NodeList -> 5
66 NodeListCooc -> 50
67 NodeModel -> 52
68
69 ---- Scores
70 -- NodeOccurrences -> 10
71 NodeGraph -> 9
72 NodePhylo -> 90
73 -- NodeChart -> 7
74 NodeDashboard -> 71
75 -- NodeNoteBook -> 88
76
77 NodeFile -> 101
78
79 NodeFrameWrite -> 991
80 NodeFrameCalc -> 992
81 NodeFrameNotebook -> 993
82 NodeFrameVisio -> 994
83
84 -- Cooccurrences -> 9
85 --
86 -- Specclusion -> 11
87 -- Genclusion -> 18
88 -- Cvalue -> 12
89 --
90 -- TfidfCorpus -> 13
91 -- TfidfGlobal -> 14
92 --
93 -- TirankLocal -> 16
94 -- TirankGlobal -> 17
95
96 -- Node management
97 -- NodeFavorites -> 15
98
99 hasNodeType :: forall a. Node a -> NodeType -> Bool
100 hasNodeType n nt = (view node_typename n) == (toDBid nt)
101
102 isInNodeTypes :: forall a. Node a -> [NodeType] -> Bool
103 isInNodeTypes n ts = elem (view node_typename n) (map toDBid ts)
104
105 -- | Nodes are typed in the database according to a specific ID
106 --
107 nodeTypeInv :: [(NodeTypeId, NodeType)]
108 nodeTypeInv = map swap nodeTypes
109
110 nodeTypes :: [(NodeType, NodeTypeId)]
111 nodeTypes = [ (n, toDBid n) | n <- allNodeTypes ]
112
113 fromNodeTypeId :: NodeTypeId -> NodeType
114 fromNodeTypeId tId = fromMaybe (panic $ pack $ "Type Id " <> show tId <> " does not exist")
115 (lookup tId nodeTypeInv)
116