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