Commit 6cdcb538 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[TREE] selected current node is now underlined and bold.

parent e390844a
...@@ -22,10 +22,10 @@ import Effect.Console (log) ...@@ -22,10 +22,10 @@ import Effect.Console (log)
import Prelude (identity) import Prelude (identity)
import React (ReactClass, ReactElement) import React (ReactClass, ReactElement)
import React as React import React as React
import React.DOM (a, button, div, h5, i, input, li, span, text, ul) import React.DOM (a, button, div, h5, i, input, li, span, text, ul, b, u)
import React.DOM.Props (_id, _type, className, href, title, onClick, onInput, placeholder, style, defaultValue, _data) import React.DOM.Props (_id, _type, className, href, title, onClick, onInput, placeholder, style, defaultValue, _data)
import React.DOM.Props as DOM import React.DOM.Props as DOM
import Thermite (PerformAction, Render, Spec, createClass, defaultPerformAction, defaultRender, modifyState_, simpleSpec) import Thermite (PerformAction, Render, Spec, createClass, defaultPerformAction, defaultRender, modifyState_, simpleSpec, modifyState)
import Gargantext.Config (toUrl, End(..), NodeType(..)) import Gargantext.Config (toUrl, End(..), NodeType(..))
import Gargantext.Config.REST (get, put, post, delete, deleteWithBody) import Gargantext.Config.REST (get, put, post, delete, deleteWithBody)
...@@ -61,16 +61,19 @@ data Action = ShowPopOver ID ...@@ -61,16 +61,19 @@ data Action = ShowPopOver ID
| ToggleCreateNode ID | ToggleCreateNode ID
| ShowRenameBox ID | ShowRenameBox ID
| CancelRename ID | CancelRename ID
| CurrentNode ID
type State = { state :: FTree } type State = { state :: FTree
, currentNode :: Maybe Int
}
-- TODO remove -- TODO remove
initialState :: State initialState :: State
initialState = { state: NTree (LNode {id : 3, name : "hello", nodeType : Node, open : true, popOver : false, renameNodeValue : "", createNode : false, nodeValue : "InitialNode", showRenameBox : false}) [] } initialState = { state: NTree (LNode {id : 3, name : "hello", nodeType : Node, open : true, popOver : false, renameNodeValue : "", createNode : false, nodeValue : "InitialNode", showRenameBox : false}) [] , currentNode : Nothing}
mapFTree :: (FTree -> FTree) -> State -> State mapFTree :: (FTree -> FTree) -> State -> State
mapFTree f {state} = {state: f state} mapFTree f {state, currentNode} = {state: f state, currentNode: currentNode}
-- TODO: make it a local function -- TODO: make it a local function
performAction :: forall props. PerformAction State props Action performAction :: forall props. PerformAction State props Action
...@@ -108,6 +111,10 @@ performAction (Create nid) _ _ = ...@@ -108,6 +111,10 @@ performAction (Create nid) _ _ =
performAction (SetNodeValue v nid) _ _ = performAction (SetNodeValue v nid) _ _ =
modifyState_ $ mapFTree $ setNodeValue nid v modifyState_ $ mapFTree $ setNodeValue nid v
performAction (CurrentNode nid) _ _ =
modifyState_ $ \{state: s} -> {state: s, currentNode : Just nid}
toggleIf :: Boolean -> Boolean -> Boolean toggleIf :: Boolean -> Boolean -> Boolean
toggleIf true = not toggleIf true = not
toggleIf false = const false toggleIf false = const false
...@@ -225,15 +232,15 @@ loadedTreeview :: Spec State LoadedTreeViewProps Action ...@@ -225,15 +232,15 @@ loadedTreeview :: Spec State LoadedTreeViewProps Action
loadedTreeview = simpleSpec performAction render loadedTreeview = simpleSpec performAction render
where where
render :: Render State LoadedTreeViewProps Action render :: Render State LoadedTreeViewProps Action
render dispatch _ {state} _ = render dispatch _ {state, currentNode} _ =
[ div [className "tree"] [ div [className "tree"]
[ toHtml dispatch state [ toHtml dispatch state currentNode
] ]
] ]
treeViewClass :: ReactClass (Loader.InnerProps Int FTree (children :: React.Children)) treeViewClass :: ReactClass (Loader.InnerProps Int FTree (children :: React.Children))
treeViewClass = createClass "TreeView" loadedTreeview (\{loaded: t} -> {state: t}) treeViewClass = createClass "TreeView" loadedTreeview (\{loaded: t} -> {state: t, currentNode: Nothing})
treeLoaderClass :: Loader.LoaderClass Int FTree treeLoaderClass :: Loader.LoaderClass Int FTree
treeLoaderClass = Loader.createLoaderClass "TreeLoader" loadNode treeLoaderClass = Loader.createLoaderClass "TreeLoader" loadNode
...@@ -351,25 +358,30 @@ getCreateNodeValue :: FTree -> String ...@@ -351,25 +358,30 @@ getCreateNodeValue :: FTree -> String
getCreateNodeValue (NTree (LNode {id, name, nodeType, open, popOver, renameNodeValue, nodeValue, showRenameBox}) ary) = nodeValue getCreateNodeValue (NTree (LNode {id, name, nodeType, open, popOver, renameNodeValue, nodeValue, showRenameBox}) ary) = nodeValue
toHtml :: (Action -> Effect Unit) -> FTree -> ReactElement toHtml :: (Action -> Effect Unit) -> FTree -> Maybe Int -> ReactElement
toHtml d s@(NTree (LNode {id, name, nodeType, open, popOver, renameNodeValue, createNode,nodeValue, showRenameBox }) []) = toHtml d s@(NTree (LNode {id, name, nodeType, open, popOver, renameNodeValue, createNode,nodeValue, showRenameBox }) []) n =
ul [] ul []
[ [
li [] $ li [] $
[ a [className "glyphicon glyphicon-cog", _id "rename-leaf",onClick $ (\_-> d $ (ShowPopOver id))] [] [ a [className "glyphicon glyphicon-cog", _id "rename-leaf",onClick $ (\_-> d $ (ShowPopOver id))] []
, a [ href (toUrl Front nodeType (Just id)), style {"margin-left":"22px"}] , a [ href (toUrl Front nodeType (Just id)), style {"margin-left":"22px"}
[ text (name <> " ") ] , onClick $ (\e -> d $ CurrentNode id)
]
[ if n == (Just id) then u [] [b [] [text (name <> " ")]] else text (name <> " ") ]
, if (popOver == true) then (renameTreeView d s id) else (renameTreeViewDummy d s) , if (popOver == true) then (renameTreeView d s id) else (renameTreeViewDummy d s)
, if (createNode == true) then (createNodeView d s id) else (renameTreeViewDummy d s) , if (createNode == true) then (createNodeView d s id) else (renameTreeViewDummy d s)
] ]
] ]
--- need to add renameTreeview value to this function --- need to add renameTreeview value to this function
toHtml d s@(NTree (LNode {id, name, nodeType, open, popOver, renameNodeValue,createNode, nodeValue, showRenameBox}) ary) = toHtml d s@(NTree (LNode {id, name, nodeType, open, popOver, renameNodeValue,createNode, nodeValue, showRenameBox}) ary) n=
ul [] ul []
[ li [] $ [ li [] $
( [ a [onClick $ (\e-> d $ ToggleFolder id)] [i [fldr open] []] ( [ a [onClick $ (\e-> d $ ToggleFolder id)] [i [fldr open] []]
, a [ href (toUrl Front nodeType (Just id)), style {"margin-left":"22px"}] , a [ href (toUrl Front nodeType (Just id)), style {"margin-left":"22px"}
[ text name ] , onClick $ (\e -> d $ CurrentNode id)
]
--[ text name ]
[ if n == (Just id) then u [] [b [] [text name]] else text name ]
, a [className "glyphicon glyphicon-cog", _id "rename",onClick $ (\_-> d $ (ShowPopOver id))] , a [className "glyphicon glyphicon-cog", _id "rename",onClick $ (\_-> d $ (ShowPopOver id))]
[ [
] ]
...@@ -378,7 +390,7 @@ toHtml d s@(NTree (LNode {id, name, nodeType, open, popOver, renameNodeValue,cre ...@@ -378,7 +390,7 @@ toHtml d s@(NTree (LNode {id, name, nodeType, open, popOver, renameNodeValue,cre
] <> ] <>
if open then if open then
map (toHtml d) ary map (\s -> toHtml d s n) ary
else [] else []
) )
] ]
......
...@@ -58,7 +58,7 @@ corpusHeaderSpec = simpleSpec defaultPerformAction render ...@@ -58,7 +58,7 @@ corpusHeaderSpec = simpleSpec defaultPerformAction render
getCorpus :: Int -> Aff CorpusData getCorpus :: Int -> Aff CorpusData
getCorpus corpusId = do getCorpus corpusId = do
corpusNode <- get $ toUrl Back Corpus $ Just corpusId corpusNode <- get $ toUrl Back Corpus $ Just corpusId
defaultListIds <- get $ toUrl Back (Children NodeList 0 1 Nothing) $ Just corpusId defaultListIds <- get $ toUrl Back (Children NodeList 0 1 Nothing) $ Just corpusId
case (head defaultListIds :: Maybe (NodePoly HyperdataList)) of case (head defaultListIds :: Maybe (NodePoly HyperdataList)) of
Just (NodePoly { id: defaultListId }) -> Just (NodePoly { id: defaultListId }) ->
......
...@@ -61,9 +61,9 @@ statefulTabs = ...@@ -61,9 +61,9 @@ statefulTabs =
docs = noState ( cmapProps (\{path: corpusId} -> {corpusId : corpusId, tabType: TabCorpus TabDocs}) histoSpec docs = noState ( cmapProps (\{path: corpusId} -> {corpusId : corpusId, tabType: TabCorpus TabDocs}) histoSpec
<> <>
(cmapProps (\{path: nodeId} -> { nodeId : nodeId (cmapProps (\{path: nodeId} -> { nodeId : nodeId
, chart : div [][] -- ECharts.chart globalPublis , chart : div [][]
, tabType: TabCorpus TabDocs , tabType: TabCorpus TabDocs
, totalRecords: 4736}) $ noState DT.docViewSpec , totalRecords: 4737}) $ noState DT.docViewSpec
) )
) )
......
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