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
0
Merge Requests
0
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
Grégoire Locqueville
purescript-gargantext
Commits
7064842c
Commit
7064842c
authored
Dec 06, 2018
by
Sudhir Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
graph api calling is done
parent
4b5da332
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
7 deletions
+51
-7
Graph.purs
src/Gargantext/Pages/Corpus/Graph.purs
+51
-7
No files found.
src/Gargantext/Pages/Corpus/Graph.purs
View file @
7064842c
...
...
@@ -4,23 +4,25 @@ import Effect.Unsafe
import Gargantext.Prelude
import Affjax (defaultRequest, request)
import Affjax.ResponseFormat (printResponseFormatError)
import Affjax.ResponseFormat (
ResponseFormat(..),
printResponseFormatError)
import Affjax.ResponseFormat as ResponseFormat
import Control.Monad.Cont.Trans (lift)
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.?), (.??), (:=), (~>))
import Data.Argonaut (decodeJson)
import Data.Array (length, mapWithIndex, (!!))
import Data.Either (Either(..))
import Data.HTTP.Method (Method(..))
import Data.Int (toNumber)
import Data.Maybe (Maybe(..), fromJust)
import Data.Int (
fromString,
toNumber)
import Data.Maybe (Maybe(..), fromJust
, fromMaybe
)
import Data.Newtype (class Newtype)
import Effect.Aff (Aff)
import Effect.Aff (Aff, attempt)
import Effect.Aff.Class (liftAff)
import Effect.Class (liftEffect)
import Effect.Console (log)
import Gargantext.Components.GraphExplorer.Sigmajs (Color(Color), SigmaEasing, SigmaGraphData(SigmaGraphData), SigmaNode, SigmaSettings, canvas, edgeShape, edgeShapes, forceAtlas2, sStyle, sigma, sigmaEasing, sigmaEdge, sigmaEnableWebGL, sigmaNode, sigmaSettings)
import Gargantext.Components.GraphExplorer.Types (Cluster(..), Edge(..), GraphData(..), Legend(..), Node(..), getLegendData)
import Gargantext.Config as Config
import Gargantext.Config.REST (get)
import Gargantext.Config.REST (get
, post
)
import Gargantext.Utils (getter)
import Math (cos, sin)
import Partial.Unsafe (unsafePartial)
...
...
@@ -50,6 +52,19 @@ newtype State = State
, selectedNode :: Maybe SelectedNode
, showSidePanel :: Boolean
, showControls :: Boolean
, nodeResults :: Array NodeResults
}
newtype NodeQuery = NodeQuery
{
query :: Array String
, parentId :: Int
}
newtype NodeResults = NodeResults
{
rid :: Int
, title :: String
, authors :: String
}
initialState :: State
...
...
@@ -61,6 +76,7 @@ initialState = State
, selectedNode : Nothing
, showSidePanel : false
, showControls : false
, nodeResults : []
}
graphSpec :: Spec State {} Action
...
...
@@ -75,8 +91,11 @@ performAction (LoadGraph fp) _ _ = void do
-- graph.
modifyState \(State s) -> State s {graphData = resp, sigmaGraphData = Just $ convert resp, legendData = getLegendData resp}
performAction (SelectNode node) _ _ = void do
modifyState $ \(State s) -> State s {selectedNode = pure node}
performAction (SelectNode (SelectedNode node)) _ _ = void do
response <- lift $selectNodeApi $ NodeQuery {query : [node.label], parentId : fromMaybe 0 $ fromString $ node.id}
modifyState $ \(State s) -> State s {nodeResults = response }
--modifyState $ \(State s) -> State s {selectedNode = pure $ SelectedNode node}
performAction (ShowSidePanel b) _ (State state) = void do
modifyState $ \(State s) -> State s {showSidePanel = b }
...
...
@@ -372,6 +391,7 @@ specOld = simpleSpec performAction render'
, style : sStyle { height : "95%"}
, onClickNode : \e -> unsafePerformEffect $ do
_ <- log " hello 2"
--_ <- attempt $ selectNodeApi $ NodeQuery {query : [], parentId : 0}
--logs $ unsafeCoerce e
_ <- d $ ShowSidePanel true
_ <- d $ SelectNode $ SelectedNode {id : (unsafeCoerce e).data.node.id, label : (unsafeCoerce e).data.node.label}
...
...
@@ -492,3 +512,27 @@ specOld = simpleSpec performAction render'
getNodes :: Int -> Aff GraphData
getNodes graphId = get $ Config.toUrl Config.Back Config.Graph $ Just graphId
selectNodeApi :: NodeQuery -> Aff (Array NodeResults)
selectNodeApi = post $ getUrl <> "search"
instance encodeJsonNQuery :: EncodeJson NodeQuery where
encodeJson (NodeQuery post)
= "query" := post.query
~> "parent_id" := post.parentId
~> jsonEmptyObject
instance decodeJsonNResults :: DecodeJson NodeResults where
decodeJson json = do
obj <- decodeJson json
rid <- obj .? "id"
title <- obj .? "title"
authors <- obj .? "authors"
pure $ NodeResults {rid,title,authors}
getUrl :: String
getUrl = back.baseUrl <> back.prePath
where
back = Config.endConfig.back
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