Commit 69f83025 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[REFACT] organize funs (WIP)

parent 1c082d54
...@@ -2,7 +2,7 @@ module Gargantext.Components.Forest.Tree where ...@@ -2,7 +2,7 @@ module Gargantext.Components.Forest.Tree where
import DOM.Simple.Console (log, log2) import DOM.Simple.Console (log, log2)
import Data.Array as A import Data.Array as A
import Data.Maybe (Maybe) import Data.Maybe (Maybe(..))
import Data.Set as Set import Data.Set as Set
import Data.Tuple (Tuple(..), fst, snd) import Data.Tuple (Tuple(..), fst, snd)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
...@@ -12,7 +12,6 @@ import Gargantext.AsyncTasks as GAT ...@@ -12,7 +12,6 @@ import Gargantext.AsyncTasks as GAT
import Gargantext.Components.Forest.Tree.Node (nodeMainSpan) import Gargantext.Components.Forest.Tree.Node (nodeMainSpan)
import Gargantext.Components.Forest.Tree.Node.Action (Action(..)) import Gargantext.Components.Forest.Tree.Node.Action (Action(..))
import Gargantext.Components.Forest.Tree.Node.Action.Add (AddNodeValue(..), addNode) import Gargantext.Components.Forest.Tree.Node.Action.Add (AddNodeValue(..), addNode)
import Gargantext.Components.Forest.Tree.Node.Action.CopyFrom (getNodeTree)
import Gargantext.Components.Forest.Tree.Node.Action.Delete (deleteNode) import Gargantext.Components.Forest.Tree.Node.Action.Delete (deleteNode)
import Gargantext.Components.Forest.Tree.Node.Action.Rename (RenameValue(..), rename) import Gargantext.Components.Forest.Tree.Node.Action.Rename (RenameValue(..), rename)
import Gargantext.Components.Forest.Tree.Node.Action.Share (ShareValue(..), share) import Gargantext.Components.Forest.Tree.Node.Action.Share (ShareValue(..), share)
...@@ -24,8 +23,10 @@ import Gargantext.Ends (Frontends) ...@@ -24,8 +23,10 @@ import Gargantext.Ends (Frontends)
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude (Unit, bind, discard, map, pure, void, ($), (+), (<>)) import Gargantext.Prelude (Unit, bind, discard, map, pure, void, ($), (+), (<>))
import Gargantext.Routes (AppRoute) import Gargantext.Routes (AppRoute)
import Gargantext.Sessions (OpenNodes, Session, mkNodeId) import Gargantext.Sessions (OpenNodes, Session, mkNodeId, get)
import Gargantext.Types (ID, Reload) import Gargantext.Types (ID, Reload)
import Gargantext.Types as GT
import Gargantext.Routes as GR
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Record as Record import Record as Record
...@@ -95,6 +96,13 @@ treeLoadView p = R.createElement treeLoadViewCpt p [] ...@@ -95,6 +96,13 @@ treeLoadView p = R.createElement treeLoadViewCpt p []
} }
useLoader { root, counter: fst reload } fetch paint useLoader { root, counter: fst reload } fetch paint
--------------
getNodeTree :: Session -> GT.ID -> Aff FTree
getNodeTree session nodeId = get session $ GR.NodeAPI GT.Tree (Just nodeId) ""
--------------
type TreeViewProps = ( asyncTasks :: R.State GAT.Storage type TreeViewProps = ( asyncTasks :: R.State GAT.Storage
, tree :: FTree , tree :: FTree
, tasks :: Record Tasks , tasks :: Record Tasks
......
...@@ -19,7 +19,6 @@ type UpdateNodeProps = ...@@ -19,7 +19,6 @@ type UpdateNodeProps =
) )
-} -}
data Action = AddNode String GT.NodeType data Action = AddNode String GT.NodeType
| DeleteNode | DeleteNode
| RenameNode String | RenameNode String
...@@ -30,7 +29,6 @@ data Action = AddNode String GT.NodeType ...@@ -30,7 +29,6 @@ data Action = AddNode String GT.NodeType
| DownloadNode | DownloadNode
| RefreshTree | RefreshTree
instance showShow :: Show Action where instance showShow :: Show Action where
show (AddNode _ _ )= "AddNode" show (AddNode _ _ )= "AddNode"
show DeleteNode = "DeleteNode" show DeleteNode = "DeleteNode"
......
...@@ -19,17 +19,11 @@ import Reactix.DOM.HTML as H ...@@ -19,17 +19,11 @@ import Reactix.DOM.HTML as H
------------------------------------------------------------------------ ------------------------------------------------------------------------
getNodeTree :: Session -> GT.ID -> Aff FTree
getNodeTree session nodeId = get session $ GR.NodeAPI GT.Tree (Just nodeId) ""
------------------------------------------------------------------------
type SubTreeParamsProps = type SubTreeParamsProps =
( subTreeParams :: SubTreeParams ( subTreeParams :: SubTreeParams
| Props | Props
) )
copyFromCorpusView :: Record SubTreeParamsProps -> R.Element copyFromCorpusView :: Record SubTreeParamsProps -> R.Element
copyFromCorpusView props = R.createElement copyFromCorpusViewCpt props [] copyFromCorpusView props = R.createElement copyFromCorpusViewCpt props []
...@@ -55,8 +49,17 @@ copyFromCorpusViewCpt = R.hooksComponent "G.C.F.T.N.A.U.copyFromCorpusView" cpt ...@@ -55,8 +49,17 @@ copyFromCorpusViewCpt = R.hooksComponent "G.C.F.T.N.A.U.copyFromCorpusView" cpt
, subTreeParams , subTreeParams
} }
------------------------------------------------------------------------ loadSubTree :: Array GT.NodeType -> Session -> Aff FTree
loadSubTree nodetypes session = getSubTree session treeId nodetypes
where
Session { treeId } = session
getSubTree :: Session -> Int -> Array GT.NodeType -> Aff FTree
getSubTree session treeId showtypes = get session $ GR.NodeAPI GT.Tree (Just treeId) nodeTypes
where
nodeTypes = A.foldl (\a b -> a <> "type=" <> show b <> "&") "?" showtypes
------------------------------------------------------------------------
type CorpusTreeProps = type CorpusTreeProps =
( tree :: FTree ( tree :: FTree
| SubTreeParamsProps | SubTreeParamsProps
...@@ -91,10 +94,15 @@ copyFromCorpusTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.copyFromCorpusTreeVi ...@@ -91,10 +94,15 @@ copyFromCorpusTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.copyFromCorpusTreeVi
) )
-- ] -- ]
where where
SubTreeParams { valitypes } = subTreeParams SubTreeParams { valitypes } = subTreeParams
children = map (\c -> copyFromCorpusTreeView (p { tree = c })) ary children = map (\c -> copyFromCorpusTreeView (p { tree = c })) ary
validNodeType = (A.elem nodeType valitypes) && (id /= sourceId) validNodeType = (A.elem nodeType valitypes) && (id /= sourceId)
clickable = if validNodeType then "clickable" else "" clickable = if validNodeType then "clickable" else ""
onClick _ = case validNodeType of onClick _ = case validNodeType of
false -> pure unit false -> pure unit
true -> do true -> do
...@@ -102,14 +110,4 @@ copyFromCorpusTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.copyFromCorpusTreeVi ...@@ -102,14 +110,4 @@ copyFromCorpusTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.copyFromCorpusTreeVi
log2 "[copyFromCorpusTreeViewCpt] issue copy from" sourceId log2 "[copyFromCorpusTreeViewCpt] issue copy from" sourceId
-------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------
loadSubTree :: Array GT.NodeType -> Session -> Aff FTree
loadSubTree nodetypes session = getSubTree session treeId nodetypes
where
Session { treeId } = session
getSubTree :: Session -> Int -> Array GT.NodeType -> Aff FTree
getSubTree session treeId showtypes = get session $ GR.NodeAPI GT.Tree (Just treeId) nodeTypes
where
nodeTypes = A.foldl (\a b -> a <> "type=" <> show b <> "&") "?" showtypes
...@@ -238,6 +238,7 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt ...@@ -238,6 +238,7 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt
cpt {action: Config , dispatch, id, nodeType, session} _ = do cpt {action: Config , dispatch, id, nodeType, session} _ = do
pure $ fragmentPT $ "Config " <> show nodeType pure $ fragmentPT $ "Config " <> show nodeType
-----------
cpt {action: Merge {subTreeParams}, dispatch, id, nodeType, session} _ = do cpt {action: Merge {subTreeParams}, dispatch, id, nodeType, session} _ = do
pure $ copyFromCorpusView {dispatch, id, nodeType, session, subTreeParams} pure $ copyFromCorpusView {dispatch, id, nodeType, session, subTreeParams}
...@@ -246,6 +247,7 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt ...@@ -246,6 +247,7 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt
cpt {action: Link {subTreeParams}, dispatch, id, nodeType, session} _ = do cpt {action: Link {subTreeParams}, dispatch, id, nodeType, session} _ = do
pure $ copyFromCorpusView {dispatch, id, nodeType, session, subTreeParams} pure $ copyFromCorpusView {dispatch, id, nodeType, session, subTreeParams}
-----------
cpt {action : Share, dispatch, id, name } _ = do cpt {action : Share, dispatch, id, name } _ = do
isOpen <- R.useState' true isOpen <- R.useState' true
......
...@@ -15,7 +15,8 @@ if user has access to node then he can do all his related actions ...@@ -15,7 +15,8 @@ if user has access to node then he can do all his related actions
-} -}
------------------------------------------------------------------------ ------------------------------------------------------------------------
------------------------------------------------------------------------ ------------------------------------------------------------------------
data Status a = IsBeta a | IsProd a -- Beta Status
data Status a = TODO a | WIP a | OnTest a | Beta a
data NodeAction = Documentation NodeType data NodeAction = Documentation NodeType
| SearchBox | SearchBox
...@@ -250,6 +251,8 @@ settingsBox _ = ...@@ -250,6 +251,8 @@ settingsBox _ =
, buttons : [] , buttons : []
} }
-- | SubTree Parameters
moveParameters = { subTreeParams : SubTreeParams moveParameters = { subTreeParams : SubTreeParams
{ showtypes: [ FolderPrivate { showtypes: [ FolderPrivate
, FolderShared , FolderShared
...@@ -267,15 +270,15 @@ moveParameters = { subTreeParams : SubTreeParams ...@@ -267,15 +270,15 @@ moveParameters = { subTreeParams : SubTreeParams
} }
linkParams = { subTreeParams : SubTreeParams linkParams = { subTreeParams : SubTreeParams
{ showtypes: [ FolderPrivate { showtypes: [ FolderPrivate
, FolderShared , FolderShared
, Team , Team
, FolderPublic , FolderPublic
, Folder , Folder
, Annuaire , Annuaire
] ]
, valitypes: [ Annuaire , valitypes: [ Annuaire
] ]
} }
} }
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