Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Przemyslaw Kaminski
purescript-gargantext
Commits
20879d3c
Commit
20879d3c
authored
Jun 01, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
[MERGE] dev
parents
eb01d47d
d6d78ff1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
212 additions
and
121 deletions
+212
-121
AsyncTasks.purs
src/Gargantext/AsyncTasks.purs
+46
-0
Forest.purs
src/Gargantext/Components/Forest.purs
+7
-4
Tree.purs
src/Gargantext/Components/Forest/Tree.purs
+51
-55
Box.purs
src/Gargantext/Components/Forest/Tree/Node/Box.purs
+39
-18
Types.purs
src/Gargantext/Types.purs
+69
-44
No files found.
src/Gargantext/AsyncTasks.purs
0 → 100644
View file @
20879d3c
module Gargantext.AsyncTasks where
import Data.Argonaut (decodeJson, class EncodeJson, encodeJson, (:=), (~>), (.:))
import Data.Argonaut.Parser (jsonParser)
import Data.Array as A
import Data.Either (Either(..))
import Data.Map as Map
import Data.Maybe (Maybe(..))
import DOM.Simple.Console (log2)
import Effect (Effect)
import Web.Storage.Storage as WSS
import Gargantext.Prelude
import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2
localStorageKey :: String
localStorageKey = "garg-async-tasks"
type Storage = Map.Map Int (Array GT.AsyncTaskWithType)
empty :: Storage
empty = Map.empty
getAsyncTasks :: Effect Storage
getAsyncTasks = R2.getls >>= WSS.getItem localStorageKey >>= handleMaybe
where
handleMaybe (Just val) = handleEither (parse val >>= decode)
handleMaybe Nothing = pure empty
-- either parsing or decoding could fail, hence two errors
handleEither (Left err) = err *> pure empty
handleEither (Right ss) = pure ss
parse s = mapLeft (log2 "Error parsing serialised sessions:") (jsonParser s)
decode j = mapLeft (log2 "Error decoding serialised sessions:") (decodeJson j)
mapLeft :: forall l m r. (l -> m) -> Either l r -> Either m r
mapLeft f (Left l) = Left (f l)
mapLeft _ (Right r) = Right r
removeTaskFromList :: Array GT.AsyncTaskWithType -> GT.AsyncTaskWithType -> Array GT.AsyncTaskWithType
removeTaskFromList ts (GT.AsyncTaskWithType { task: GT.AsyncTask { id: id' } }) =
A.filter (\(GT.AsyncTaskWithType { task: GT.AsyncTask { id: id'' } }) -> id' /= id'') ts
src/Gargantext/Components/Forest.purs
View file @
20879d3c
...
@@ -3,6 +3,7 @@ module Gargantext.Components.Forest where
...
@@ -3,6 +3,7 @@ module Gargantext.Components.Forest where
import Gargantext.Prelude
import Gargantext.Prelude
import Data.Array as A
import Data.Array as A
import Data.Map as Map
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..))
import Data.Set as Set
import Data.Set as Set
import Data.Tuple (fst)
import Data.Tuple (fst)
...
@@ -11,6 +12,7 @@ import Effect (Effect)
...
@@ -11,6 +12,7 @@ import Effect (Effect)
import Reactix as R
import Reactix as R
import Reactix.DOM.HTML as H
import Reactix.DOM.HTML as H
import Gargantext.AsyncTasks as GAT
import Gargantext.Components.Forest.Tree (treeView)
import Gargantext.Components.Forest.Tree (treeView)
import Gargantext.Components.Forest.Tree.Node.Action (Reload)
import Gargantext.Components.Forest.Tree.Node.Action (Reload)
import Gargantext.Ends (Frontends)
import Gargantext.Ends (Frontends)
...
@@ -35,15 +37,16 @@ forestCpt = R.hooksComponent "G.C.Forest.forest" cpt where
...
@@ -35,15 +37,16 @@ forestCpt = R.hooksComponent "G.C.Forest.forest" cpt where
-- NOTE: this is a hack to reload the tree view on demand
-- NOTE: this is a hack to reload the tree view on demand
reload <- R.useState' (0 :: Reload)
reload <- R.useState' (0 :: Reload)
openNodes <- R2.useLocalStorageState R2.openNodesKey (Set.empty :: OpenNodes)
openNodes <- R2.useLocalStorageState R2.openNodesKey (Set.empty :: OpenNodes)
asyncTasks <- R2.useLocalStorageState GAT.localStorageKey GAT.empty
R2.useCache
R2.useCache
(frontends /\ route /\ sessions /\ fst openNodes /\ fst extReload /\ fst reload)
(frontends /\ route /\ sessions /\ fst openNodes /\ fst extReload /\ fst reload
/\ fst asyncTasks
)
(cpt' openNodes reload showLogin)
(cpt' openNodes
asyncTasks
reload showLogin)
cpt' openNodes
reload showLogin (frontends /\ route /\ sessions
/\ _ /\ _ /\ _) = do
cpt' openNodes
asyncTasks reload showLogin (frontends /\ route /\ sessions /\ _
/\ _ /\ _ /\ _) = do
pure $ R.fragment $ A.cons (plus showLogin) trees
pure $ R.fragment $ A.cons (plus showLogin) trees
where
where
trees = tree <$> unSessions sessions
trees = tree <$> unSessions sessions
tree s@(Session {treeId}) =
tree s@(Session {treeId}) =
treeView { root: treeId, frontends, mCurrentRoute: Just route, session: s, openNodes, reload }
treeView { root: treeId,
asyncTasks,
frontends, mCurrentRoute: Just route, session: s, openNodes, reload }
plus :: R2.Setter Boolean -> R.Element
plus :: R2.Setter Boolean -> R.Element
plus showLogin =
plus showLogin =
...
...
src/Gargantext/Components/Forest/Tree.purs
View file @
20879d3c
module Gargantext.Components.Forest.Tree where
module Gargantext.Components.Forest.Tree where
import DOM.Simple.Console (log2)
import Data.Array as A
import Data.Array as A
import Data.Maybe (Maybe)
import Data.Map as Map
import Data.Maybe (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 ((/\))
import DOM.Simple.Console (log2)
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Effect.Class (liftEffect)
import Reactix as R
import Reactix as R
...
@@ -13,13 +15,14 @@ import Reactix.DOM.HTML as H
...
@@ -13,13 +15,14 @@ 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.AsyncTasks as GAT
import Gargantext.Components.Forest.Tree.Node.Action (Action(..), FTree, ID, LNode(..), NTree(..), Reload, RenameValue(..), Tree, deleteNode, loadNode, renameNode)
import Gargantext.Components.Forest.Tree.Node.Action (Action(..), FTree, ID, LNode(..), NTree(..), Reload, RenameValue(..), Tree, deleteNode, loadNode, renameNode)
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.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
, Tasks, tasksStruct
)
import Gargantext.Ends (Frontends)
import Gargantext.Ends (Frontends)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude (Unit, bind, const, discard, map, pure, void, ($), (+), (/=), (<>))
import Gargantext.Prelude (Unit, bind, const, discard, map, pure, void, ($), (+), (/=), (<>)
, identity
)
import Gargantext.Routes (AppRoute)
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
...
@@ -36,6 +39,7 @@ type CommonProps =
...
@@ -36,6 +39,7 @@ type CommonProps =
------------------------------------------------------------------------
------------------------------------------------------------------------
type Props = ( root :: ID
type Props = ( root :: ID
, asyncTasks :: R.State GAT.Storage
| CommonProps
| CommonProps
)
)
...
@@ -55,20 +59,23 @@ treeLoadView p = R.createElement treeLoadViewCpt p []
...
@@ -55,20 +59,23 @@ treeLoadView p = R.createElement treeLoadViewCpt p []
treeLoadViewCpt :: R.Component Props
treeLoadViewCpt :: R.Component Props
treeLoadViewCpt = R.hooksComponent "TreeLoadView" cpt
treeLoadViewCpt = R.hooksComponent "TreeLoadView" cpt
where
where
cpt {
root, mCurrentRoute, session, frontends, openNodes, reload} _
= do
cpt {
root, asyncTasks, mCurrentRoute, session, frontends, openNodes, reload } _children
= do
let fetch _ = loadNode session root
let fetch _ = loadNode session root
let paint loaded = loadedTreeView { tree: loaded
let paint loaded = loadedTreeView {
asyncTasks
, frontends
, mCurrentRoute
, mCurrentRoute
, openNodes
, reload
, session
, session
,
frontends
,
tasks: tasksStruct root asyncTasks reload
,
openNodes, reloa
d
,
tree: loade
d
}
}
useLoader { root
useLoader { root, counter: fst reload } fetch paint
, counter: fst reload
}
fetch paint
type TreeViewProps = ( tree :: FTree
type TreeViewProps = ( asyncTasks :: R.State GAT.Storage
, tree :: FTree
, tasks :: Record Tasks
| CommonProps
| CommonProps
)
)
...
@@ -78,29 +85,28 @@ loadedTreeView p = R.createElement loadedTreeViewCpt p []
...
@@ -78,29 +85,28 @@ loadedTreeView p = R.createElement loadedTreeViewCpt p []
loadedTreeViewCpt :: R.Component TreeViewProps
loadedTreeViewCpt :: R.Component TreeViewProps
loadedTreeViewCpt = R.hooksComponent "LoadedTreeView" cpt
loadedTreeViewCpt = R.hooksComponent "LoadedTreeView" cpt
where
where
cpt {tree, mCurrentRoute, session, frontends, openNodes, reload} _ = do
cpt { asyncTasks, frontends, mCurrentRoute, openNodes, reload, tasks, tree, session } _ = do
tasks <- R.useState' []
pure $ H.div {className: "tree"}
pure $ H.div {className: "tree"}
[ toHtml { frontends, mCurrentRoute, openNodes, reload, session, tasks, tree } ]
[ toHtml {
asyncTasks,
frontends, mCurrentRoute, openNodes, reload, session, tasks, tree } ]
------------------------------------------------------------------------
------------------------------------------------------------------------
type ToHtmlProps =
type ToHtmlProps =
(
(
tasks :: R.State (Array GT.AsyncTaskWithType)
asyncTasks :: R.State GAT.Storage
, tasks :: Record Tasks
, tree :: FTree
, tree :: FTree
| CommonProps
| CommonProps
)
)
toHtml :: Record ToHtmlProps -> R.Element
toHtml :: Record ToHtmlProps -> R.Element
toHtml p@{ frontends
toHtml p@{ asyncTasks
, frontends
, mCurrentRoute
, mCurrentRoute
, openNodes
, openNodes
, reload: reload@(_ /\ setReload)
, reload: reload@(_ /\ setReload)
, session
, session
, tasks: tasks@(asyncTasks /\ setAsyncTasks)
, tasks: tasks@{ onTaskAdd, onTaskFinish, tasks: tasks' }
, tree: tree@(NTree (LNode {id, name, nodeType}) ary)
, tree: tree@(NTree (LNode {id, name, nodeType}) ary) } = R.createElement el {} []
} = 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
...
@@ -118,31 +124,26 @@ toHtml p@{ frontends
...
@@ -118,31 +124,26 @@ toHtml p@{ frontends
pure $ H.ul {}
pure $ H.ul {}
[ H.li {}
[ H.li {}
( [ nodeMainSpan { id
( [ nodeMainSpan { id
, asyncTasks
, dispatch: pAction
, dispatch: pAction
, folderOpen
, folderOpen
, frontends
, frontends
, mCurrentRoute
, mCurrentRoute
, name
, name
, nodeType
, nodeType
, onAsyncTaskFinish
, session
, session
, tasks
} ]
} ]
<> childNodes (Record.merge commonProps
<> childNodes (Record.merge commonProps
{ children: ary
{ asyncTasks
, children: ary
, folderOpen })
, folderOpen })
)
)
]
]
onAsyncTaskFinish (GT.AsyncTaskWithType {task: GT.AsyncTask {id: id'}}) = do
setAsyncTasks $ const newAsyncTasks
setReload (_ + 1)
where
newAsyncTasks = A.filter (\(GT.AsyncTaskWithType {task: GT.AsyncTask {id: id''}}) -> id' /= id'') asyncTasks
type ChildNodesProps =
type ChildNodesProps =
( children :: Array FTree
( asyncTasks :: R.State GAT.Storage
, children :: Array FTree
, folderOpen :: R.State Boolean
, folderOpen :: R.State Boolean
| CommonProps
| CommonProps
)
)
...
@@ -150,24 +151,23 @@ type ChildNodesProps =
...
@@ -150,24 +151,23 @@ type ChildNodesProps =
childNodes :: Record ChildNodesProps -> Array R.Element
childNodes :: Record ChildNodesProps -> Array R.Element
childNodes { children: [] } = []
childNodes { children: [] } = []
childNodes { folderOpen: (false /\ _) } = []
childNodes { folderOpen: (false /\ _) } = []
childNodes props@{ children } =
childNodes props@{ asyncTasks, children, reload } =
map (\ctree -> childNode {tree: ctree, asyncTasks: []}) $ sorted children
map (\ctree@(NTree (LNode {id}) _) ->
where
toHtml (Record.merge commonProps {
commonProps = RecordE.pick props :: Record CommonProps
asyncTasks
sorted :: Array FTree -> Array FTree
, tasks: tasksStruct id asyncTasks reload
sorted = A.sortWith (\(NTree (LNode {id}) _) -> id)
, tree: ctree
childNode :: Tree -> R.Element
})) $ sorted children
childNode props = R.createElement el props []
where
el = R.hooksComponent "ChildNodeView" cpt
commonProps = RecordE.pick props :: Record CommonProps
cpt {tree, asyncTasks} _ = do
sorted :: Array FTree -> Array FTree
tasks <- R.useState' asyncTasks
sorted = A.sortWith (\(NTree (LNode {id}) _) -> id)
pure $ toHtml (Record.merge commonProps { tasks, tree })
type PerformActionProps =
type PerformActionProps =
( openNodes :: R.State OpenNodes
( openNodes :: R.State OpenNodes
, reload :: R.State Reload
, reload :: R.State Reload
, session :: Session
, session :: Session
, tasks :: R
.State (Array GT.AsyncTaskWithType)
, tasks :: R
ecord Tasks
, tree :: FTree
, tree :: FTree
)
)
...
@@ -185,10 +185,9 @@ performAction p@{ openNodes: (_ /\ setOpenNodes)
...
@@ -185,10 +185,9 @@ performAction p@{ openNodes: (_ /\ setOpenNodes)
performAction { reload: (_ /\ setReload)
performAction { reload: (_ /\ setReload)
, session
, session
, tasks: (_ /\ setAsyncTasks)
, tasks: { onTaskAdd }
, tree: (NTree (LNode {id}) _)
, tree: (NTree (LNode {id}) _) } (SearchQuery task) = do
} (SearchQuery task) = do
liftEffect $ onTaskAdd task
liftEffect $ setAsyncTasks $ A.cons task
liftEffect $ log2 "[performAction] SearchQuery task:" task
liftEffect $ log2 "[performAction] SearchQuery task:" task
performAction { reload: (_ /\ setReload)
performAction { reload: (_ /\ setReload)
...
@@ -206,21 +205,18 @@ performAction p@{ reload: (_ /\ setReload)
...
@@ -206,21 +205,18 @@ performAction p@{ reload: (_ /\ setReload)
performAction p@{ openNodes: (_ /\ setOpenNodes)
performAction p@{ openNodes: (_ /\ setOpenNodes)
, reload: (_ /\ setReload)
, reload: (_ /\ setReload)
, tasks: (_ /\ setAsyncTasks)
, 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 <- addNode session id $ AddNodeValue {name, nodeType}
task <- addNode session id $ AddNodeValue {name, nodeType}
-- liftEffect $ setAsyncTasks $ A.cons task
liftEffect do
liftEffect do
setOpenNodes (Set.insert (mkNodeId session id))
setOpenNodes (Set.insert (mkNodeId session id))
performAction p RefreshTree
performAction p RefreshTree
performAction { session
performAction { session
, tasks:
(_ /\ setAsyncTasks)
, tasks:
{ onTaskAdd }
, tree: (NTree (LNode {id}) _) } (UploadFile nodeType fileType mName contents) = do
, tree: (NTree (LNode {id}) _) } (UploadFile nodeType fileType mName contents) = do
task <- uploadFile session nodeType id fileType {mName, contents}
task <- uploadFile session nodeType id fileType {mName, contents}
liftEffect $
setAsyncTasks $ A.cons
task
liftEffect $
onTaskAdd
task
liftEffect $ log2 "uploaded, task:" task
liftEffect $ log2 "uploaded, task:" task
performAction { reload: (_ /\ setReload) } RefreshTree = do
performAction { reload: (_ /\ setReload) } RefreshTree = do
...
...
src/Gargantext/Components/Forest/Tree/Node/Box.purs
View file @
20879d3c
module Gargantext.Components.Forest.Tree.Node.Box where
module Gargantext.Components.Forest.Tree.Node.Box where
import Gargantext.Prelude
import Data.Array as A
import Data.Map as Map
import Data.Maybe (Maybe(..), maybe)
import Data.Nullable (Nullable, null)
import Data.Tuple (fst, Tuple(..))
import Data.Tuple.Nested ((/\))
import DOM.Simple as DOM
import DOM.Simple as DOM
import DOM.Simple.Event
import DOM.Simple.Event
import DOM.Simple.EventListener
import DOM.Simple.EventListener
import DOM.Simple.Types
import DOM.Simple.Types
import DOM.Simple.Window
import DOM.Simple.Window
import Data.Maybe (Maybe(..))
import Data.Nullable (Nullable, null)
import Data.Tuple (fst, Tuple(..))
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect (Effect)
import Effect.Aff (Aff, launchAff, launchAff_)
import Effect.Aff (Aff, launchAff, launchAff_)
import Effect.Class (liftEffect)
import Effect.Class (liftEffect)
import Effect.Console
import Effect.Console
import Effect.Uncurried (mkEffectFn1)
import Effect.Uncurried (mkEffectFn1)
import React.SyntheticEvent as E
import Reactix as R
import Reactix.DOM.HTML as H
import URI.Extra.QueryPairs as NQP
import URI.Query as Query
import Web.File.FileReader.Aff (readAsText)
import Gargantext.Prelude
import Gargantext.AsyncTasks as GAT
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,
Reload,
UploadFileContents(..))
import Gargantext.Components.Forest.Tree.Node.Action.Add (NodePopup(..), addNodeView)
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)
...
@@ -38,15 +48,27 @@ import Gargantext.Types as GT
...
@@ -38,15 +48,27 @@ import Gargantext.Types as GT
import Gargantext.Utils (glyphicon, glyphiconActive)
import Gargantext.Utils (glyphicon, glyphiconActive)
import Gargantext.Utils.Popover as Popover
import Gargantext.Utils.Popover as Popover
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix as R2
import React.SyntheticEvent as E
import Reactix as R
import Reactix.DOM.HTML as H
import URI.Extra.QueryPairs as NQP
import URI.Query as Query
import Web.File.FileReader.Aff (readAsText)
type Dispatch = Action -> Aff Unit
type Dispatch = Action -> Aff Unit
type Tasks =
(
onTaskAdd :: GT.AsyncTaskWithType -> Effect Unit
, onTaskFinish :: GT.AsyncTaskWithType -> Effect Unit
, tasks :: Array GT.AsyncTaskWithType
)
tasksStruct :: Int -> R.State GAT.Storage -> R.State Reload -> Record Tasks
tasksStruct id (asyncTasks /\ setAsyncTasks) (_ /\ setReload) = { onTaskAdd, onTaskFinish, tasks }
where
tasks = maybe [] identity $ Map.lookup id asyncTasks
onTaskAdd t = do
setReload (_ + 1)
setAsyncTasks $ Map.alter (maybe (Just [t]) $ (\ts -> Just $ A.cons t ts)) id
onTaskFinish t = do
setReload (_ + 1)
setAsyncTasks $ Map.alter (maybe Nothing $ (\ts -> Just $ GAT.removeTaskFromList ts t)) id
type CommonProps =
type CommonProps =
( dispatch :: Dispatch
( dispatch :: Dispatch
, session :: Session
, session :: Session
...
@@ -55,13 +77,12 @@ type CommonProps =
...
@@ -55,13 +77,12 @@ type CommonProps =
-- Main Node
-- Main Node
type NodeMainSpanProps =
type NodeMainSpanProps =
( id :: ID
( id :: ID
, asyncTasks :: Array GT.AsyncTaskWithType
, folderOpen :: R.State Boolean
, folderOpen :: R.State Boolean
, frontends :: Frontends
, frontends :: Frontends
, mCurrentRoute :: Maybe Routes.AppRoute
, mCurrentRoute :: Maybe Routes.AppRoute
, name :: Name
, name :: Name
, nodeType :: GT.NodeType
, nodeType :: GT.NodeType
,
onAsyncTaskFinish :: GT.AsyncTaskWithType -> Effect Unit
,
tasks :: Record Tasks
| CommonProps
| CommonProps
)
)
...
@@ -70,7 +91,7 @@ nodeMainSpan :: Record NodeMainSpanProps
...
@@ -70,7 +91,7 @@ nodeMainSpan :: Record NodeMainSpanProps
nodeMainSpan p@{ dispatch, folderOpen, frontends, session } = R.createElement el p []
nodeMainSpan p@{ dispatch, folderOpen, frontends, session } = R.createElement el p []
where
where
el = R.hooksComponent "G.C.F.T.N.B.NodeMainSpan" cpt
el = R.hooksComponent "G.C.F.T.N.B.NodeMainSpan" cpt
cpt props@{id,
asyncTasks, mCurrentRoute, name, nodeType, onAsyncTaskFinish
} _ = do
cpt props@{id,
mCurrentRoute, name, nodeType, tasks: { onTaskFinish, tasks }
} _ = do
-- only 1 popup at a time is allowed to be opened
-- only 1 popup at a time is allowed to be opened
droppedFile <- R.useState' (Nothing :: Maybe DroppedFile)
droppedFile <- R.useState' (Nothing :: Maybe DroppedFile)
isDragOver <- R.useState' false
isDragOver <- R.useState' false
...
@@ -102,8 +123,8 @@ nodeMainSpan p@{ dispatch, folderOpen, frontends, session } = R.createElement el
...
@@ -102,8 +123,8 @@ nodeMainSpan p@{ dispatch, folderOpen, frontends, session } = R.createElement el
, H.div {} (map (\t -> asyncProgressBar { asyncTask: t
, H.div {} (map (\t -> asyncProgressBar { asyncTask: t
, barType: Pie
, barType: Pie
, corpusId: id
, corpusId: id
, onFinish: const $ on
Async
TaskFinish t
, onFinish: const $ onTaskFinish t
, session })
asyncT
asks)
, session })
t
asks)
]
]
where
where
SettingsBox {show: showBox} = settingsBox nodeType
SettingsBox {show: showBox} = settingsBox nodeType
...
...
src/Gargantext/Types.purs
View file @
20879d3c
...
@@ -439,14 +439,11 @@ type AffTableResult a = Aff (TableResult a)
...
@@ -439,14 +439,11 @@ type AffTableResult a = Aff (TableResult a)
data Mode = Authors | Sources | Institutes | Terms
data Mode = Authors | Sources | Institutes | Terms
derive instance genericMode :: Generic Mode _
derive instance genericMode :: Generic Mode _
instance showMode :: Show Mode where
instance showMode :: Show Mode where
show = genericShow
show = genericShow
derive instance eqMode :: Eq Mode
derive instance eqMode :: Eq Mode
instance ordMode :: Ord Mode where
instance ordMode :: Ord Mode where
compare = genericCompare
compare = genericCompare
instance encodeMode :: EncodeJson Mode where
instance encodeMode :: EncodeJson Mode where
encodeJson x = encodeJson $ show x
encodeJson x = encodeJson $ show x
...
@@ -457,41 +454,51 @@ modeTabType Institutes = CTabInstitutes
...
@@ -457,41 +454,51 @@ modeTabType Institutes = CTabInstitutes
modeTabType Terms = CTabTerms
modeTabType Terms = CTabTerms
modeFromString :: String -> Maybe Mode
modeFromString :: String -> Maybe Mode
modeFromString "Authors"
= Just Authors
modeFromString "Authors" = Just Authors
modeFromString "Sources"
= Just Sources
modeFromString "Sources" = Just Sources
modeFromString "Institutes" = Just Institutes
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
data AsyncTaskType = Form
| GraphT
| GraphT
| Query
| Query
| AddNode
| AddNode
| UpdateNode
derive instance genericAsyncTaskType :: Generic AsyncTaskType _
derive instance genericAsyncTaskType :: Generic AsyncTaskType _
instance eqAsyncTaskType :: Eq AsyncTaskType where
eq = genericEq
instance showAsyncTaskType :: Show AsyncTaskType where
show = genericShow
instance encodeJsonAsyncTaskType :: EncodeJson AsyncTaskType where
encodeJson t = encodeJson $ show t
instance decodeJsonAsyncTaskType :: DecodeJson AsyncTaskType where
decodeJson json = do
obj <- decodeJson json
case obj of
"Form" -> pure Form
"GraphT" -> pure GraphT
"Query" -> pure Query
"AddNode" -> pure AddNode
s -> Left ("Unknown string " <> s)
asyncTaskTypePath :: AsyncTaskType -> String
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 AddNode = "async/nobody/"
asyncTaskTypePath AddNode = "async/nobody/"
asyncTaskTypePath UpdateNode = "async/"
type AsyncTaskID = String
type AsyncTaskID = String
data AsyncTaskStatus = Running
data AsyncTaskStatus = Running | Pending | Received | Started | Failed | Finished | Killed
| Pending
| Received
| Started
| Failed
| Finished
| Killed
derive instance genericAsyncTaskStatus :: Generic AsyncTaskStatus _
derive instance genericAsyncTaskStatus :: Generic AsyncTaskStatus _
instance showAsyncTaskStatus :: Show AsyncTaskStatus where
show = genericShow
derive instance eqAsyncTaskStatus :: Eq AsyncTaskStatus
derive instance eqAsyncTaskStatus :: Eq AsyncTaskStatus
instance encodeJsonAsyncTaskStatus :: EncodeJson AsyncTaskStatus where
encodeJson s = encodeJson $ show s
instance decodeJsonAsyncTaskStatus :: DecodeJson AsyncTaskStatus where
instance decodeJsonAsyncTaskStatus :: DecodeJson AsyncTaskStatus where
decodeJson json = do
decodeJson json = do
obj <- decodeJson json
obj <- decodeJson json
...
@@ -507,46 +514,64 @@ readAsyncTaskStatus "IsRunning" = Running
...
@@ -507,46 +514,64 @@ readAsyncTaskStatus "IsRunning" = Running
readAsyncTaskStatus "IsStarted" = Started
readAsyncTaskStatus "IsStarted" = Started
readAsyncTaskStatus _ = Running
readAsyncTaskStatus _ = Running
newtype AsyncTask =
newtype AsyncTask =
AsyncTask {
AsyncTask {
id :: AsyncTaskID
id :: AsyncTaskID
, status :: AsyncTaskStatus
, status :: AsyncTaskStatus
}
}
derive instance genericAsyncTask :: Generic AsyncTask _
derive instance genericAsyncTask :: Generic AsyncTask _
instance eqAsyncTask :: Eq AsyncTask where
eq = genericEq
instance encodeJsonAsyncTask :: EncodeJson AsyncTask where
encodeJson (AsyncTask { id, status }) =
"id" := id
~> "status" := status
~> jsonEmptyObject
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 { task :: AsyncTask
, typ :: AsyncTaskType
}
newtype AsyncProgress =
AsyncProgress { id :: AsyncTaskID
, log :: Array AsyncTaskLog
, status :: AsyncTaskStatus
}
newtype AsyncTaskWithType = AsyncTaskWithType {
task :: AsyncTask
, typ :: AsyncTaskType
}
derive instance genericAsyncTaskWithType :: Generic AsyncTaskWithType _
instance eqAsyncTaskWithType :: Eq AsyncTaskWithType where
eq = genericEq
instance encodeJsonAsyncTaskWithType :: EncodeJson AsyncTaskWithType where
encodeJson (AsyncTaskWithType { task, typ }) =
"task" := task
~> "typ" := typ
~> jsonEmptyObject
instance decodeJsonAsyncTaskWithType :: DecodeJson AsyncTaskWithType where
decodeJson json = do
obj <- decodeJson json
task <- obj .: "task"
typ <- obj .: "typ"
pure $ AsyncTaskWithType { task, typ }
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 =
newtype AsyncTaskLog = AsyncTaskLog {
AsyncTaskLog { events :: Array String
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment