Corpus.Document: cleanup

parent 3bcb795f
module Gargantext.Pages.Corpus.Document where module Gargantext.Pages.Corpus.Document where
import Data.Argonaut (class DecodeJson, decodeJson, (.:), (.:?)) import Data.Argonaut (class DecodeJson, decodeJson, (.:), (.:?))
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Lens (Lens', lens, (?~)) import Data.Lens (Lens', lens, (?~))
...@@ -26,34 +25,19 @@ import Gargantext.Components.Annotation.AnnotatedField as AnnotatedField ...@@ -26,34 +25,19 @@ import Gargantext.Components.Annotation.AnnotatedField as AnnotatedField
import Gargantext.Types (TermList(..)) import Gargantext.Types (TermList(..))
import Gargantext.Utils.Reactix ( scuff ) import Gargantext.Utils.Reactix ( scuff )
nge :: String -> Tuple String NgramsElement
nge word = Tuple word elem where
elem = NgramsElement
{ ngrams: word, list: StopTerm
, occurrences: 1, parent: Nothing
, root: Nothing, children: Set.empty }
testTable :: NgramsTable
testTable = NgramsTable $ Map.fromFoldable $ nge <$> words
where words = [ "the", "quick", "brown", "fox", "jumped", "over", "lazy", "dog" ]
type State = type State =
{ document :: Maybe (NodePoly Document) { document :: Maybe (NodePoly Document)
, ngramsTable :: Maybe NgramsTable , ngramsTable :: Maybe NgramsTable
, inputValue :: String
} }
initialState :: {} -> State initialState :: {} -> State
initialState {} = initialState {} =
{ document: Nothing { document: Nothing
, ngramsTable: (Just testTable) , ngramsTable: Nothing
, inputValue: ""
} }
data Action data Action
= Load Int Int = Load Int Int
| ChangeString String
| SetInput String
newtype Status = Status { failed :: Int newtype Status = Status { failed :: Int
, succeeded :: Int , succeeded :: Int
...@@ -289,13 +273,9 @@ performAction (Load lId nId) _ _ = do ...@@ -289,13 +273,9 @@ performAction (Load lId nId) _ _ = do
, termListFilter : Nothing , termListFilter : Nothing
, termSizeFilter : Nothing , termSizeFilter : Nothing
} }
void $ modifyState $ _document ?~ node void $ modifyState $ _document ?~ node
void $ modifyState $ _ngramsTable ?~ table void $ modifyState $ _ngramsTable ?~ table
logs $ "Node Document " <> show nId <> " fetched." logs $ "Node Document " <> show nId <> " fetched."
performAction (ChangeString ps) _ _ = pure unit
performAction (SetInput ps) _ _ = void <$> modifyState $ _ { inputValue = ps }
getNode :: Maybe Int -> Aff (NodePoly Document) getNode :: Maybe Int -> Aff (NodePoly Document)
getNode = get <<< toUrl Back Node getNode = get <<< toUrl Back Node
...@@ -306,7 +286,6 @@ _document = lens (\s -> s.document) (\s ss -> s{document = ss}) ...@@ -306,7 +286,6 @@ _document = lens (\s -> s.document) (\s ss -> s{document = ss})
_ngramsTable :: Lens' State (Maybe NgramsTable) _ngramsTable :: Lens' State (Maybe NgramsTable)
_ngramsTable = lens (\s -> s.ngramsTable) (\s ss -> s{ngramsTable = ss}) _ngramsTable = lens (\s -> s.ngramsTable) (\s ss -> s{ngramsTable = ss})
------------------------------------------------------------------------ ------------------------------------------------------------------------
docview :: Spec State {} Action docview :: Spec State {} Action
...@@ -325,12 +304,10 @@ docview = simpleSpec performAction render ...@@ -325,12 +304,10 @@ docview = simpleSpec performAction render
[ li' [ span [] [text' document.source] [ li' [ span [] [text' document.source]
, badge "source" , badge "source"
] ]
-- TODO add href to /author/ if author present in -- TODO add href to /author/ if author present in
, li' [ span [] [text' document.authors] , li' [ span [] [text' document.authors]
, badge "authors" , badge "authors"
] ]
, li' [ span [] [text' document.publication_date] , li' [ span [] [text' document.publication_date]
, badge "date" , badge "date"
] ]
...@@ -349,23 +326,5 @@ docview = simpleSpec performAction render ...@@ -349,23 +326,5 @@ docview = simpleSpec performAction render
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
findInDocument :: (Document -> Maybe String) -> State -> Maybe String
findInDocument f state =
do (NodePoly d) <- state.document
f d.hyperdata
aryPS :: Array String
aryPS = ["Map", "Main", "Stop"]
aryPS1 :: Array String
aryPS1 = ["Nothing Selected","STOPLIST", "MAINLIST", "MAPLIST"]
optps :: String -> ReactElement
optps val = option [ value val ] [text val]
unsafeEventValue :: forall event. event -> String
unsafeEventValue e = (unsafeCoerce e).target.value
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