Commit 79e4ca7a authored by Alexandre Delanoë's avatar Alexandre Delanoë

[REFACT] tree

parent 569f45ee
Pipeline #876 failed with stage
......@@ -52,7 +52,7 @@ import Gargantext.Database.Query.Table.Node
import Gargantext.Database.Query.Table.Node.Children (getChildren)
import Gargantext.Database.Query.Table.Node.UpdateOpaleye (updateHyperdata)
import Gargantext.Database.Query.Table.Node.User
import Gargantext.Database.Query.Tree (treeDB)
import Gargantext.Database.Query.Tree (tree, TreeMode(..))
import Gargantext.Database.Admin.Config (nodeTypeId)
import Gargantext.Database.Query.Table.Node.Error (HasNodeError(..))
import Gargantext.Database.Admin.Types.Node
......@@ -310,7 +310,7 @@ type TreeApi = Summary " Tree API"
type TreeAPI = QueryParams "type" NodeType :> Get '[JSON] (Tree NodeTree)
treeAPI :: NodeId -> GargServer TreeAPI
treeAPI = treeDB
treeAPI = tree Advanced
------------------------------------------------------------------------
-- | Check if the name is less than 255 char
......
......@@ -7,10 +7,8 @@ Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
-}
module Gargantext.Database.Action.Share
where
......
......@@ -21,8 +21,8 @@ module Gargantext.Database.Query.Tree
( module Gargantext.Database.Query.Tree.Error
, isDescendantOf
, isIn
, treeDB
, treeDB'
, tree
, TreeMode(..)
, findNodesId
, DbTreeNode(..)
, dt_name
......@@ -58,23 +58,36 @@ data DbTreeNode = DbTreeNode { _dt_nodeId :: NodeId
makeLenses ''DbTreeNode
------------------------------------------------------------------------
data TreeMode = Basic | Advanced
-- | Returns the Tree of Nodes in Database
tree :: HasTreeError err
=> TreeMode
-> RootId
-> [NodeType]
-> Cmd err (Tree NodeTree)
tree Basic = tree_basic
tree Advanced = tree_advanced
-- | Tree basic returns the Tree of Nodes in Database
-- (without shared folders)
-- keeping this for teaching purpose only
treeDB' :: HasTreeError err
tree_basic :: HasTreeError err
=> RootId
-> [NodeType]
-> Cmd err (Tree NodeTree)
treeDB' r nodeTypes =
tree_basic r nodeTypes =
(dbTree r nodeTypes <&> toTreeParent) >>= toTree
-- Same as (but easier to read) :
-- toTree =<< (toTreeParent <$> dbTree r nodeTypes)
treeDB :: HasTreeError err
-- | Advanced mode of the Tree enables shared nodes
tree_advanced :: HasTreeError err
=> RootId
-> [NodeType]
-> Cmd err (Tree NodeTree)
treeDB r nodeTypes = do
tree_advanced r nodeTypes = do
mainRoot <- dbTree r nodeTypes
sharedRoots <- findShared r nodeTypes
toTree $ toTreeParent (mainRoot <> sharedRoots)
......
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