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
142
Issues
142
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
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
gargantext
purescript-gargantext
Commits
b2e1f439
Commit
b2e1f439
authored
Sep 19, 2018
by
Sudhir Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working tree
parent
3dee4b8d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
10 deletions
+29
-10
Tree.purs
src/Gargantext/Components/Tree.purs
+23
-5
Actions.purs
src/Gargantext/Pages/Layout/Actions.purs
+6
-5
No files found.
src/Gargantext/Components/Tree.purs
View file @
b2e1f439
...
...
@@ -4,9 +4,11 @@ import Prelude hiding (div)
import Affjax (defaultRequest, printResponseFormatError, request)
import Affjax.ResponseFormat as ResponseFormat
import Control.Monad.Cont.Trans (lift)
import Data.Argonaut (class DecodeJson, decodeJson, (.?))
import Data.Either (Either(..))
import Data.HTTP.Method (Method(..))
import Data.Newtype (class Newtype)
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
...
...
@@ -14,7 +16,7 @@ import Effect.Console (log)
import React (ReactElement)
import React.DOM (a, div, i, li, text, ul)
import React.DOM.Props (Props, className, href, onClick)
import Thermite (PerformAction, Render, Spec, cotransform, simpleSpec)
import Thermite (PerformAction, Render, Spec, cotransform,
modifyState,
simpleSpec)
type Name = String
type Open = Boolean
...
...
@@ -25,7 +27,7 @@ data NTree a = NTree a (Array (NTree a))
type FTree = NTree LNode
data Action = ToggleFolder ID
data Action = ToggleFolder ID
--| Initialize
type State = FTree
...
...
@@ -36,6 +38,13 @@ performAction :: PerformAction State {} Action
performAction (ToggleFolder i) _ _ = void $
cotransform (\td -> toggleNode i td)
-- performAction Initialize _ _ = void $ do
-- s <- lift $ loadDefaultNode
-- case s of
-- Left err -> modifyState identity
-- Right d -> modifyState (\state -> d)
toggleNode :: Int -> NTree LNode -> NTree LNode
toggleNode sid (NTree (LNode {id, name, nodeType, open}) ary) =
NTree (LNode {id,name, nodeType, open : nopen}) $ map (toggleNode sid) ary
...
...
@@ -124,7 +133,7 @@ fldr open = if open then className "fas fa-folder-open" else className "fas fa-f
newtype LNode = LNode {id :: Int, name :: String, nodeType :: String, open :: Boolean}
--
derive instance newtypeLNode :: Newtype LNode _
derive instance newtypeLNode :: Newtype LNode _
instance decodeJsonLNode :: DecodeJson LNode where
decodeJson json = do
...
...
@@ -134,10 +143,19 @@ instance decodeJsonLNode :: DecodeJson LNode where
nodeType <- obj .? "type"
pure $ LNode {id : id_, name, nodeType, open : true}
loadDefaultNode :: Aff (Either String (Array LNode))
instance decodeJsonFTree :: DecodeJson (NTree LNode) where
decodeJson json = do
obj <- decodeJson json
node <- obj .? "node"
nodes <- obj .? "children"
node' <- decodeJson node
nodes' <- decodeJson nodes
pure $ NTree node' nodes'
loadDefaultNode :: Aff (Either String (NTree LNode))
loadDefaultNode = do
res <- request $ defaultRequest
{ url = "http://localhost:8008/
user
"
{ url = "http://localhost:8008/
tree/1
"
, responseFormat = ResponseFormat.json
, method = Left GET
, headers = []
...
...
src/Gargantext/Pages/Layout/Actions.purs
View file @
b2e1f439
...
...
@@ -3,7 +3,6 @@ module Gargantext.Pages.Layout.Actions where
import Prelude hiding (div)
import Control.Monad.Cont.Trans (lift)
import Data.Array (length)
import Data.Either (Either(..))
import Data.Lens (Prism', prism)
import Effect.Class (liftEffect)
...
...
@@ -80,16 +79,18 @@ performAction Initialize _ state = void do
Left err -> do
modifyState identity
Right d -> do
_ <- modifyState $ _ { initialized = true, ntreeState = d}
page <- lift $ DV.loadPage
case page of
Left err -> do
modifyState identity
Right docs -> do
modifyState $ _ { initialized = true
, ntreeState = if length d > 0
then Tree.exampleTree
--then fnTransform $ unsafePartial $ fromJust $ head d
else Tree.initialState
, ntreeState = d
-- if length d > 0
-- then Tree.exampleTree
-- --then fnTransform $ unsafePartial $ fromJust $ head d
-- else Tree.initialState
, docViewState = docs
}
...
...
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