Commit 77c4095c authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FEAT] Cumulative private and social lists (WIP)

parent 4eb0b1c2
...@@ -294,7 +294,7 @@ pairWith cId aId lId = do ...@@ -294,7 +294,7 @@ pairWith cId aId lId = do
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 = tree Advanced treeAPI = tree TreeAdvanced
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | TODO Check if the name is less than 255 char -- | TODO Check if the name is less than 255 char
......
{-|
Module : Gargantext.Core.Text.List.Social
Description :
Copyright : (c) CNRS, 2018-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
-}
module Gargantext.Core.Text.List.Social
where
import Gargantext.Database.Prelude
import Gargantext.Database.Query.Tree
import Gargantext.Database.Query.Tree.Root (getRootId)
import Gargantext.Core.Types.Individu
import Gargantext.Database.Admin.Types.Node
import Gargantext.Prelude
import Gargantext.Database.Query.Table.Node.Error
import Gargantext.Database.Admin.Config
findListsId :: (HasNodeError err, HasTreeError err) => NodeMode -> User -> Cmd err [NodeId]
findListsId mode u = do
r <- getRootId u
map _dt_nodeId <$> filter (\n -> _dt_typeId n == nodeTypeId NodeList)
<$> findNodes' mode r
findNodes' :: HasTreeError err
=> NodeMode -> RootId
-> Cmd err [DbTreeNode]
findNodes' Private r = findNodes Private r [NodeFolderPrivate, NodeCorpus, NodeList]
findNodes' Shared r = findNodes Shared r [NodeFolderShared, NodeCorpus, NodeList]
findNodes' Public r = findNodes Public r [NodeFolderPublic, NodeCorpus, NodeList]
...@@ -42,9 +42,10 @@ getUserId UserPublic = nodeError NoUserFound ...@@ -42,9 +42,10 @@ getUserId UserPublic = nodeError NoUserFound
-- | Username = Text -- | Username = Text
-- UserName is User -- UserName is User
-- that is confusing, we should change this -- that is confusing, we should change this
type Username = Text
getUsername :: HasNodeError err getUsername :: HasNodeError err
=> User => User
-> Cmd err Text -> Cmd err Username
getUsername (UserName u) = pure u getUsername (UserName u) = pure u
getUsername (UserDBId i) = do getUsername (UserDBId i) = do
users <- getUsersWithId i users <- getUsersWithId i
......
...@@ -29,6 +29,8 @@ module Gargantext.Database.Query.Tree ...@@ -29,6 +29,8 @@ module Gargantext.Database.Query.Tree
, dt_nodeId , dt_nodeId
, dt_typeId , dt_typeId
, findShared , findShared
, findNodes
, NodeMode(..)
) )
where where
...@@ -62,7 +64,7 @@ instance Eq DbTreeNode where ...@@ -62,7 +64,7 @@ instance Eq DbTreeNode where
------------------------------------------------------------------------ ------------------------------------------------------------------------
data TreeMode = Basic | Advanced data TreeMode = TreeBasic | TreeAdvanced
-- | Returns the Tree of Nodes in Database -- | Returns the Tree of Nodes in Database
tree :: HasTreeError err tree :: HasTreeError err
...@@ -70,8 +72,8 @@ tree :: HasTreeError err ...@@ -70,8 +72,8 @@ tree :: HasTreeError err
-> RootId -> RootId
-> [NodeType] -> [NodeType]
-> Cmd err (Tree NodeTree) -> Cmd err (Tree NodeTree)
tree Basic = tree_basic tree TreeBasic = tree_basic
tree Advanced = tree_advanced tree TreeAdvanced = tree_advanced
-- | Tree basic returns the Tree of Nodes in Database -- | Tree basic returns the Tree of Nodes in Database
-- (without shared folders) -- (without shared folders)
...@@ -91,11 +93,23 @@ tree_advanced :: HasTreeError err ...@@ -91,11 +93,23 @@ tree_advanced :: HasTreeError err
-> [NodeType] -> [NodeType]
-> Cmd err (Tree NodeTree) -> Cmd err (Tree NodeTree)
tree_advanced r nodeTypes = do tree_advanced r nodeTypes = do
mainRoot <- dbTree r nodeTypes mainRoot <- findNodes Private r nodeTypes
sharedRoots <- findShared r NodeFolderShared nodeTypes sharedTreeUpdate sharedRoots <- findNodes Shared r nodeTypes
publicRoots <- findShared r NodeFolderPublic nodeTypes publicTreeUpdate publicRoots <- findNodes Public r nodeTypes
toTree $ toTreeParent (mainRoot <> sharedRoots <> publicRoots) toTree $ toTreeParent (mainRoot <> sharedRoots <> publicRoots)
------------------------------------------------------------------------
data NodeMode = Private | Shared | Public
findNodes :: HasTreeError err
=> NodeMode
-> RootId -> [NodeType]
-> Cmd err [DbTreeNode]
findNodes Private r nt = dbTree r nt
findNodes Shared r nt = findShared r NodeFolderShared nt sharedTreeUpdate
findNodes Public r nt = findShared r NodeFolderPublic nt publicTreeUpdate
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | Collaborative Nodes in the Tree -- | Collaborative Nodes in the Tree
findShared :: HasTreeError err findShared :: HasTreeError err
......
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