Commit 1d0b9f16 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FEAT] UpdateNode type and json instance

parent 1aded978
...@@ -13,7 +13,7 @@ import Reactix.DOM.HTML as H ...@@ -13,7 +13,7 @@ import Reactix.DOM.HTML as H
import Record as Record import Record as Record
import Record.Extra as RecordE import Record.Extra as RecordE
import Gargantext.Components.Forest.Tree.Node.Action (Action(..), CreateValue(..), FTree, ID, LNode(..), NTree(..), Reload, RenameValue(..), Tree, createNode, deleteNode, loadNode, renameNode) import Gargantext.Components.Forest.Tree.Node.Action (Action(..), AddNodeValue(..), FTree, ID, LNode(..), NTree(..), Reload, RenameValue(..), Tree, addNode, deleteNode, loadNode, renameNode)
import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadFile) import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadFile)
import Gargantext.Components.Forest.Tree.Node.Box (nodeMainSpan) import Gargantext.Components.Forest.Tree.Node.Box (nodeMainSpan)
import Gargantext.Ends (Frontends) import Gargantext.Ends (Frontends)
...@@ -209,7 +209,7 @@ performAction p@{ openNodes: (_ /\ setOpenNodes) ...@@ -209,7 +209,7 @@ performAction p@{ openNodes: (_ /\ setOpenNodes)
, session , session
, tree: (NTree (LNode {id}) _) } (CreateSubmit name nodeType) = do , tree: (NTree (LNode {id}) _) } (CreateSubmit name nodeType) = do
-- task <- createNodeAsync session id $ CreateValue {name, nodeType} -- task <- createNodeAsync session id $ CreateValue {name, nodeType}
task <- createNode session id $ CreateValue {name, nodeType} task <- addNode session id $ AddNodeValue {name, nodeType}
-- liftEffect $ setAsyncTasks $ A.cons task -- liftEffect $ setAsyncTasks $ A.cons task
liftEffect do liftEffect do
setOpenNodes (Set.insert (mkNodeId session id)) setOpenNodes (Set.insert (mkNodeId session id))
......
...@@ -60,18 +60,18 @@ type UploadFile = ...@@ -60,18 +60,18 @@ type UploadFile =
, name :: String , name :: String
} }
createNode :: Session -> ID -> CreateValue -> Aff (Array ID) addNode :: Session -> ID -> AddNodeValue -> Aff (Array ID)
createNode session parentId = post session $ NodeAPI GT.Node (Just parentId) "" addNode session parentId = post session $ NodeAPI GT.Node (Just parentId) ""
createNodeAsync :: Session addNodeAsync :: Session
-> ID -> ID
-> CreateValue -> AddNodeValue
-> Aff GT.AsyncTaskWithType -> Aff GT.AsyncTaskWithType
createNodeAsync session parentId q = do addNodeAsync session parentId q = do
task <- post session p q task <- post session p q
pure $ GT.AsyncTaskWithType {task, typ: GT.CreateNode} pure $ GT.AsyncTaskWithType {task, typ: GT.AddNode}
where where
p = GR.NodeAPI GT.Node (Just parentId) (GT.asyncTaskTypePath GT.CreateNode) p = GR.NodeAPI GT.Node (Just parentId) (GT.asyncTaskTypePath GT.AddNode)
renameNode :: Session -> ID -> RenameValue -> Aff (Array ID) renameNode :: Session -> ID -> RenameValue -> Aff (Array ID)
renameNode session renameNodeId = put session $ NodeAPI GT.Node (Just renameNodeId) "rename" renameNode session renameNodeId = put session $ NodeAPI GT.Node (Just renameNodeId) "rename"
...@@ -87,29 +87,53 @@ updateNode :: Session -> ID -> Aff ID ...@@ -87,29 +87,53 @@ updateNode :: Session -> ID -> Aff ID
updateNode session nodeId = post session updateNode session nodeId = post session
-} -}
-----------------------------------------------------------------------
newtype RenameValue = RenameValue newtype RenameValue = RenameValue
{ name :: Name { name :: Name }
}
instance encodeJsonRenameValue :: EncodeJson RenameValue where instance encodeJsonRenameValue :: EncodeJson RenameValue where
encodeJson (RenameValue {name}) encodeJson (RenameValue {name})
= "r_name" := name = "r_name" := name
~> jsonEmptyObject ~> jsonEmptyObject
newtype CreateValue = CreateValue -----------------------------------------------------------------------
newtype AddNodeValue = AddNodeValue
{ name :: Name { name :: Name
, nodeType :: GT.NodeType , nodeType :: GT.NodeType
} }
instance encodeJsonCreateValue :: EncodeJson CreateValue where instance encodeJsonCreateValue :: EncodeJson AddNodeValue where
encodeJson (CreateValue {name, nodeType}) encodeJson (AddNodeValue {name, nodeType})
= "pn_name" := name = "pn_name" := name
~> "pn_typename" := nodeType ~> "pn_typename" := nodeType
~> jsonEmptyObject ~> jsonEmptyObject
-----------------------------------------------------------------------
data UpdateNodeParams = UpdateNodeParamsList { method :: Int }
| UpdateNodeParamsGraph { method :: String }
| UpdateNodeParamsTexts { method :: Int }
instance encodeJsonUpdateNodeParams :: EncodeJson UpdateNodeParams
where
encodeJson (UpdateNodeParamsList { method })
= "method" := method
~> jsonEmptyObject
encodeJson (UpdateNodeParamsGraph { method })
= "method" := method
~> jsonEmptyObject
encodeJson (UpdateNodeParamsTexts { method })
= "method" := method
~> jsonEmptyObject
-----------------------------------------------------------------------
data NTree a = NTree a (Array (NTree a)) data NTree a = NTree a (Array (NTree a))
type FTree = NTree LNode type FTree = NTree LNode
type Tree = { tree :: FTree, asyncTasks :: Array GT.AsyncTaskWithType } type Tree = { tree :: FTree
, asyncTasks :: Array GT.AsyncTaskWithType
}
instance ntreeFunctor :: Functor NTree where instance ntreeFunctor :: Functor NTree where
map f (NTree x ary) = NTree (f x) (map (map f) ary) map f (NTree x ary) = NTree (f x) (map (map f) ary)
...@@ -129,7 +153,8 @@ instance decodeJsonLNode :: DecodeJson LNode where ...@@ -129,7 +153,8 @@ instance decodeJsonLNode :: DecodeJson LNode where
nodeType <- obj .: "type" nodeType <- obj .: "type"
pure $ LNode { id : id_ pure $ LNode { id : id_
, name , name
, nodeType} , nodeType
}
instance decodeJsonFTree :: DecodeJson (NTree LNode) where instance decodeJsonFTree :: DecodeJson (NTree LNode) where
decodeJson json = do decodeJson json = do
......
...@@ -28,11 +28,11 @@ type CreateNodeProps = ...@@ -28,11 +28,11 @@ type CreateNodeProps =
, nodeTypes :: Array NodeType , nodeTypes :: Array NodeType
) )
createNodeView :: Record CreateNodeProps addNodeView :: Record CreateNodeProps
-> R.Element -> R.Element
createNodeView p@{ dispatch, nodeType, nodeTypes } = R.createElement el p [] addNodeView p@{ dispatch, nodeType, nodeTypes } = R.createElement el p []
where where
el = R.hooksComponent "CreateNodeView" cpt el = R.hooksComponent "AddNodeView" cpt
cpt {id, name} _ = do cpt {id, name} _ = do
nodeName <- R.useState' "Name" nodeName <- R.useState' "Name"
nodeType' <- R.useState' $ fromMaybe NodeUser $ head nodeTypes nodeType' <- R.useState' $ fromMaybe NodeUser $ head nodeTypes
...@@ -103,7 +103,6 @@ createNodeView p@{ dispatch, nodeType, nodeTypes } = R.createElement el p [] ...@@ -103,7 +103,6 @@ createNodeView p@{ dispatch, nodeType, nodeTypes } = R.createElement el p []
-- END Create Node -- END Create Node
showConfig :: NodeType -> R.Element showConfig :: NodeType -> R.Element
showConfig NodeUser = H.div {} [] showConfig NodeUser = H.div {} []
showConfig FolderPrivate = H.div {} [H.text "This folder will be private only"] showConfig FolderPrivate = H.div {} [H.text "This folder will be private only"]
...@@ -111,4 +110,3 @@ showConfig FolderShared = H.div {} [H.text "This folder will be shared"] ...@@ -111,4 +110,3 @@ showConfig FolderShared = H.div {} [H.text "This folder will be shared"]
showConfig FolderPublic = H.div {} [H.text "This folder will be public"] showConfig FolderPublic = H.div {} [H.text "This folder will be public"]
showConfig nt = H.div {} [H.h4 {} [H.text $ "Config of " <> show nt ]] showConfig nt = H.div {} [H.h4 {} [H.text $ "Config of " <> show nt ]]
...@@ -18,7 +18,7 @@ import Effect.Console ...@@ -18,7 +18,7 @@ import Effect.Console
import Effect.Uncurried (mkEffectFn1) import Effect.Uncurried (mkEffectFn1)
import Gargantext.Components.Forest.Tree.Node (NodeAction(..), SettingsBox(..), glyphiconNodeAction, settingsBox) import Gargantext.Components.Forest.Tree.Node (NodeAction(..), SettingsBox(..), glyphiconNodeAction, settingsBox)
import Gargantext.Components.Forest.Tree.Node.Action (Action(..), DroppedFile(..), FileType(..), ID, Name, UploadFileContents(..)) import Gargantext.Components.Forest.Tree.Node.Action (Action(..), DroppedFile(..), FileType(..), ID, Name, UploadFileContents(..))
import Gargantext.Components.Forest.Tree.Node.Action.Add (NodePopup(..), createNodeView) import Gargantext.Components.Forest.Tree.Node.Action.Add (NodePopup(..), addNodeView)
import Gargantext.Components.Forest.Tree.Node.Action.Rename (renameBox) import Gargantext.Components.Forest.Tree.Node.Action.Rename (renameBox)
import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadFileView, fileTypeView, uploadTermListView, copyFromCorpusView) import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadFileView, fileTypeView, uploadTermListView, copyFromCorpusView)
import Gargantext.Components.Forest.Tree.Node.ProgressBar (asyncProgressBar, BarType(..)) import Gargantext.Components.Forest.Tree.Node.ProgressBar (asyncProgressBar, BarType(..))
...@@ -542,7 +542,7 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt ...@@ -542,7 +542,7 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt
cpt {action: Delete, nodeType, dispatch} _ = actionDelete nodeType dispatch cpt {action: Delete, nodeType, dispatch} _ = actionDelete nodeType dispatch
cpt {action: Add xs, dispatch, id, name, nodePopup: p, nodeType} _ = do cpt {action: Add xs, dispatch, id, name, nodePopup: p, nodeType} _ = do
pure $ createNodeView {dispatch, id, name, nodeType, nodeTypes: xs} pure $ addNodeView {dispatch, id, name, nodeType, nodeTypes: xs}
cpt {action: CopyFromCorpus, dispatch, id, nodeType, session} _ = do cpt {action: CopyFromCorpus, dispatch, id, nodeType, session} _ = do
pure $ copyFromCorpusView {dispatch, id, nodeType, session} pure $ copyFromCorpusView {dispatch, id, nodeType, session}
......
...@@ -469,7 +469,7 @@ modeFromString _ = Nothing ...@@ -469,7 +469,7 @@ modeFromString _ = Nothing
data AsyncTaskType = Form data AsyncTaskType = Form
| GraphT | GraphT
| Query | Query
| CreateNode | AddNode
| UpdateNode | UpdateNode
derive instance genericAsyncTaskType :: Generic AsyncTaskType _ derive instance genericAsyncTaskType :: Generic AsyncTaskType _
...@@ -477,7 +477,7 @@ asyncTaskTypePath :: AsyncTaskType -> String ...@@ -477,7 +477,7 @@ asyncTaskTypePath :: AsyncTaskType -> String
asyncTaskTypePath Form = "add/form/async/" asyncTaskTypePath Form = "add/form/async/"
asyncTaskTypePath Query = "query/" asyncTaskTypePath Query = "query/"
asyncTaskTypePath GraphT = "async/" asyncTaskTypePath GraphT = "async/"
asyncTaskTypePath CreateNode = "async/nobody/" asyncTaskTypePath AddNode = "async/nobody/"
asyncTaskTypePath UpdateNode = "async/" asyncTaskTypePath UpdateNode = "async/"
type AsyncTaskID = String type AsyncTaskID = String
......
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