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
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
Przemyslaw Kaminski
purescript-gargantext
Commits
5e813179
Commit
5e813179
authored
Apr 12, 2019
by
James Laver
Committed by
Alexandre Delanoë
Apr 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Push for anoe to test
parent
88b73a01
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
18 deletions
+51
-18
AnnotatedField.purs
src/Gargantext/Components/Annotated/AnnotatedField.purs
+43
-12
NgramsTable.purs
src/Gargantext/Components/NgramsTable.purs
+4
-0
Document.purs
src/Gargantext/Pages/Corpus/Document.purs
+4
-6
No files found.
src/Gargantext/Components/Annotated/AnnotatedField.purs
View file @
5e813179
...
@@ -14,24 +14,28 @@ module Gargantext.Components.Annotated.AnnotatedField where
...
@@ -14,24 +14,28 @@ module Gargantext.Components.Annotated.AnnotatedField where
import Prelude hiding (div)
import Prelude hiding (div)
import Data.Unit (Unit, unit)
import Data.Unit (Unit, unit)
import Data.Array (fromFoldable)
import Data.Array (fromFoldable)
import Data.Maybe (Maybe(..), isJust)
import Data.Map as Map
import Data.Maybe (Maybe(..), maybe)
import Data.Lens (Lens', Prism', over, view, lens)
import Data.Lens (Lens', Prism', over, view, lens)
import Data.List as List
import Data.List as List
import Data.List (List(..), mapWithIndex, toUnfoldable, sortBy)
import Data.List (List(..), mapWithIndex, toUnfoldable, sortBy)
import Data.Ordering (Ordering(..))
import Data.Ordering (Ordering(..))
import Data.Tuple (Tuple(..))
import Data.Tuple (Tuple(..))
import Effect (Effect)
import Effect (Effect)
import Effect.Class.Console (log)
import Effect.Unsafe (unsafePerformEffect)
import React (Children, ReactElement, ReactClass, createElement)
import React (Children, ReactElement, ReactClass, createElement)
import React.DOM (a, div, p, span, nav, text)
import React.DOM (a, div, p, span, nav, text)
import React.DOM.Props (className, onContextMenu)
import React.DOM.Props (className, onContextMenu)
import Thermite ( PerformAction, Render, Spec
import Thermite ( PerformAction, Render, Spec
, defaultPerformAction, createClass
, defaultPerformAction, createClass
, createReactSpec
, _render, modifyState, focus, focusState
, _render, modifyState,
writeState,
focus, focusState
, simpleSpec, withState)
, simpleSpec, withState)
import Gargantext.Types (TermList(..))
import Gargantext.Types (TermList(..))
import Gargantext.Components.NgramsTable (NgramsTable(..), highlightNgrams, termStyle)
import Gargantext.Components.NgramsTable (NgramsTable(..), highlightNgrams, termStyle)
import Gargantext.Utils.React (WithChildren)
import Gargantext.Utils.React (WithChildren)
import Gargantext.Utils.Selection (getSelection, toString)
import Gargantext.Utils.Selection (getSelection, toString)
import React as React
import React.SyntheticEvent (SyntheticMouseEvent, pageX, pageY)
import React.SyntheticEvent (SyntheticMouseEvent, pageX, pageY)
newtype PageOffset = PageOffset { x :: Number, y :: Number }
newtype PageOffset = PageOffset { x :: Number, y :: Number }
...
@@ -44,9 +48,12 @@ type Props' = ( ngrams :: NgramsTable, text :: Maybe String )
...
@@ -44,9 +48,12 @@ type Props' = ( ngrams :: NgramsTable, text :: Maybe String )
type Props = { | Props' }
type Props = { | Props' }
data Action
data Action
= OnContextMenu PageOffset String
= ForceRefresh
| OnContextMenu PageOffset String
| AddTerm String TermList
| AddTerm String TermList
defaultProps :: Props
defaultProps = { ngrams: NgramsTable Map.empty, text: Nothing }
defaultState :: State
defaultState :: State
defaultState = { runs: Nil, contextMenu: { visible: false } } -- contextMenu: ContextMenu.defaultState }
defaultState = { runs: Nil, contextMenu: { visible: false } } -- contextMenu: ContextMenu.defaultState }
...
@@ -54,20 +61,41 @@ annotatedField :: Props -> ReactElement
...
@@ -54,20 +61,41 @@ annotatedField :: Props -> ReactElement
annotatedField p = createElement annotatedFieldClass p []
annotatedField p = createElement annotatedFieldClass p []
annotatedFieldClass :: ReactClass (WithChildren Props')
annotatedFieldClass :: ReactClass (WithChildren Props')
annotatedFieldClass = createClass "AnnotatedField" spec compile
annotatedFieldClass =
React.component "AnnotatedField"
(\this -> do
-- log $ "AnnotatedField: constructing"
s <- spec this
pure { state : s.state
, render: s.render
, componentDidUpdate: \old _s _snap -> do
new <- React.getProps this
when (old.ngrams /= new.ngrams || old.text /= new.text) do
-- log "AnnotatedField: forcing refresh"
dispatcher this ForceRefresh
})
where
where
spec :: Spec State Props Action
performAction :: PerformAction State Props Action
spec = simpleSpec performAction render
performAction ForceRefresh = forceRefresh
performAction _ = \_ _ -> pure unit
-- performAction (ShowContextMenu i) = showContextMenu i
-- performAction (ShowContextMenu i) = showContextMenu i
-- performAction (AddTerm t l) = addTerm t l
-- performAction (AddTerm t l) = addTerm t l
performAction :: PerformAction State Props Action
-- performAction = defaultPerformAction
performAction = defaultPerformAction
render :: Render State Props Action
render :: Render State Props Action
render d _p s _c = [ p [className "annotated-field"] $ children d s.runs ]
render d _p s _c = [ p [className "annotated-field"] $ children d s.runs ]
children d = fromFoldable <<< map (renderRun $ contextMenuHandler d)
children d = fromFoldable <<< map (renderRun $ contextMenuHandler d)
renderRun menu (Tuple txt lst)
renderRun menu (Tuple txt lst)
| Just list <- lst = span [termStyle list, onContextMenu menu] [text txt]
| Just list <- lst = span [termStyle list, onContextMenu menu] [text txt]
| otherwise = span [] [text txt]
| otherwise = span [] [text txt]
{spec, dispatcher} = createReactSpec (simpleSpec performAction render) compile
-- performAction handlers
forceRefresh props state =
do wrote <- writeState (compile props)
log $ msg wrote
pure unit
where msg = maybe "AnnotatedField: failed to write new state" (const "AnnotatedField: wrote new state")
-- showContextMenu :: PerformAction State Props String
-- showContextMenu :: PerformAction State Props String
-- showContextMenu p s = pure unit
-- showContextMenu p s = pure unit
...
@@ -76,13 +104,16 @@ annotatedFieldClass = createClass "AnnotatedField" spec compile
...
@@ -76,13 +104,16 @@ annotatedFieldClass = createClass "AnnotatedField" spec compile
-- addTerm t l p s = pure unit
-- addTerm t l p s = pure unit
compile :: Props -> State
compile :: Props -> State
compile {text, ngrams} = { runs: runs text, contextMenu: { visible: false } }
compile props =
where runs (Just txt) = highlight ngrams txt
unsafePerformEffect $
do let ret = { runs: runs props.text, contextMenu: { visible: false } }
log "Compiling..."
pure ret
where runs (Just txt) = highlight props.ngrams txt
runs _ = Nil
runs _ = Nil
-- highlightNgrams :: NgramsTable -> String -> Array (Tuple String (Maybe TermList))
-- highlightNgrams :: NgramsTable -> String -> Array (Tuple String (Maybe TermList))
-- TODO HOOK IN string search
highlight :: NgramsTable -> String -> List Run
highlight :: NgramsTable -> String -> List Run
highlight n t = List.fromFoldable $ highlightNgrams n t
highlight n t = List.fromFoldable $ highlightNgrams n t
...
...
src/Gargantext/Components/NgramsTable.purs
View file @
5e813179
...
@@ -110,6 +110,10 @@ newtype NgramsElement = NgramsElement
...
@@ -110,6 +110,10 @@ newtype NgramsElement = NgramsElement
, children :: Set NgramsTerm
, children :: Set NgramsTerm
}
}
derive instance eqNgramsElement :: Eq NgramsElement
derive instance eqNgramsTable :: Eq NgramsTable
_parent = prop (SProxy :: SProxy "parent")
_parent = prop (SProxy :: SProxy "parent")
_root = prop (SProxy :: SProxy "root")
_root = prop (SProxy :: SProxy "root")
_ngrams = prop (SProxy :: SProxy "ngrams")
_ngrams = prop (SProxy :: SProxy "ngrams")
...
...
src/Gargantext/Pages/Corpus/Document.purs
View file @
5e813179
...
@@ -29,7 +29,7 @@ import Gargantext.Types (TermList(..))
...
@@ -29,7 +29,7 @@ import Gargantext.Types (TermList(..))
nge :: String -> Tuple String NgramsElement
nge :: String -> Tuple String NgramsElement
nge word = Tuple word elem where
nge word = Tuple word elem where
elem = NgramsElement
elem = NgramsElement
{ ngrams: word, list:
Candidate
Term
{ ngrams: word, list:
Stop
Term
, occurrences: 1, parent: Nothing
, occurrences: 1, parent: Nothing
, root: Nothing, children: Set.empty }
, root: Nothing, children: Set.empty }
...
@@ -314,7 +314,7 @@ docview = simpleSpec performAction render
...
@@ -314,7 +314,7 @@ docview = simpleSpec performAction render
div [className "row"]
div [className "row"]
[
[
div [className "col-md-8"]
div [className "col-md-8"]
[ h4 [] [
text'
document.title]
[ h4 [] [
annotate
document.title]
, ul [className "list-group"]
, ul [className "list-group"]
[ li' [ span [] [text' document.source]
[ li' [ span [] [text' document.source]
, badge "source"
, badge "source"
...
@@ -330,7 +330,7 @@ docview = simpleSpec performAction render
...
@@ -330,7 +330,7 @@ docview = simpleSpec performAction render
]
]
]
]
, badge "abstract"
, badge "abstract"
, abstract
, a
nnotate document.a
bstract
, div [className "jumbotron"]
, div [className "jumbotron"]
[ p [] [text "Empty Full Text"]
[ p [] [text "Empty Full Text"]
]
]
...
@@ -339,12 +339,10 @@ docview = simpleSpec performAction render
...
@@ -339,12 +339,10 @@ docview = simpleSpec performAction render
]
]
]
]
where
where
abs = findInDocument (\(Document d) -> d.abstract) state
annotate t = AnnotatedField.annotatedField { ngrams: state.ngramsTable, text: t }
abstract = AnnotatedField.annotatedField { ngrams: state.ngramsTable, text: abs }
li' = li [className "list-group-item justify-content-between"]
li' = li [className "list-group-item justify-content-between"]
text' x = text $ maybe "Nothing" identity x
text' x = text $ maybe "Nothing" identity x
badge s = span [className "badge badge-default badge-pill"] [text s]
badge s = span [className "badge badge-default badge-pill"] [text s]
NodePoly {hyperdata : Document document} =
NodePoly {hyperdata : Document document} =
maybe defaultNodeDocument identity state.document
maybe defaultNodeDocument identity state.document
...
...
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