Commit 3dee4b8d authored by Sudhir Kumar's avatar Sudhir Kumar

tree data structure modified and builds successfully

parent e7366db6
...@@ -7,7 +7,6 @@ import Affjax.ResponseFormat as ResponseFormat ...@@ -7,7 +7,6 @@ import Affjax.ResponseFormat as ResponseFormat
import Data.Argonaut (class DecodeJson, decodeJson, (.?)) import Data.Argonaut (class DecodeJson, decodeJson, (.?))
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.HTTP.Method (Method(..)) import Data.HTTP.Method (Method(..))
import Data.Tuple (Tuple(..))
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
...@@ -22,51 +21,53 @@ type Open = Boolean ...@@ -22,51 +21,53 @@ type Open = Boolean
type URL = String type URL = String
type ID = Int type ID = Int
data NTree a = NLeaf a | NNode ID Open Name (Array (NTree a)) data NTree a = NTree a (Array (NTree a))
type FTree = NTree (Tuple Name URL) type FTree = NTree LNode
data Action = ToggleFolder ID data Action = ToggleFolder ID
type State = FTree type State = FTree
initialState :: State initialState :: State
initialState = NLeaf (Tuple "" "") initialState = NTree (LNode {id : 1, name : "", nodeType : "", open : true}) []
performAction :: PerformAction State {} Action performAction :: PerformAction State {} Action
performAction (ToggleFolder i) _ _ = void $ performAction (ToggleFolder i) _ _ = void $
cotransform (\td -> toggleNode i td) cotransform (\td -> toggleNode i td)
toggleNode :: forall t10. Int -> NTree t10 -> NTree t10 toggleNode :: Int -> NTree LNode -> NTree LNode
toggleNode sid (NNode iid open name ary) = toggleNode sid (NTree (LNode {id, name, nodeType, open}) ary) =
NNode iid nopen name $ map (toggleNode sid) ary NTree (LNode {id,name, nodeType, open : nopen}) $ map (toggleNode sid) ary
where where
nopen = if sid == iid then not open else open nopen = if sid == id then not open else open
toggleNode sid a = a
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- Realistic Tree for the UI -- Realistic Tree for the UI
exampleTree :: NTree (Tuple String String) exampleTree :: NTree LNode
exampleTree = exampleTree = NTree (LNode {id : 1, name : "", nodeType : "", open : false}) []
NNode 1 true "françois.pineau"
[ annuaire 2 "Annuaire" -- exampleTree :: NTree LNode
, corpus 3 "IMT publications" -- exampleTree =
] -- NTree 1 true "françois.pineau"
-- [ --annuaire 2 "Annuaire"
-- --, corpus 3 "IMT publications"
-- ]
annuaire :: Int -> String -> NTree (Tuple String String) -- annuaire :: Int -> String -> NTree (Tuple String String)
annuaire n name = NNode n false name -- annuaire n name = NTree n false name
[ NLeaf (Tuple "IMT community" "#/docView") -- [ NTree (Tuple "IMT community" "#/docView")
] -- ]
corpus :: Int -> String -> NTree (Tuple String String) -- corpus :: Int -> String -> NTree (Tuple String String)
corpus n name = NNode n false name -- corpus n name = NTree (LNode {id : n, name, nodeType : "", open : false})
[ NLeaf (Tuple "Facets" "#/corpus") -- [ NTree (Tuple "Facets" "#/corpus") []
, NLeaf (Tuple "Dashboard" "#/dashboard") -- , NTree (Tuple "Dashboard" "#/dashboard") []
, NLeaf (Tuple "Graph" "#/graphExplorer") -- , NTree (Tuple "Graph" "#/graphExplorer") []
] -- ]
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -98,14 +99,14 @@ treeview = simpleSpec performAction render ...@@ -98,14 +99,14 @@ treeview = simpleSpec performAction render
toHtml :: (Action -> Effect Unit) -> FTree -> ReactElement toHtml :: (Action -> Effect Unit) -> FTree -> ReactElement
toHtml d (NLeaf (Tuple name link)) = toHtml d (NTree (LNode {id, name, nodeType, open}) []) =
li [] li []
[ a [ href link] [ a [ href "#"]
( [ text (name <> " ") ( [ text (name <> " ")
] <> nodeOptionsView false ] <> nodeOptionsView false
) )
] ]
toHtml d (NNode id open name ary) = toHtml d (NTree (LNode {id, name, nodeType, open}) ary) =
ul [ ] ul [ ]
[ li [] $ [ li [] $
( [ a [onClick $ (\e-> d $ ToggleFolder id)] [i [fldr open] []] ( [ a [onClick $ (\e-> d $ ToggleFolder id)] [i [fldr open] []]
...@@ -121,7 +122,7 @@ fldr :: Boolean -> Props ...@@ -121,7 +122,7 @@ fldr :: Boolean -> Props
fldr open = if open then className "fas fa-folder-open" else className "fas fa-folder" 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 _ -- derive instance newtypeLNode :: Newtype LNode _
...@@ -130,7 +131,8 @@ instance decodeJsonLNode :: DecodeJson LNode where ...@@ -130,7 +131,8 @@ instance decodeJsonLNode :: DecodeJson LNode where
obj <- decodeJson json obj <- decodeJson json
id_ <- obj .? "id" id_ <- obj .? "id"
name <- obj .? "name" 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 :: Aff (Either String (Array LNode))
loadDefaultNode = do loadDefaultNode = do
...@@ -153,4 +155,4 @@ loadDefaultNode = do ...@@ -153,4 +155,4 @@ loadDefaultNode = do
fnTransform :: LNode -> FTree fnTransform :: LNode -> FTree
fnTransform (LNode r) = NNode r.id false r.name [] fnTransform n = NTree n []
...@@ -4,22 +4,20 @@ import Prelude hiding (div) ...@@ -4,22 +4,20 @@ import Prelude hiding (div)
import Data.Lens (Lens', lens) import Data.Lens (Lens', lens)
import Data.Maybe (Maybe(Just)) import Data.Maybe (Maybe(Just))
import Gargantext.Components.Login as LN
import Gargantext.Components.Login as LN import Gargantext.Components.Tree as Tree
import Gargantext.Components.Tree as Tree import Gargantext.Pages.Corpus as CA
import Gargantext.Pages.Layout.Specs.AddCorpus as AC import Gargantext.Pages.Corpus.Doc.Annotation as D
import Gargantext.Pages.Corpus as CA import Gargantext.Pages.Corpus.Doc.Facets as TV
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.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.Graph as GE
import Gargantext.Pages.Corpus.Doc.Facets.Terms.NgramsTable as NG import Gargantext.Pages.Corpus.Doc.Facets.Terms.NgramsTable as NG
import Gargantext.Pages.Corpus.User.Users as U import Gargantext.Pages.Corpus.User.Users as U
import Gargantext.Pages.Home as L import Gargantext.Pages.Home as L
import Gargantext.Pages.Layout.Specs.Search as S import Gargantext.Pages.Layout.Specs.AddCorpus as AC
import Gargantext.Router (Routes(..)) import Gargantext.Pages.Layout.Specs.Search as S
import Gargantext.Router (Routes(..))
type AppState = type AppState =
{ currentRoute :: Maybe Routes { currentRoute :: Maybe Routes
......
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