Commit 4b367cb2 authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge branch 'dev-refact' into dev

parents 976e1511 461ebdf9
...@@ -13,7 +13,9 @@ import Gargantext.Components.Forest.Tree.Node (nodeMainSpan) ...@@ -13,7 +13,9 @@ 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.Delete (deleteNode) import Gargantext.Components.Forest.Tree.Node.Action.Delete (deleteNode)
import Gargantext.Components.Forest.Tree.Node.Action.Move (moveNode) import Gargantext.Components.Forest.Tree.Node.Action.Move (moveNodeReq)
import Gargantext.Components.Forest.Tree.Node.Action.Merge (mergeNodeReq)
import Gargantext.Components.Forest.Tree.Node.Action.Link (linkNodeReq)
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)
import Gargantext.Components.Forest.Tree.Node.Action.Update (updateRequest) import Gargantext.Components.Forest.Tree.Node.Action.Update (updateRequest)
...@@ -306,8 +308,19 @@ performAction DownloadNode _ = do ...@@ -306,8 +308,19 @@ performAction DownloadNode _ = do
liftEffect $ log "[performAction] DownloadNode" liftEffect $ log "[performAction] DownloadNode"
------- -------
performAction (MoveNode n1 n2) p@{session} = do performAction (MoveNode n1 n2) p@{session} = do
void $ moveNode session n1 n2 void $ moveNodeReq session n1 n2
performAction RefreshTree p performAction RefreshTree p
performAction (MergeNode n1 n2) p@{session} = do
void $ mergeNodeReq session n1 n2
performAction RefreshTree p
performAction (LinkNode n1 n2) p@{session} = do
void $ linkNodeReq session n1 n2
performAction RefreshTree p
------- -------
performAction RefreshTree { reload: (_ /\ setReload) } = do performAction RefreshTree { reload: (_ /\ setReload) } = do
liftEffect $ setReload (_ + 1) liftEffect $ setReload (_ + 1)
......
...@@ -29,6 +29,8 @@ data Action = AddNode String GT.NodeType ...@@ -29,6 +29,8 @@ data Action = AddNode String GT.NodeType
| DownloadNode | DownloadNode
| RefreshTree | RefreshTree
| MoveNode GT.NodeID GT.NodeID | MoveNode GT.NodeID GT.NodeID
| MergeNode GT.NodeID GT.NodeID
| LinkNode GT.NodeID GT.NodeID
| NoAction | NoAction
instance showShow :: Show Action where instance showShow :: Show Action where
...@@ -42,6 +44,8 @@ instance showShow :: Show Action where ...@@ -42,6 +44,8 @@ instance showShow :: Show Action where
show RefreshTree = "RefreshTree" show RefreshTree = "RefreshTree"
show DownloadNode = "Download" show DownloadNode = "Download"
show (MoveNode _ _) = "MoveNode" show (MoveNode _ _) = "MoveNode"
show (MergeNode _ _) = "MergeNode"
show (LinkNode _ _) = "LinkNode"
show NoAction = "NoAction" show NoAction = "NoAction"
type Props = type Props =
...@@ -62,6 +66,9 @@ icon (UploadFile _ _ _ _) = glyphiconNodeAction Upload ...@@ -62,6 +66,9 @@ icon (UploadFile _ _ _ _) = glyphiconNodeAction Upload
icon RefreshTree = glyphiconNodeAction Refresh icon RefreshTree = glyphiconNodeAction Refresh
icon DownloadNode = glyphiconNodeAction Download icon DownloadNode = glyphiconNodeAction Download
icon (MoveNode _ _) = glyphiconNodeAction (Move { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }}) icon (MoveNode _ _) = glyphiconNodeAction (Move { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (MergeNode _ _) = glyphiconNodeAction (Merge { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (LinkNode _ _) = glyphiconNodeAction (Link { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon NoAction = "hand-o-right" icon NoAction = "hand-o-right"
-- icon _ = "hand-o-right" -- icon _ = "hand-o-right"
...@@ -77,5 +84,7 @@ text (UploadFile _ _ _ _)= "Upload File !" ...@@ -77,5 +84,7 @@ text (UploadFile _ _ _ _)= "Upload File !"
text RefreshTree = "Refresh Tree !" text RefreshTree = "Refresh Tree !"
text DownloadNode = "Download !" text DownloadNode = "Download !"
text (MoveNode _ _ ) = "Move !" text (MoveNode _ _ ) = "Move !"
text (MergeNode _ _ ) = "Merge !"
text (LinkNode _ _ ) = "Link !"
text NoAction = "No Action" text NoAction = "No Action"
----------------------------------------------------------------------- -----------------------------------------------------------------------
module Gargantext.Components.Forest.Tree.Node.Action.Link
where
import Data.Argonaut as Argonaut
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
import Gargantext.Components.Forest.Tree.Node.Action (Action(..))
import Gargantext.Components.Forest.Tree.Node.Tools (submitButton, panel)
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (SubTreeParamsProps, subTreeView, SubTreeOut(..))
import Gargantext.Prelude
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, put_)
import Gargantext.Types as GT
import Gargantext.Types (NodeType(..))
import Gargantext.Utils.Argonaut (genericSumDecodeJson, genericSumEncodeJson, genericEnumDecodeJson, genericEnumEncodeJson)
import Reactix as R
import Reactix.DOM.HTML as H
linkNodeReq :: Session -> GT.ID -> GT.ID -> Aff (Array GT.ID)
linkNodeReq session fromId toId =
put_ session $ NodeAPI GT.Node (Just fromId) ("link/" <> show toId)
linkNode :: Record SubTreeParamsProps -> R.Hooks R.Element
linkNode p@{subTreeOut, dispatch} = pure $ panel [subTreeView p] button
where
( subTreeOutParams /\ _ ) = subTreeOut
button = case subTreeOutParams of
Nothing -> H.div {} []
Just sbto -> submitButton (LinkNode inId outId) dispatch
where
(SubTreeOut { in:inId, out:outId}) = sbto
module Gargantext.Components.Forest.Tree.Node.Action.Merge
where
import Data.Argonaut as Argonaut
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
import Gargantext.Components.Forest.Tree.Node.Action (Action(..))
import Gargantext.Components.Forest.Tree.Node.Tools (submitButton, panel)
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (SubTreeParamsProps, subTreeView)
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (SubTreeParamsProps, subTreeView, SubTreeOut(..))
import Gargantext.Prelude
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, put_)
import Gargantext.Types as GT
import Gargantext.Types (NodeType(..))
import Gargantext.Utils.Argonaut (genericSumDecodeJson, genericSumEncodeJson, genericEnumDecodeJson, genericEnumEncodeJson)
import Reactix as R
import Reactix.DOM.HTML as H
mergeNodeReq :: Session -> GT.ID -> GT.ID -> Aff (Array GT.ID)
mergeNodeReq session fromId toId =
put_ session $ NodeAPI GT.Node (Just fromId) ("merge/" <> show toId)
mergeNode :: Record SubTreeParamsProps -> R.Hooks R.Element
mergeNode p@{subTreeOut, dispatch} = pure $ panel [subTreeView p] button
where
( subTreeOutParams /\ _ ) = subTreeOut
button = case subTreeOutParams of
Nothing -> H.div {} []
Just sbto -> submitButton (MergeNode inId outId) dispatch
where
(SubTreeOut { in:inId, out:outId}) = sbto
module Gargantext.Components.Forest.Tree.Node.Action.Move module Gargantext.Components.Forest.Tree.Node.Action.Move
where where
import Data.Argonaut as Argonaut
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Generic.Rep (class Generic) import Data.Tuple.Nested ((/\))
import Gargantext.Prelude
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Gargantext.Types as GT
import Gargantext.Sessions (Session, put_)
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Types (NodeType(..))
import Gargantext.Utils.Argonaut (genericSumDecodeJson, genericSumEncodeJson, genericEnumDecodeJson, genericEnumEncodeJson)
import Data.Generic.Rep.Show (genericShow)
import Gargantext.Components.Forest.Tree.Node.Action (Action(..)) import Gargantext.Components.Forest.Tree.Node.Action (Action(..))
import Reactix as R
import Gargantext.Components.Forest.Tree.Node.Tools (submitButton, panel) import Gargantext.Components.Forest.Tree.Node.Tools (submitButton, panel)
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (SubTreeParamsProps, subTreeView, SubTreeOut(..))
import Gargantext.Prelude
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, put_)
import Gargantext.Types as GT
import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
moveNode :: Session -> GT.ID -> GT.ID -> Aff (Array GT.ID) moveNodeReq :: Session -> GT.ID -> GT.ID -> Aff (Array GT.ID)
moveNode session fromId toId= moveNodeReq session fromId toId =
put_ session $ NodeAPI GT.Node (Just fromId) ("move/" <> show toId) put_ session $ NodeAPI GT.Node (Just fromId) ("move/" <> show toId)
moveNode :: Record SubTreeParamsProps -> R.Hooks R.Element
moveNode p@{subTreeOut, dispatch} = pure $ panel [subTreeView p] button
where
( subTreeOutParams /\ _ ) = subTreeOut
button = case subTreeOutParams of
Nothing -> H.div {} []
Just sbto -> submitButton (MoveNode inId outId) dispatch
where
(SubTreeOut { in:inId, out:outId}) = sbto
...@@ -21,10 +21,13 @@ import Gargantext.Components.Forest.Tree.Node.Action.Search.SearchField (default ...@@ -21,10 +21,13 @@ import Gargantext.Components.Forest.Tree.Node.Action.Search.SearchField (default
import Gargantext.Components.Forest.Tree.Node.Action.Share as Share import Gargantext.Components.Forest.Tree.Node.Action.Share as Share
import Gargantext.Components.Forest.Tree.Node.Action.Update (update) import Gargantext.Components.Forest.Tree.Node.Action.Update (update)
import Gargantext.Components.Forest.Tree.Node.Action.Upload (actionUpload) import Gargantext.Components.Forest.Tree.Node.Action.Upload (actionUpload)
import Gargantext.Components.Forest.Tree.Node.Action.Move (moveNode)
import Gargantext.Components.Forest.Tree.Node.Action.Link (linkNode)
import Gargantext.Components.Forest.Tree.Node.Action.Merge (mergeNode)
import Gargantext.Components.Forest.Tree.Node.Box.Types (NodePopupProps, NodePopupS) import Gargantext.Components.Forest.Tree.Node.Box.Types (NodePopupProps, NodePopupS)
import Gargantext.Components.Forest.Tree.Node.Settings (NodeAction(..), SettingsBox(..), glyphiconNodeAction, settingsBox) import Gargantext.Components.Forest.Tree.Node.Settings (NodeAction(..), SettingsBox(..), glyphiconNodeAction, settingsBox)
import Gargantext.Components.Forest.Tree.Node.Tools (textInputBox, fragmentPT) import Gargantext.Components.Forest.Tree.Node.Tools (textInputBox, fragmentPT)
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (subTreeView) import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (SubTreeOut)
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types (Name, ID) import Gargantext.Types (Name, ID)
import Gargantext.Types as GT import Gargantext.Types as GT
...@@ -246,25 +249,30 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt ...@@ -246,25 +249,30 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt
pure $ fragmentPT $ "Config " <> show nodeType pure $ fragmentPT $ "Config " <> show nodeType
----------- -----------
-- Functions using SubTree
cpt {action: Merge {subTreeParams}, dispatch, id, nodeType, session} _ = do cpt {action: Merge {subTreeParams}, dispatch, id, nodeType, session} _ = do
pure $ subTreeView {dispatch, id, nodeType, session, subTreeParams} subTreeOut :: R.State (Maybe SubTreeOut) <- R.useState' Nothing
mergeNode {dispatch, id, nodeType, session, subTreeParams, subTreeOut}
cpt {action: Move {subTreeParams}, dispatch, id, nodeType, session} _ = do cpt {action: Move {subTreeParams}, dispatch, id, nodeType, session} _ = do
pure $ subTreeView {dispatch, id, nodeType, session, subTreeParams} subTreeOut :: R.State (Maybe SubTreeOut) <- R.useState' Nothing
moveNode {dispatch, id, nodeType, session, subTreeParams, subTreeOut}
cpt {action: Link {subTreeParams}, dispatch, id, nodeType, session} _ = do cpt {action: Link {subTreeParams}, dispatch, id, nodeType, session} _ = do
pure $ subTreeView {dispatch, id, nodeType, session, subTreeParams} subTreeOut :: R.State (Maybe SubTreeOut) <- R.useState' Nothing
linkNode {dispatch, id, nodeType, session, subTreeParams, subTreeOut}
----------- -----------
cpt {action : Share, dispatch, id, name } _ = do cpt {action : Share, dispatch, id, name } _ = do
isOpen <- R.useState' true isOpen <- R.useState' true
pure $ H.div {} [ textInputBox { boxAction: Share.shareAction pure $ H.div {} [ textInputBox { boxAction: Share.shareAction
, boxName: "Share" , boxName: "Share"
, dispatch , dispatch
, id , id
, text: "username" , text: "username"
, isOpen , isOpen
} ] }
]
cpt props@{action: SearchBox, id, session, dispatch, nodePopup} _ = cpt props@{action: SearchBox, id, session, dispatch, nodePopup} _ =
actionSearch session (Just id) dispatch nodePopup actionSearch session (Just id) dispatch nodePopup
......
...@@ -37,7 +37,7 @@ data SubTreeParams = SubTreeParams { showtypes :: Array NodeType ...@@ -37,7 +37,7 @@ data SubTreeParams = SubTreeParams { showtypes :: Array NodeType
derive instance eqSubTreeParams :: Eq SubTreeParams derive instance eqSubTreeParams :: Eq SubTreeParams
derive instance genericSubTreeParams :: Generic SubTreeParams _ derive instance genericSubTreeParams :: Generic SubTreeParams _
instance showSubTreeParams :: Show SubTreeParams where instance showSubTreeParams :: Show SubTreeParams where
show = genericShow show = genericShow
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -261,9 +261,8 @@ moveParameters = { subTreeParams : SubTreeParams ...@@ -261,9 +261,8 @@ moveParameters = { subTreeParams : SubTreeParams
, Folder , Folder
] ]
, valitypes: [ FolderPrivate , valitypes: [ FolderPrivate
, FolderShared , Team
, Team -- , FolderPublic
, FolderPublic
, Folder , Folder
] ]
} }
......
...@@ -3,6 +3,7 @@ module Gargantext.Components.Forest.Tree.Node.Tools.SubTree where ...@@ -3,6 +3,7 @@ module Gargantext.Components.Forest.Tree.Node.Tools.SubTree where
import DOM.Simple.Console (log2) import DOM.Simple.Console (log2)
import Data.Array as A import Data.Array as A
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\))
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq) import Data.Generic.Rep.Eq (genericEq)
import Effect.Uncurried (mkEffectFn1) import Effect.Uncurried (mkEffectFn1)
...@@ -11,7 +12,7 @@ import Gargantext.Components.Forest.Tree.Node.Action (Props, Action(..)) ...@@ -11,7 +12,7 @@ import Gargantext.Components.Forest.Tree.Node.Action (Props, Action(..))
import Gargantext.Components.Forest.Tree.Node.Settings (SubTreeParams(..)) import Gargantext.Components.Forest.Tree.Node.Settings (SubTreeParams(..))
import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..)) import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..))
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude (discard, map, pure, show, unit, ($), (&&), (/=), (<>), class Eq) import Gargantext.Prelude (discard, map, pure, show, unit, ($), (&&), (/=), (<>), class Eq, const)
import Gargantext.Routes as GR import Gargantext.Routes as GR
import Gargantext.Sessions (Session(..), get) import Gargantext.Sessions (Session(..), get)
import Gargantext.Types as GT import Gargantext.Types as GT
...@@ -19,9 +20,13 @@ import Reactix as R ...@@ -19,9 +20,13 @@ import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
data SubTreeOut = SubTreeOut { in :: GT.ID
, out :: GT.ID
}
------------------------------------------------------------------------ ------------------------------------------------------------------------
type SubTreeParamsProps = type SubTreeParamsProps =
( subTreeParams :: SubTreeParams ( subTreeParams :: SubTreeParams
, subTreeOut :: R.State (Maybe SubTreeOut)
| Props | Props
) )
...@@ -32,23 +37,25 @@ subTreeViewCpt :: R.Component SubTreeParamsProps ...@@ -32,23 +37,25 @@ subTreeViewCpt :: R.Component SubTreeParamsProps
subTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeView" cpt subTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeView" cpt
where where
cpt params@{ dispatch cpt params@{ dispatch
, id , id
, nodeType , nodeType
, session , session
, subTreeParams , subTreeParams
} _ = , subTreeOut
} _ =
do do
let SubTreeParams {showtypes} = subTreeParams let SubTreeParams {showtypes} = subTreeParams
useLoader session (loadSubTree showtypes) $ useLoader session (loadSubTree showtypes) $
\tree -> \tree ->
subTreeViewLoaded { dispatch subTreeViewLoaded { dispatch
, id , id
, nodeType , nodeType
, session , session
, tree , tree
, subTreeParams , subTreeParams
} , subTreeOut
}
loadSubTree :: Array GT.NodeType -> Session -> Aff FTree loadSubTree :: Array GT.NodeType -> Session -> Aff FTree
loadSubTree nodetypes session = getSubTree session treeId nodetypes loadSubTree nodetypes session = getSubTree session treeId nodetypes
...@@ -92,6 +99,7 @@ subTreeTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeTreeViewCpt" cpt ...@@ -92,6 +99,7 @@ subTreeTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeTreeViewCpt" cpt
) ary ) ary
, subTreeParams , subTreeParams
, dispatch , dispatch
, subTreeOut
} _ = do } _ = do
pure $ {- H.div {} [ H.h5 { className: GT.fldr nodeType true} [] pure $ {- H.div {} [ H.h5 { className: GT.fldr nodeType true} []
, -} H.div { className: "node" } , -} H.div { className: "node" }
...@@ -111,14 +119,10 @@ subTreeTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeTreeViewCpt" cpt ...@@ -111,14 +119,10 @@ subTreeTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeTreeViewCpt" cpt
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 ""
sbto@( subTreeOutParams /\ setSubTreeOut) = subTreeOut
onClick _ = mkEffectFn1 onClick _ = mkEffectFn1 $ \_ -> case validNodeType of
$ \_ -> case validNodeType of false -> setSubTreeOut (const Nothing)
false -> launchAff $ dispatch NoAction true -> setSubTreeOut (const $ Just $ SubTreeOut { in: id, out:sourceId})
true -> do
log2 "[subTreeTreeViewCpt] from" sourceId
log2 "[subTreeTreeViewCpt] to" id
launchAff $ dispatch (MoveNode id sourceId)
-------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------
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