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

[Tree/Box] UpdateNode start

parent 914fc19b
...@@ -288,7 +288,7 @@ versionCpt = R.hooksComponent "G.C.A.version" cpt ...@@ -288,7 +288,7 @@ versionCpt = R.hooksComponent "G.C.A.version" cpt
showVersions frontendVer backendVer = showVersions frontendVer backendVer =
H.div { className: "row" } H.div { className: "row" }
[ H.h5 {} [ H.text $ "Frontend version: " <> frontendVer ] [ H.h5 {} [ H.text $ "Frontend version: " <> frontendVer ]
, H.h5 {} [ H.text $ "backend version: " <> backendVer ] , H.h5 {} [ H.text $ "Backend version: " <> backendVer ]
] ]
footer :: Record VersionProps -> R.Element footer :: Record VersionProps -> R.Element
......
...@@ -23,6 +23,8 @@ import Gargantext.Routes (AppRoute) ...@@ -23,6 +23,8 @@ import Gargantext.Routes (AppRoute)
import Gargantext.Sessions (OpenNodes, Session, mkNodeId) import Gargantext.Sessions (OpenNodes, Session, mkNodeId)
import Gargantext.Types as GT import Gargantext.Types as GT
------------------------------------------------------------------------
type CommonProps = type CommonProps =
( frontends :: Frontends ( frontends :: Frontends
, mCurrentRoute :: Maybe AppRoute , mCurrentRoute :: Maybe AppRoute
...@@ -38,44 +40,50 @@ type Props = ( root :: ID ...@@ -38,44 +40,50 @@ type Props = ( root :: ID
treeView :: Record Props -> R.Element treeView :: Record Props -> R.Element
treeView props = R.createElement treeViewCpt props [] treeView props = R.createElement treeViewCpt props []
treeViewCpt :: R.Component Props
treeViewCpt = R.hooksComponent "G.C.Tree.treeView" cpt
where where
cpt { root, mCurrentRoute, session, frontends, openNodes, reload } _children = do treeViewCpt :: R.Component Props
pure $ treeLoadView treeViewCpt = R.hooksComponent "G.C.Tree.treeView" cpt
{ root, mCurrentRoute, session, frontends, openNodes, reload } where
cpt { root, mCurrentRoute, session, frontends, openNodes, reload } _children = do
pure $ treeLoadView
{ root, mCurrentRoute, session, frontends, openNodes, reload }
treeLoadView :: Record Props -> R.Element treeLoadView :: Record Props -> R.Element
treeLoadView p = R.createElement treeLoadView' p [] treeLoadView p = R.createElement treeLoadViewCpt p []
treeLoadView' :: R.Component Props
treeLoadView' = R.hooksComponent "TreeLoadView" cpt
where where
cpt {root, mCurrentRoute, session, frontends, openNodes, reload} _ = do treeLoadViewCpt :: R.Component Props
let fetch _ = loadNode session root treeLoadViewCpt = R.hooksComponent "TreeLoadView" cpt
let paint loaded = loadedTreeView {tree: loaded, mCurrentRoute, session, frontends, openNodes, reload} where
useLoader {root, counter: fst reload} fetch paint cpt {root, mCurrentRoute, session, frontends, openNodes, reload} _ = do
let fetch _ = loadNode session root
let paint loaded = loadedTreeView { tree: loaded
, mCurrentRoute
, session
, frontends
, openNodes, reload
}
useLoader { root
, counter: fst reload
}
fetch paint
type TreeViewProps = ( tree :: FTree type TreeViewProps = ( tree :: FTree
| CommonProps | CommonProps
) )
loadedTreeView :: Record TreeViewProps -> R.Element loadedTreeView :: Record TreeViewProps -> R.Element
loadedTreeView p = R.createElement loadedTreeView' p [] loadedTreeView p = R.createElement loadedTreeViewCpt p []
loadedTreeView' :: R.Component TreeViewProps
loadedTreeView' = R.hooksComponent "LoadedTreeView" cpt
where where
cpt {tree, mCurrentRoute, session, frontends, openNodes, reload} _ = do loadedTreeViewCpt :: R.Component TreeViewProps
tasks <- R.useState' [] loadedTreeViewCpt = R.hooksComponent "LoadedTreeView" cpt
where
cpt {tree, mCurrentRoute, session, frontends, openNodes, reload} _ = do
tasks <- R.useState' []
pure $ H.div {className: "tree"} pure $ H.div {className: "tree"}
[ toHtml { frontends, mCurrentRoute, openNodes, reload, session, tasks, tree } ] [ toHtml { frontends, mCurrentRoute, openNodes, reload, session, tasks, tree } ]
------------------------------------------------------------------------ ------------------------------------------------------------------------
type ToHtmlProps = type ToHtmlProps =
( (
tasks :: R.State (Array GT.AsyncTaskWithType) tasks :: R.State (Array GT.AsyncTaskWithType)
...@@ -90,7 +98,8 @@ toHtml p@{ frontends ...@@ -90,7 +98,8 @@ toHtml p@{ frontends
, reload: reload@(_ /\ setReload) , reload: reload@(_ /\ setReload)
, session , session
, tasks: tasks@(asyncTasks /\ setAsyncTasks) , tasks: tasks@(asyncTasks /\ setAsyncTasks)
, tree: tree@(NTree (LNode {id, name, nodeType}) ary) } = R.createElement el {} [] , tree: tree@(NTree (LNode {id, name, nodeType}) ary)
} = R.createElement el {} []
where where
el = R.hooksComponent "NodeView" cpt el = R.hooksComponent "NodeView" cpt
commonProps = RecordE.pick p :: Record CommonProps commonProps = RecordE.pick p :: Record CommonProps
...@@ -132,13 +141,11 @@ toHtml p@{ frontends ...@@ -132,13 +141,11 @@ toHtml p@{ frontends
type ChildNodesProps = type ChildNodesProps =
( ( children :: Array FTree
children :: Array FTree , folderOpen :: R.State Boolean
, folderOpen :: R.State Boolean | CommonProps
| CommonProps
) )
childNodes :: Record ChildNodesProps -> Array R.Element childNodes :: Record ChildNodesProps -> Array R.Element
childNodes { children: [] } = [] childNodes { children: [] } = []
childNodes { folderOpen: (false /\ _) } = [] childNodes { folderOpen: (false /\ _) } = []
...@@ -178,10 +185,18 @@ performAction p@{ openNodes: (_ /\ setOpenNodes) ...@@ -178,10 +185,18 @@ performAction p@{ openNodes: (_ /\ setOpenNodes)
performAction { reload: (_ /\ setReload) performAction { reload: (_ /\ setReload)
, session , session
, tasks: (_ /\ setAsyncTasks) , tasks: (_ /\ setAsyncTasks)
, tree: (NTree (LNode {id}) _) } (SearchQuery task) = do , tree: (NTree (LNode {id}) _)
} (SearchQuery task) = do
liftEffect $ setAsyncTasks $ A.cons task liftEffect $ setAsyncTasks $ A.cons task
liftEffect $ log2 "[performAction] SearchQuery task:" task liftEffect $ log2 "[performAction] SearchQuery task:" task
performAction { reload: (_ /\ setReload)
, session
, tasks: (_ /\ setAsyncTasks)
, tree: (NTree (LNode {id}) _) } (UpdateNode task) = do
liftEffect $ setAsyncTasks $ A.cons task
liftEffect $ log2 "[performAction] UpdateNode task:" task
performAction p@{ reload: (_ /\ setReload) performAction p@{ reload: (_ /\ setReload)
, session , session
, tree: (NTree (LNode {id}) _) } (Submit name) = do , tree: (NTree (LNode {id}) _) } (Submit name) = do
......
...@@ -17,8 +17,9 @@ import Gargantext.Types as GT ...@@ -17,8 +17,9 @@ import Gargantext.Types as GT
data Action = CreateSubmit String GT.NodeType data Action = CreateSubmit String GT.NodeType
| DeleteNode | DeleteNode
| UpdateNode GT.AsyncTaskWithType
| SearchQuery GT.AsyncTaskWithType | SearchQuery GT.AsyncTaskWithType
| Submit String | Submit String
| UploadFile GT.NodeType FileType (Maybe String) UploadFileContents | UploadFile GT.NodeType FileType (Maybe String) UploadFileContents
| RefreshTree | RefreshTree
...@@ -54,8 +55,8 @@ type ID = Int ...@@ -54,8 +55,8 @@ type ID = Int
type Reload = Int type Reload = Int
newtype UploadFileContents = UploadFileContents String newtype UploadFileContents = UploadFileContents String
type UploadFile = { type UploadFile =
contents :: UploadFileContents { contents :: UploadFileContents
, name :: String , name :: String
} }
...@@ -81,10 +82,13 @@ deleteNode session nodeId = delete session $ NodeAPI GT.Node (Just nodeId) "" ...@@ -81,10 +82,13 @@ deleteNode session nodeId = delete session $ NodeAPI GT.Node (Just nodeId) ""
loadNode :: Session -> ID -> Aff FTree loadNode :: Session -> ID -> Aff FTree
loadNode session nodeId = get session $ NodeAPI GT.Tree (Just nodeId) "" loadNode session nodeId = get session $ NodeAPI GT.Tree (Just nodeId) ""
{-
updateNode :: Session -> ID -> Aff ID
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
...@@ -93,8 +97,7 @@ instance encodeJsonRenameValue :: EncodeJson RenameValue where ...@@ -93,8 +97,7 @@ instance encodeJsonRenameValue :: EncodeJson RenameValue where
~> jsonEmptyObject ~> jsonEmptyObject
newtype CreateValue = CreateValue newtype CreateValue = CreateValue
{ { name :: Name
name :: Name
, nodeType :: GT.NodeType , nodeType :: GT.NodeType
} }
......
...@@ -518,7 +518,6 @@ type NodeProps = ...@@ -518,7 +518,6 @@ type NodeProps =
, nodeType :: GT.NodeType , nodeType :: GT.NodeType
) )
type Open = Boolean
type PanelActionProps = type PanelActionProps =
( id :: ID ( id :: ID
...@@ -568,7 +567,11 @@ actionSearch search session dispatch nodePopup = ...@@ -568,7 +567,11 @@ actionSearch search session dispatch nodePopup =
pure $ R.fragment [ H.p {"style": {"margin" :"10px"}} pure $ R.fragment [ H.p {"style": {"margin" :"10px"}}
[ H.text $ "Search and create a private " [ H.text $ "Search and create a private "
<> "corpus with the search query as corpus name." ] <> "corpus with the search query as corpus name." ]
, searchBar {langs: allLangs, onSearch: searchOn dispatch nodePopup, search, session} , searchBar { langs: allLangs
, onSearch: searchOn dispatch nodePopup
, search
, session
}
] ]
where where
searchOn :: (Action -> Aff Unit) searchOn :: (Action -> Aff Unit)
......
...@@ -33,4 +33,10 @@ searchBarCpt = R.hooksComponent "G.C.Node.SearchBar.searchBar" cpt ...@@ -33,4 +33,10 @@ searchBarCpt = R.hooksComponent "G.C.Node.SearchBar.searchBar" cpt
cpt {langs, onSearch, search: search@(s /\ _), session} _ = do cpt {langs, onSearch, search: search@(s /\ _), session} _ = do
--onSearchChange session s --onSearchChange session s
pure $ H.div {"style": {"margin" :"10px"}} pure $ H.div {"style": {"margin" :"10px"}}
[ searchField {databases:allDatabases, langs, onSearch, search, session}] [ searchField { databases:allDatabases
, langs
, onSearch
, search
, session
}
]
...@@ -463,10 +463,14 @@ modeFromString "Institutes" = Just Institutes ...@@ -463,10 +463,14 @@ modeFromString "Institutes" = Just Institutes
modeFromString "Terms" = Just Terms modeFromString "Terms" = Just Terms
modeFromString _ = Nothing modeFromString _ = Nothing
-- Async tasks -- | Async tasks
-- corresponds to /add/form/async or /add/query/async -- corresponds to /add/form/async or /add/query/async
data AsyncTaskType = Form | GraphT | Query | CreateNode data AsyncTaskType = Form
| GraphT
| Query
| CreateNode
| UpdateNode
derive instance genericAsyncTaskType :: Generic AsyncTaskType _ derive instance genericAsyncTaskType :: Generic AsyncTaskType _
asyncTaskTypePath :: AsyncTaskType -> String asyncTaskTypePath :: AsyncTaskType -> String
...@@ -474,10 +478,18 @@ asyncTaskTypePath Form = "add/form/async/" ...@@ -474,10 +478,18 @@ asyncTaskTypePath Form = "add/form/async/"
asyncTaskTypePath Query = "query/" asyncTaskTypePath Query = "query/"
asyncTaskTypePath GraphT = "async/" asyncTaskTypePath GraphT = "async/"
asyncTaskTypePath CreateNode = "async/nobody/" asyncTaskTypePath CreateNode = "async/nobody/"
asyncTaskTypePath UpdateNode = "async/"
type AsyncTaskID = String type AsyncTaskID = String
data AsyncTaskStatus = Running | Pending | Received | Started | Failed | Finished | Killed data AsyncTaskStatus = Running
| Pending
| Received
| Started
| Failed
| Finished
| Killed
derive instance genericAsyncTaskStatus :: Generic AsyncTaskStatus _ derive instance genericAsyncTaskStatus :: Generic AsyncTaskStatus _
derive instance eqAsyncTaskStatus :: Eq AsyncTaskStatus derive instance eqAsyncTaskStatus :: Eq AsyncTaskStatus
instance decodeJsonAsyncTaskStatus :: DecodeJson AsyncTaskStatus where instance decodeJsonAsyncTaskStatus :: DecodeJson AsyncTaskStatus where
...@@ -495,44 +507,46 @@ readAsyncTaskStatus "IsRunning" = Running ...@@ -495,44 +507,46 @@ readAsyncTaskStatus "IsRunning" = Running
readAsyncTaskStatus "IsStarted" = Started readAsyncTaskStatus "IsStarted" = Started
readAsyncTaskStatus _ = Running readAsyncTaskStatus _ = Running
newtype AsyncTask = AsyncTask { newtype AsyncTask =
id :: AsyncTaskID AsyncTask { id :: AsyncTaskID
, status :: AsyncTaskStatus , status :: AsyncTaskStatus
} }
derive instance genericAsyncTask :: Generic AsyncTask _ derive instance genericAsyncTask :: Generic AsyncTask _
instance decodeJsonAsyncTask :: DecodeJson AsyncTask where instance decodeJsonAsyncTask :: DecodeJson AsyncTask where
decodeJson json = do decodeJson json = do
obj <- decodeJson json obj <- decodeJson json
id <- obj .: "id" id <- obj .: "id"
status <- obj .: "status" status <- obj .: "status"
pure $ AsyncTask {id, status} pure $ AsyncTask {id, status}
newtype AsyncTaskWithType = AsyncTaskWithType { newtype AsyncTaskWithType =
task :: AsyncTask AsyncTaskWithType { task :: AsyncTask
, typ :: AsyncTaskType , typ :: AsyncTaskType
} }
newtype AsyncProgress =
AsyncProgress { id :: AsyncTaskID
, log :: Array AsyncTaskLog
, status :: AsyncTaskStatus
}
newtype AsyncProgress = AsyncProgress {
id :: AsyncTaskID
, log :: Array AsyncTaskLog
, status :: AsyncTaskStatus
}
derive instance genericAsyncProgress :: Generic AsyncProgress _ derive instance genericAsyncProgress :: Generic AsyncProgress _
instance decodeJsonAsyncProgress :: DecodeJson AsyncProgress where instance decodeJsonAsyncProgress :: DecodeJson AsyncProgress where
decodeJson json = do decodeJson json = do
obj <- decodeJson json obj <- decodeJson json
id <- obj .: "id" id <- obj .: "id"
log <- obj .: "log" log <- obj .: "log"
status <- obj .: "status" status <- obj .: "status"
pure $ AsyncProgress {id, log, status} pure $ AsyncProgress {id, log, status}
newtype AsyncTaskLog = AsyncTaskLog { newtype AsyncTaskLog =
events :: Array String AsyncTaskLog { events :: Array String
, failed :: Int , failed :: Int
, remaining :: Int , remaining :: Int
, succeeded :: Int , succeeded :: Int
} }
derive instance genericAsyncTaskLog :: Generic AsyncTaskLog _ derive instance genericAsyncTaskLog :: Generic AsyncTaskLog _
instance decodeJsonAsyncTaskLog :: DecodeJson AsyncTaskLog where instance decodeJsonAsyncTaskLog :: DecodeJson AsyncTaskLog where
decodeJson json = do decodeJson json = do
......
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