Commit d89f060c authored by Alexandre Delanoë's avatar Alexandre Delanoë

[Community] Annuaire added, ok.

parent af2155c3
...@@ -18,9 +18,9 @@ library: ...@@ -18,9 +18,9 @@ library:
ghc-options: ghc-options:
- -Wincomplete-uni-patterns - -Wincomplete-uni-patterns
- -Wincomplete-record-updates - -Wincomplete-record-updates
- -Wmissing-signatures #- -Wmissing-signatures
- -Wunused-binds #- -Wunused-binds
- -Wunused-imports #- -Wunused-imports
# - -Werror # - -Werror
exposed-modules: exposed-modules:
- Gargantext - Gargantext
...@@ -143,18 +143,6 @@ executables: ...@@ -143,18 +143,6 @@ executables:
- optparse-generic - optparse-generic
- unordered-containers - unordered-containers
- full-text-search - full-text-search
gargantext-workflow:
main: Main.hs
source-dirs: app-workflow
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
- -O2
- -Wmissing-signatures
dependencies:
- base
- gargantext
tests: tests:
garg-test: garg-test:
......
...@@ -118,9 +118,11 @@ type Notebook = Node HyperdataNotebook ...@@ -118,9 +118,11 @@ type Notebook = Node HyperdataNotebook
nodeTypes :: [(NodeType, NodeTypeId)] nodeTypes :: [(NodeType, NodeTypeId)]
nodeTypes = [ (NodeUser , 1) nodeTypes = [ (NodeUser , 1)
, (Project , 2) , (Folder , 2)
, (Corpus , 3) , (Corpus , 30)
, (Document , 4) , (Annuaire , 31)
, (Document , 40)
, (UserPage , 41)
--, (NodeSwap , 19) --, (NodeSwap , 19)
------ Lists ------ Lists
-- , (StopList , 5) -- , (StopList , 5)
......
...@@ -236,7 +236,7 @@ type Corpus = Node HyperdataCorpus ...@@ -236,7 +236,7 @@ type Corpus = Node HyperdataCorpus
type Document = Node HyperdataDocument type Document = Node HyperdataDocument
------------------------------------------------------------------------ ------------------------------------------------------------------------
data NodeType = NodeUser | Project | Corpus | Document | DocumentCopy data NodeType = NodeUser | Project | Folder | Corpus | Annuaire | Document | UserPage | DocumentCopy
| Classification | Classification
| Lists | Lists
| Metrics | Occurrences | Metrics | Occurrences
......
...@@ -63,6 +63,7 @@ module Gargantext.Database ( module Gargantext.Database.Utils ...@@ -63,6 +63,7 @@ module Gargantext.Database ( module Gargantext.Database.Utils
, post, post' , post, post'
, del , del' , del , del'
, tree, tree' , tree, tree'
, postCorpus, postAnnuaire
) )
where where
...@@ -72,7 +73,7 @@ import Gargantext.Database.Utils (connectGargandb) ...@@ -72,7 +73,7 @@ import Gargantext.Database.Utils (connectGargandb)
import Gargantext.Database.Node import Gargantext.Database.Node
import Gargantext.Prelude import Gargantext.Prelude
import Database.PostgreSQL.Simple (Connection) import Database.PostgreSQL.Simple (Connection)
import Data.Text (Text) import Data.Text (Text, pack)
import Opaleye hiding (FromField) import Opaleye hiding (FromField)
import Data.Aeson import Data.Aeson
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
...@@ -160,12 +161,36 @@ post' = do ...@@ -160,12 +161,36 @@ post' = do
c <- connectGargandb "gargantext.ini" c <- connectGargandb "gargantext.ini"
pid <- last <$> home c pid <- last <$> home c
let uid = 1 let uid = 1
postNode c uid pid (Node' Corpus "Premier corpus" "{}" [ Node' Document "Doc1" "{}" [] postNode c uid pid ( Node' Corpus (pack "Premier corpus") (toJSON ("{}"::Text)) [ Node' Document (pack "Doc1") (toJSON ("{}" :: Text)) []
, Node' Document "Doc2" "{}" [] , Node' Document (pack "Doc2") (toJSON (pack "{}" :: Text)) []
, Node' Document "Doc3" "{}" [] , Node' Document (pack "Doc3") (toJSON ("{}" :: Text)) []
] ]
) )
type CorpusName = Text
postCorpus :: ToJSON a => CorpusName -> (a -> Text) -> [a] -> IO [Int]
postCorpus corpusName title ns = do
c <- connectGargandb "gargantext.ini"
pid <- last <$> home c
let uid = 1
postNode c uid pid ( Node' Corpus corpusName (toJSON ("{}"::Text))
(map (\n -> Node' Document (title n) (toJSON n) []) ns)
)
-- |
-- import IMTClient as C
-- postAnnuaire "Annuaire IMT" (\n -> (maybe "" identity (C.prenom n)) <> " " <> (maybe "" identity (C.nom n))) (take 30 annuaire)
postAnnuaire :: ToJSON a => CorpusName -> (a -> Text) -> [a] -> IO [Int]
postAnnuaire corpusName title ns = do
c <- connectGargandb "gargantext.ini"
pid <- last <$> home c
let uid = 1
postNode c uid pid ( Node' Annuaire corpusName (toJSON ("{}"::Text))
(map (\n -> Node' UserPage (title n) (toJSON n) []) ns)
)
del' :: [NodeId] -> IO Int del' :: [NodeId] -> IO Int
del' ns = do del' ns = do
......
...@@ -45,7 +45,7 @@ import Control.Arrow (returnA) ...@@ -45,7 +45,7 @@ import Control.Arrow (returnA)
import Control.Lens.TH (makeLensesWith, abbreviatedFields) import Control.Lens.TH (makeLensesWith, abbreviatedFields)
import Data.Aeson import Data.Aeson
import Data.Maybe (Maybe, fromMaybe) import Data.Maybe (Maybe, fromMaybe)
import Data.Text (Text) import Data.Text (Text, pack)
import Data.Profunctor.Product.TH (makeAdaptorAndInstance) import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
import Data.Typeable (Typeable) import Data.Typeable (Typeable)
...@@ -288,7 +288,7 @@ post c uid pid [ Node' Corpus "name" "{}" [] ...@@ -288,7 +288,7 @@ post c uid pid [ Node' Corpus "name" "{}" []
node2table :: UserId -> ParentId -> Node' -> [NodeWriteT] node2table :: UserId -> ParentId -> Node' -> [NodeWriteT]
node2table uid pid (Node' nt txt v []) = [( Nothing, (pgInt4$ nodeTypeId nt), (pgInt4 uid), (pgInt4 pid) node2table uid pid (Node' nt txt v []) = [( Nothing, (pgInt4$ nodeTypeId nt), (pgInt4 uid), (pgInt4 pid)
, pgStrictText txt, Nothing, pgStrictJSONB $ DB.pack $ DBL.unpack $ encode v)] , pgStrictText txt, Nothing, pgStrictJSONB $ DB.pack $ DBL.unpack $ encode v)]
node2table _ _ (Node' _ _ _ _) = panic "node2table: should not happen, Tree insert not implemented yet" node2table _ _ (Node' _ _ _ _) = panic $ pack "node2table: should not happen, Tree insert not implemented yet"
data Node' = Node' { _n_type :: NodeType data Node' = Node' { _n_type :: NodeType
...@@ -318,7 +318,11 @@ postNode c uid pid (Node' Corpus txt v ns) = do ...@@ -318,7 +318,11 @@ postNode c uid pid (Node' Corpus txt v ns) = do
[pid'] <- postNode c uid pid (Node' Corpus txt v []) [pid'] <- postNode c uid pid (Node' Corpus txt v [])
pids <- mkNodeR' c $ concat $ (map (\(Node' Document txt v _) -> node2table uid pid' $ Node' Document txt v []) ns) pids <- mkNodeR' c $ concat $ (map (\(Node' Document txt v _) -> node2table uid pid' $ Node' Document txt v []) ns)
pure (pids) pure (pids)
postNode c uid pid (Node' _ _ _ _) = panic "postNode for this type not implemented yet" postNode c uid pid (Node' Annuaire txt v ns) = do
[pid'] <- postNode c uid pid (Node' Annuaire txt v [])
pids <- mkNodeR' c $ concat $ (map (\(Node' UserPage txt v _) -> node2table uid pid' $ Node' UserPage txt v []) ns)
pure (pids)
postNode c uid pid (Node' _ _ _ _) = panic $ pack "postNode for this type not implemented yet"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment