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