Commit 044be1f5 authored by Sudhir Kumar's avatar Sudhir Kumar

graph data loading, need to fix types once I can see data

parent 688c795a
...@@ -15,6 +15,7 @@ import Data.HTTP.Method (Method(..)) ...@@ -15,6 +15,7 @@ import Data.HTTP.Method (Method(..))
import Data.Int (fromString, toNumber) import Data.Int (fromString, toNumber)
import Data.Maybe (Maybe(..), fromJust, fromMaybe) import Data.Maybe (Maybe(..), fromJust, fromMaybe)
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import Data.String (joinWith)
import Effect.Aff (Aff, attempt) import Effect.Aff (Aff, attempt)
import Effect.Aff.Class (liftAff) import Effect.Aff.Class (liftAff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
...@@ -52,7 +53,8 @@ newtype State = State ...@@ -52,7 +53,8 @@ newtype State = State
, selectedNode :: Maybe SelectedNode , selectedNode :: Maybe SelectedNode
, showSidePanel :: Boolean , showSidePanel :: Boolean
, showControls :: Boolean , showControls :: Boolean
, nodeResults :: Array NodeResults , nodeResults :: Array NodeResults
, corpusId :: Int
} }
newtype NodeQuery = NodeQuery newtype NodeQuery = NodeQuery
...@@ -77,6 +79,7 @@ initialState = State ...@@ -77,6 +79,7 @@ initialState = State
, showSidePanel : false , showSidePanel : false
, showControls : false , showControls : false
, nodeResults : [] , nodeResults : []
, corpusId : 0
} }
graphSpec :: Spec State {} Action graphSpec :: Spec State {} Action
...@@ -85,17 +88,21 @@ graphSpec = simpleSpec performAction render ...@@ -85,17 +88,21 @@ graphSpec = simpleSpec performAction render
performAction :: PerformAction State {} Action performAction :: PerformAction State {} Action
performAction (LoadGraph fp) _ _ = void do performAction (LoadGraph fp) _ _ = void do
_ <- logs fp _ <- logs fp
_ <- modifyState \(State s) -> State s { sigmaGraphData = Nothing} _ <- modifyState \(State s) -> State s {corpusId = fp, sigmaGraphData = Nothing}
resp <- lift $ getNodes fp resp <- lift $ getNodes fp
-- TODO: here one might `catchError getNodes` to visually empty the -- TODO: here one might `catchError getNodes` to visually empty the
-- graph. -- graph.
modifyState \(State s) -> State s {graphData = resp, sigmaGraphData = Just $ convert resp, legendData = getLegendData resp} modifyState \(State s) -> State s {graphData = resp, sigmaGraphData = Just $ convert resp, legendData = getLegendData resp}
performAction (SelectNode (SelectedNode node)) _ _ = void do performAction (SelectNode (SelectedNode node)) _ (State state) = void do
response <- lift $selectNodeApi $ NodeQuery {query : [node.label], parentId : fromMaybe 0 $ fromString $ node.id} _ <- modifyState $ \(State s) -> State s {selectedNode = pure $ SelectedNode node}
response <- lift $ attempt $ selectNodeApi $ NodeQuery {query : [node.label], parentId : state.corpusId}
modifyState $ \(State s) -> State s {nodeResults = response } case response of
--modifyState $ \(State s) -> State s {selectedNode = pure $ SelectedNode node} Left err -> do
_ <- liftEffect $ log $ show err
modifyState identity
Right resp -> do
modifyState $ \(State s) -> State s {nodeResults = resp}
performAction (ShowSidePanel b) _ (State state) = void do performAction (ShowSidePanel b) _ (State state) = void do
modifyState $ \(State s) -> State s {showSidePanel = b } modifyState $ \(State s) -> State s {showSidePanel = b }
...@@ -411,8 +418,10 @@ specOld = simpleSpec performAction render' ...@@ -411,8 +418,10 @@ specOld = simpleSpec performAction render'
[ div [className "row"] [ div [className "row"]
[ div [_id "sidepanel" , style {borderBottom : "1px solid black"}] [ div [_id "sidepanel" , style {borderBottom : "1px solid black"}]
[ case st.selectedNode of [ case st.selectedNode of
Nothing -> span [] [] Nothing -> span [] [ text "dummy text"]
Just selectedNode -> p [] [text $ "selected Node : " <> getter _.label selectedNode Just selectedNode -> p [] [ text $ "selected Node : " <> getter _.label selectedNode
, text $ (joinWith ", " ( getTitle st.nodeResults))
, text $ (joinWith ", " (getAuthors st.nodeResults))
, br' , br'
, p [] [button [className "btn btn-primary", style {marginBottom : "18px"}] [text "Remove"]] , p [] [button [className "btn btn-primary", style {marginBottom : "18px"}] [text "Remove"]]
] ]
...@@ -510,6 +519,13 @@ specOld = simpleSpec performAction render' ...@@ -510,6 +519,13 @@ specOld = simpleSpec performAction render'
] ]
] ]
getTitle :: Array NodeResults -> Array String
getTitle ary = map (\(NodeResults s)-> s.title) ary
getAuthors :: Array NodeResults -> Array String
getAuthors ary = map (\(NodeResults s ) -> s.authors) ary
getNodes :: Int -> Aff GraphData getNodes :: Int -> Aff GraphData
getNodes graphId = get $ Config.toUrl Config.Back Config.Graph $ Just graphId getNodes graphId = get $ Config.toUrl Config.Back Config.Graph $ Just graphId
......
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