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
62535487
Unverified
Commit
62535487
authored
Nov 21, 2018
by
Nicolas Pouillard
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[NGRAMS] display the tree of ngrams
parent
cb9cfeca
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
11 deletions
+44
-11
Documents.purs
src/Gargantext/Pages/Corpus/Tabs/Documents.purs
+4
-2
NgramsTable.purs
src/Gargantext/Pages/Corpus/Tabs/Ngrams/NgramsTable.purs
+40
-9
No files found.
src/Gargantext/Pages/Corpus/Tabs/Documents.purs
View file @
62535487
...
...
@@ -151,8 +151,10 @@ layoutDocview = simpleSpec performAction render
-- * should we locally update our data?
-- * should we reset documentIdsToDelete?
-- * if so, how to un-check the checkboxes since the inputs are uncontrolled?
-- (maybe there is no need to uncheck them if they disapear because we
-- either reload or local update our data)
-- + There is no need to uncheck them if they disapear because we
-- either reload or local update our data.
-- + Sync the checked value using
-- `checked: Set.member n state.documentIdsToDelete`
render :: Render State Props Action
render dispatch {path: nodeId, loaded: corpusInfo} _ _ =
...
...
src/Gargantext/Pages/Corpus/Tabs/Ngrams/NgramsTable.purs
View file @
62535487
...
...
@@ -6,13 +6,19 @@ import Data.Array (filter, toUnfoldable)
import Data.Either (Either(..))
import Data.FunctorWithIndex
import Data.Newtype (class Newtype, unwrap)
import Data.Lens (Lens', Prism', lens, over, prism)
import Data.Lens (Lens', Prism', lens, over, prism, (^..))
import Data.Lens.At (class At, at)
import Data.Lens.Index (class Index, ix)
import Data.Lens.Fold (folded)
import Data.Lens.Getter (to)
import Data.Lens.Iso (re)
import Data.Lens.Iso.Newtype (_Newtype)
import Data.List (List)
import Data.List as List
import Data.Map (Map)
import Data.Map as Map
import Data.Maybe (Maybe(..), maybe)
import Data.Traversable (traverse)
import Data.Set (Set)
import Data.Set as Set
import Data.Tuple (Tuple(..), uncurry)
...
...
@@ -24,6 +30,7 @@ import React (ReactElement, ReactClass, Children)
import React as React
import React.DOM hiding (style, map)
import React.DOM.Props (_id, _type, checked, className, href, name, onChange, onClick, onInput, placeholder, scope, selected, style, value)
import React.DOM.Props as DOM
import Thermite (PerformAction, Spec, StateCoTransformer, Render, _render, modifyState_, defaultPerformAction, focusState, hideState, simpleSpec, createClass)
import Unsafe.Coerce (unsafeCoerce)
...
...
@@ -55,6 +62,8 @@ newtype NgramsElement = NgramsElement
, children :: Set NgramsTerm
}
derive instance newtypeNgramsElement :: Newtype NgramsElement _
instance decodeJsonNgramsElement :: DecodeJson NgramsElement where
decodeJson json = do
obj <- decodeJson json
...
...
@@ -70,6 +79,14 @@ instance decodeJsonNgramsElement :: DecodeJson NgramsElement where
-- type NgramsTable = Array NgramsElement
newtype NgramsTable = NgramsTable (Map NgramsTerm NgramsElement)
derive instance newtypeNgramsTable :: Newtype NgramsTable _
instance indexNgramsTable :: Index NgramsTable String NgramsElement where
ix k = _Newtype <<< ix k
instance atNgramsTable :: At NgramsTable String NgramsElement where
at k = _Newtype <<< at k
instance decodeJsonNgramsTable :: DecodeJson NgramsTable where
decodeJson json = do
elements <- decodeJson json
...
...
@@ -307,10 +324,10 @@ ngramsTableSpec' = simpleSpec performAction render
rows =
case applyNgramsTablePatch ngramsTablePatch <$> initTable of
Nothing -> [] -- or an error
Just (NgramsTable table) ->
convertRow <$> Map.toUnfoldable (Map.filter isRoot table)
Just
t@
(NgramsTable table) ->
convertRow
t
<$> Map.toUnfoldable (Map.filter isRoot table)
isRoot (NgramsElement e) = e.root == Nothing
convertRow (Tuple ngrams (NgramsElement { occurrences, list })) =
convertRow
table
(Tuple ngrams (NgramsElement { occurrences, list })) =
{ row:
let
setTermList Keep = do
...
...
@@ -319,7 +336,7 @@ ngramsTableSpec' = simpleSpec performAction render
setTermList rep@(Replace {old,new}) = do
logs $ Tuple "setTermList" (Tuple old new)
dispatch $ SetTermListItem ngrams rep in
renderNgramsItem { ngrams, occurrences, termList: list, setTermList }
renderNgramsItem {
table,
ngrams, occurrences, termList: list, setTermList }
, delete: false
}
...
...
@@ -353,18 +370,32 @@ ngramsTableSpec = simpleSpec defaultPerformAction render
, component: createClass "Layout" ngramsTableSpec' initialState
} ]
renderNgramsItem :: { ngrams :: String
tree :: NgramsTable -> DOM.Props -> NgramsTerm -> ReactElement
tree table props label =
li [ style {width : "100%"} ]
[ i [className "fas fa-folder-open"] [] -- TODO icon
, span [props] [text $ " " <> label]
, forest table props (table ^.. ix label <<< _Newtype <<< to _.children <<< folded)
]
forest :: NgramsTable -> DOM.Props -> List NgramsTerm -> ReactElement
forest table props = ul [] <<< map (tree table props) <<< List.toUnfoldable
renderNgramsItem :: { table :: NgramsTable
, ngrams :: String
, occurrences :: Int
, termList :: TermList
, setTermList :: Replace TermList -> Effect Unit
} -> Array ReactElement
renderNgramsItem { ngrams, occurrences, termList, setTermList } =
renderNgramsItem {
table,
ngrams, occurrences, termList, setTermList } =
[ checkbox GraphTerm
, checkbox StopTerm
, span [termStyle termList] [text ngrams]
, span [className "tree"]
[ forest table (termStyle termList) (List.singleton ngrams) ]
, text $ show occurrences
]
where
checkbox termList' =
let chkd = termList == termList'
termList'' = if chkd then CandidateTerm else termList'
...
...
@@ -377,7 +408,7 @@ renderNgramsItem { ngrams, occurrences, termList, setTermList } =
, onChange $ const $ setTermList (replace termList termList'')
]
-- termStyle :: TermList -> {}
termStyle :: TermList -> DOM.Props
termStyle GraphTerm = style {color: "green"}
termStyle StopTerm = style {color: "red", textDecoration : "line-through"}
termStyle CandidateTerm = style {color: "black"}
...
...
Nicolas Pouillard
@np
mentioned in issue
#18 (closed)
·
Nov 29, 2018
mentioned in issue
#18 (closed)
mentioned in issue #18
Toggle commit list
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