Commit 28af3ffe authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FEAT] move node in Tree implemented (needs refact and security)

parent d9a9615c
......@@ -13,6 +13,7 @@ import Gargantext.Components.Forest.Tree.Node (nodeMainSpan)
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.Delete (deleteNode)
import Gargantext.Components.Forest.Tree.Node.Action.Move (moveNode)
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.Update (updateRequest)
......@@ -304,6 +305,13 @@ performAction (UploadFile nodeType fileType mName contents) { session
performAction DownloadNode _ = do
liftEffect $ log "[performAction] DownloadNode"
-------
performAction (MoveNode n1 n2) p@{session} = do
void $ moveNode session n1 n2
performAction RefreshTree p
-------
performAction RefreshTree { reload: (_ /\ setReload) } = do
liftEffect $ setReload (_ + 1)
-------
performAction NoAction _ = do
liftEffect $ log "[performAction] NoAction"
......@@ -5,7 +5,7 @@ import Effect.Aff (Aff)
import Gargantext.Prelude (class Show, Unit)
import Gargantext.Sessions (Session)
import Gargantext.Types as GT
import Gargantext.Components.Forest.Tree.Node.Settings (NodeAction(..), glyphiconNodeAction)
import Gargantext.Components.Forest.Tree.Node.Settings (NodeAction(..), glyphiconNodeAction, SubTreeParams(..))
import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileType, UploadFileContents)
import Gargantext.Components.Forest.Tree.Node.Action.Update.Types (UpdateNodeParams)
......@@ -28,6 +28,8 @@ data Action = AddNode String GT.NodeType
| UploadFile GT.NodeType FileType (Maybe String) UploadFileContents
| DownloadNode
| RefreshTree
| MoveNode GT.NodeID GT.NodeID
| NoAction
instance showShow :: Show Action where
show (AddNode _ _ )= "AddNode"
......@@ -39,6 +41,8 @@ instance showShow :: Show Action where
show (UploadFile _ _ _ _)= "UploadFile"
show RefreshTree = "RefreshTree"
show DownloadNode = "Download"
show (MoveNode _ _) = "MoveNode"
show NoAction = "NoAction"
type Props =
( dispatch :: Action -> Aff Unit
......@@ -57,6 +61,9 @@ icon (DoSearch _) = glyphiconNodeAction SearchBox
icon (UploadFile _ _ _ _) = glyphiconNodeAction Upload
icon RefreshTree = glyphiconNodeAction Refresh
icon DownloadNode = glyphiconNodeAction Download
icon (MoveNode _ _) = glyphiconNodeAction (Move { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon NoAction = "hand-o-right"
-- icon _ = "hand-o-right"
text :: Action -> String
......@@ -69,4 +76,6 @@ text (DoSearch _ )= "Launch search !"
text (UploadFile _ _ _ _)= "Upload File !"
text RefreshTree = "Refresh Tree !"
text DownloadNode = "Download !"
text (MoveNode _ _ ) = "Move !"
text NoAction = "No Action"
-----------------------------------------------------------------------
module Gargantext.Components.Forest.Tree.Node.Action.Move
where
import Data.Argonaut as Argonaut
import Data.Maybe (Maybe(..))
import Data.Generic.Rep (class Generic)
import Gargantext.Prelude
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 Reactix as R
import Gargantext.Components.Forest.Tree.Node.Tools (submitButton, panel)
import Reactix.DOM.HTML as H
moveNode :: Session -> GT.ID -> GT.ID -> Aff (Array GT.ID)
moveNode session fromId toId=
put_ session $ NodeAPI GT.Node (Just fromId) ("move/" <> show toId)
......@@ -5,8 +5,9 @@ import Data.Array as A
import Data.Maybe (Maybe(..))
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Effect.Aff (Aff)
import Gargantext.Components.Forest.Tree.Node.Action (Props)
import Effect.Uncurried (mkEffectFn1)
import Effect.Aff (Aff, launchAff)
import Gargantext.Components.Forest.Tree.Node.Action (Props, Action(..))
import Gargantext.Components.Forest.Tree.Node.Settings (SubTreeParams(..))
import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..))
import Gargantext.Hooks.Loader (useLoader)
......@@ -83,7 +84,15 @@ subTreeTreeView props = R.createElement subTreeTreeViewCpt props []
subTreeTreeViewCpt :: R.Component CorpusTreeProps
subTreeTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeTreeViewCpt" cpt
where
cpt p@{id, tree: NTree (LNode { id: sourceId, name, nodeType }) ary, subTreeParams} _ = do
cpt p@{ id
, tree: NTree (LNode { id: sourceId
, name
, nodeType
}
) ary
, subTreeParams
, dispatch
} _ = do
pure $ {- H.div {} [ H.h5 { className: GT.fldr nodeType true} []
, -} H.div { className: "node" }
( [ H.span { className: "name " <> clickable
......@@ -103,11 +112,13 @@ subTreeTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeTreeViewCpt" cpt
clickable = if validNodeType then "clickable" else ""
onClick _ = case validNodeType of
false -> pure unit
onClick _ = mkEffectFn1
$ \_ -> case validNodeType of
false -> launchAff $ dispatch NoAction
true -> do
log2 "[subTreeTreeViewCpt] issue copy into" id
log2 "[subTreeTreeViewCpt] issue copy from" sourceId
log2 "[subTreeTreeViewCpt] from" sourceId
log2 "[subTreeTreeViewCpt] to" id
launchAff $ dispatch (MoveNode id sourceId)
--------------------------------------------------------------------------------------------
......@@ -64,6 +64,9 @@ get mtoken url = send GET mtoken url noReqBody
put :: forall a b. EncodeJson a => DecodeJson b => Maybe Token -> String -> a -> Aff b
put mtoken url = send PUT mtoken url <<< Just
put_ :: forall a. DecodeJson a => Maybe Token -> String -> Aff a
put_ mtoken url = send PUT mtoken url noReqBody
delete :: forall a. DecodeJson a => Maybe Token -> String -> Aff a
delete mtoken url = send DELETE mtoken url noReqBody
......
......@@ -223,6 +223,9 @@ get session@(Session {token}) p = REST.get (Just token) (toUrl session p)
put :: forall a b p. EncodeJson a => DecodeJson b => ToUrl Session p => Session -> p -> a -> Aff b
put session@(Session {token}) p = REST.put (Just token) (toUrl session p)
put_ :: forall a b p. DecodeJson b => ToUrl Session p => Session -> p -> Aff b
put_ session@(Session {token}) p = REST.put_ (Just token) (toUrl session p)
delete :: forall a p. DecodeJson a => ToUrl Session p => Session -> p -> Aff a
delete session@(Session {token}) p = REST.delete (Just token) (toUrl session p)
......
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