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
3dee4b8d
Commit
3dee4b8d
authored
Sep 18, 2018
by
Sudhir Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tree data structure modified and builds successfully
parent
e7366db6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
44 deletions
+44
-44
Tree.purs
src/Gargantext/Components/Tree.purs
+33
-31
States.purs
src/Gargantext/Pages/Layout/States.purs
+11
-13
No files found.
src/Gargantext/Components/Tree.purs
View file @
3dee4b8d
...
...
@@ -7,7 +7,6 @@ import Affjax.ResponseFormat as ResponseFormat
import Data.Argonaut (class DecodeJson, decodeJson, (.?))
import Data.Either (Either(..))
import Data.HTTP.Method (Method(..))
import Data.Tuple (Tuple(..))
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
...
...
@@ -22,51 +21,53 @@ type Open = Boolean
type URL = String
type ID = Int
data NTree a = N
Leaf a | NNode ID Open Name
(Array (NTree a))
data NTree a = N
Tree a
(Array (NTree a))
type FTree = NTree
(Tuple Name URL)
type FTree = NTree
LNode
data Action = ToggleFolder ID
type State = FTree
initialState :: State
initialState = N
Leaf (Tuple "" "")
initialState = N
Tree (LNode {id : 1, name : "", nodeType : "", open : true}) []
performAction :: PerformAction State {} Action
performAction (ToggleFolder i) _ _ = void $
cotransform (\td -> toggleNode i td)
toggleNode ::
forall t10. Int -> NTree t10 -> NTree t10
toggleNode sid (N
Node iid open name
ary) =
N
Node iid nopen name
$ map (toggleNode sid) ary
toggleNode ::
Int -> NTree LNode -> NTree LNode
toggleNode sid (N
Tree (LNode {id, name, nodeType, open})
ary) =
N
Tree (LNode {id,name, nodeType, open : nopen})
$ map (toggleNode sid) ary
where
nopen = if sid == iid then not open else open
toggleNode sid a = a
nopen = if sid == id then not open else open
------------------------------------------------------------------------
-- Realistic Tree for the UI
exampleTree :: NTree (Tuple String String)
exampleTree =
NNode 1 true "françois.pineau"
[ annuaire 2 "Annuaire"
, corpus 3 "IMT publications"
]
exampleTree :: NTree LNode
exampleTree = NTree (LNode {id : 1, name : "", nodeType : "", open : false}) []
annuaire :: Int -> String -> NTree (Tuple String String)
annuaire n name = NNode n false name
[ NLeaf (Tuple "IMT community" "#/docView")
]
-- exampleTree :: NTree LNode
-- exampleTree =
-- NTree 1 true "françois.pineau"
-- [ --annuaire 2 "Annuaire"
-- --, corpus 3 "IMT publications"
-- ]
corpus :: Int -> String -> NTree (Tuple String String)
corpus n name = NNode n false name
[ NLeaf (Tuple "Facets" "#/corpus")
, NLeaf (Tuple "Dashboard" "#/dashboard")
, NLeaf (Tuple "Graph" "#/graphExplorer")
]
-- annuaire :: Int -> String -> NTree (Tuple String String)
-- annuaire n name = NTree n false name
-- [ NTree (Tuple "IMT community" "#/docView")
-- ]
-- corpus :: Int -> String -> NTree (Tuple String String)
-- corpus n name = NTree (LNode {id : n, name, nodeType : "", open : false})
-- [ NTree (Tuple "Facets" "#/corpus") []
-- , NTree (Tuple "Dashboard" "#/dashboard") []
-- , NTree (Tuple "Graph" "#/graphExplorer") []
-- ]
------------------------------------------------------------------------
...
...
@@ -98,14 +99,14 @@ treeview = simpleSpec performAction render
toHtml :: (Action -> Effect Unit) -> FTree -> ReactElement
toHtml d (N
Leaf (Tuple name link)
) =
toHtml d (N
Tree (LNode {id, name, nodeType, open}) []
) =
li []
[ a [ href
link
]
[ a [ href
"#"
]
( [ text (name <> " ")
] <> nodeOptionsView false
)
]
toHtml d (N
Node id open name
ary) =
toHtml d (N
Tree (LNode {id, name, nodeType, open})
ary) =
ul [ ]
[ li [] $
( [ a [onClick $ (\e-> d $ ToggleFolder id)] [i [fldr open] []]
...
...
@@ -121,7 +122,7 @@ fldr :: Boolean -> Props
fldr open = if open then className "fas fa-folder-open" else className "fas fa-folder"
newtype LNode = LNode {id :: Int, name :: String}
newtype LNode = LNode {id :: Int, name :: String
, nodeType :: String, open :: Boolean
}
-- derive instance newtypeLNode :: Newtype LNode _
...
...
@@ -130,7 +131,8 @@ instance decodeJsonLNode :: DecodeJson LNode where
obj <- decodeJson json
id_ <- obj .? "id"
name <- obj .? "name"
pure $ LNode {id : id_, name}
nodeType <- obj .? "type"
pure $ LNode {id : id_, name, nodeType, open : true}
loadDefaultNode :: Aff (Either String (Array LNode))
loadDefaultNode = do
...
...
@@ -153,4 +155,4 @@ loadDefaultNode = do
fnTransform :: LNode -> FTree
fnTransform
(LNode r) = NNode r.id false r.name
[]
fnTransform
n = NTree n
[]
src/Gargantext/Pages/Layout/States.purs
View file @
3dee4b8d
...
...
@@ -4,23 +4,21 @@ import Prelude hiding (div)
import Data.Lens (Lens', lens)
import Data.Maybe (Maybe(Just))
import Gargantext.Components.Login as LN
import Gargantext.Components.Tree as Tree
import Gargantext.Pages.Layout.Specs.AddCorpus as AC
import Gargantext.Pages.Corpus as CA
import Gargantext.Pages.Corpus.Doc.Annotation as D
import Gargantext.Pages.Corpus.Doc.Facets as TV
import Gargantext.Pages.Corpus.Doc.Facets.Documents as DV
import Gargantext.Pages.Corpus.Doc.Facets.Dashboard as Dsh
import Gargantext.Pages.Corpus.Doc.Facets.Documents as DV
import Gargantext.Pages.Corpus.Doc.Facets.Graph as GE
import Gargantext.Pages.Corpus.Doc.Facets.Terms.NgramsTable as NG
import Gargantext.Pages.Corpus.User.Users as U
import Gargantext.Pages.Home as L
import Gargantext.Pages.Layout.Specs.AddCorpus as AC
import Gargantext.Pages.Layout.Specs.Search as S
import Gargantext.Router (Routes(..))
type AppState =
{ currentRoute :: Maybe Routes
, landingState :: L.State
...
...
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