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
0
Merge Requests
0
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
Grégoire Locqueville
purescript-gargantext
Commits
0770e5ba
Commit
0770e5ba
authored
Mar 19, 2020
by
Justin Woo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
load lists endpoint from ngramstable
parent
81889fb1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
98 additions
and
47 deletions
+98
-47
NgramsTable.purs
src/Gargantext/Components/NgramsTable.purs
+22
-28
Core.purs
src/Gargantext/Components/NgramsTable/Core.purs
+63
-17
Ends.purs
src/Gargantext/Ends.purs
+1
-0
Routes.purs
src/Gargantext/Routes.purs
+1
-0
Types.purs
src/Gargantext/Types.purs
+11
-2
No files found.
src/Gargantext/Components/NgramsTable.purs
View file @
0770e5ba
...
@@ -3,17 +3,13 @@ module Gargantext.Components.NgramsTable
...
@@ -3,17 +3,13 @@ module Gargantext.Components.NgramsTable
, mainNgramsTable
, mainNgramsTable
) where
) where
import Prelude
( class Show, Unit, bind, const, discard, identity, map, mempty, not
, pure, show, unit, (#), ($), (&&), (+), (/=), (<$>), (<<<), (<>), (=<<)
, (==), (||), otherwise, when )
import Data.Array as A
import Data.Array as A
import Data.FunctorWithIndex (mapWithIndex)
import Data.FunctorWithIndex (mapWithIndex)
import Data.Lens (Lens', to, view, (%~), (.~), (^.), (^..), (^?))
import Data.Lens (Lens', to, view, (%~), (.~), (^.), (^..), (^?))
import Data.Lens.Common (_Just)
import Data.Lens.At (at)
import Data.Lens.At (at)
import Data.Lens.
Index (ix
)
import Data.Lens.
Common (_Just
)
import Data.Lens.Fold (folded)
import Data.Lens.Fold (folded)
import Data.Lens.Index (ix)
import Data.Lens.Record (prop)
import Data.Lens.Record (prop)
import Data.List as List
import Data.List as List
import Data.Map (Map)
import Data.Map (Map)
...
@@ -26,34 +22,26 @@ import Data.Set as Set
...
@@ -26,34 +22,26 @@ import Data.Set as Set
import Data.Symbol (SProxy(..))
import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..), snd)
import Data.Tuple (Tuple(..), snd)
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested ((/\))
import Debug.Trace (spy)
import Effect (Effect)
import Effect (Effect)
import Reactix as R
import Reactix.DOM.HTML as H
import React (ReactClass, ReactElement, Children)
import React.DOM (a, i, input, li, span, text, ul)
import React.DOM.Props ( _type, checked, className, onChange, onClick, style
, readOnly)
import React.DOM.Props as DOM
import Thermite as Thermite
import Thermite (modifyState_)
import Gargantext.Types
( CTabNgramType, OrderBy(..), TabType, TermList(..), readTermList
, readTermSize, termLists, termSizes)
import Gargantext.Components.AutoUpdate (autoUpdateElt)
import Gargantext.Components.AutoUpdate (autoUpdateElt)
import Gargantext.Components.NgramsTable.Core
( CoreState, NgramsElement(..), NgramsPatch(..), NgramsTablePatch, _PatchMap
, NgramsTable, NgramsTerm, PageParams, Replace, Versioned(..)
, VersionedNgramsTable, _NgramsElement, _NgramsTable, _children
, _list, _ngrams, _occurrences, _root, addNewNgram, applyNgramsPatches
, applyPatchSet, commitPatch, syncPatches, convOrderBy, initialPageParams, loadNgramsTable
, patchSetFromMap, replace, singletonNgramsTablePatch
, normNgram, ngramsTermText, fromNgramsPatches, PatchMap(..), rootsOf )
import Gargantext.Components.Loader (loader)
import Gargantext.Components.Loader (loader)
import Gargantext.Components.LoadingSpinner (loadingSpinner)
import Gargantext.Components.NgramsTable.Core (CoreState, NgramsElement(..), NgramsPatch(..), NgramsTable, NgramsTablePatch, NgramsTerm, PageParams, PatchMap(..), Replace, Versioned(..), VersionedNgramsTable, _NgramsElement, _NgramsTable, _PatchMap, _children, _list, _ngrams, _occurrences, _root, addNewNgram, applyNgramsPatches, applyPatchSet, commitPatch, convOrderBy, fromNgramsPatches, initialPageParams, loadNgramsTable, loadNgramsTableAll, ngramsTermText, normNgram, patchSetFromMap, replace, rootsOf, singletonNgramsTablePatch, syncPatches)
import Gargantext.Components.Table as T
import Gargantext.Components.Table as T
import Gargantext.Sessions (Session)
import Gargantext.Sessions (Session)
import Gargantext.Types (CTabNgramType, Mode(..), OrderBy(..), TabType, TermList(..), readTermList, readTermSize, termLists, termSizes)
import Gargantext.Utils (queryMatchesLabel)
import Gargantext.Utils (queryMatchesLabel)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix as R2
import Prelude (class Show, Unit, bind, const, discard, identity, map, mempty, not, pure, show, unit, (#), ($), (&&), (+), (/=), (<$>), (<<<), (<>), (=<<), (==), (||), otherwise, when)
import React (ReactClass, ReactElement, Children)
import React.DOM (a, i, input, li, span, text, ul)
import React.DOM.Props (_type, checked, className, onChange, onClick, style, readOnly)
import React.DOM.Props as DOM
import Reactix as R
import Reactix.DOM.HTML as H
import Thermite (modifyState_)
import Thermite as Thermite
import Unsafe.Coerce (unsafeCoerce)
import Unsafe.Coerce (unsafeCoerce)
type State =
type State =
...
@@ -427,7 +415,13 @@ mainNgramsTableCpt = R.hooksComponent "MainNgramsTable" cpt
...
@@ -427,7 +415,13 @@ mainNgramsTableCpt = R.hooksComponent "MainNgramsTable" cpt
cpt {nodeId, defaultListId, tabType, session, tabNgramType} _ = do
cpt {nodeId, defaultListId, tabType, session, tabNgramType} _ = do
path /\ setPath <- R.useState' $ initialPageParams session nodeId [defaultListId] tabType
path /\ setPath <- R.useState' $ initialPageParams session nodeId [defaultListId] tabType
let paint versioned = loadedNgramsTable' {tabNgramType, path: path /\ setPath, versioned}
let paint versioned = loadedNgramsTable' {tabNgramType, path: path /\ setPath, versioned}
pure $ loader path loadNgramsTable paint
-- TODO: get rid of ngramsTble loading
-- pure $ loader path loadNgramsTable paint
pure $ loader path loadNgramsTableAll \loaded -> do
case Map.lookup Sources loaded of
Just versioned -> paint versioned
Nothing -> loadingSpinner {}
type NgramsDepth = {ngrams :: NgramsTerm, depth :: Int}
type NgramsDepth = {ngrams :: NgramsTerm, depth :: Int}
type NgramsClick = NgramsDepth -> Maybe (Effect Unit)
type NgramsClick = NgramsDepth -> Maybe (Effect Unit)
...
...
src/Gargantext/Components/NgramsTable/Core.purs
View file @
0770e5ba
...
@@ -21,6 +21,7 @@ module Gargantext.Components.NgramsTable.Core
...
@@ -21,6 +21,7 @@ module Gargantext.Components.NgramsTable.Core
, highlightNgrams
, highlightNgrams
, initialPageParams
, initialPageParams
, loadNgramsTable
, loadNgramsTable
, loadNgramsTableAll
, convOrderBy
, convOrderBy
, Replace(..) -- Ideally we should keep the constructors hidden
, Replace(..) -- Ideally we should keep the constructors hidden
, replace
, replace
...
@@ -50,50 +51,49 @@ module Gargantext.Components.NgramsTable.Core
...
@@ -50,50 +51,49 @@ module Gargantext.Components.NgramsTable.Core
where
where
import Prelude
import Prelude
import Control.Monad.State (class MonadState, execState)
import Control.Monad.Cont.Trans (lift)
import Control.Monad.Cont.Trans (lift)
import Control.Monad.State (class MonadState, execState)
import Data.Argonaut (class DecodeJson, class EncodeJson, Json, decodeJson, encodeJson, jsonEmptyObject, (.:), (.:!), (:=), (~>))
import Data.Array (head)
import Data.Array (head)
import Data.Array as A
import Data.Array as A
import Data.Argonaut ( class DecodeJson, decodeJson, class EncodeJson, encodeJson
import Data.Array as Array
, jsonEmptyObject, (:=), (~>), (.:), (.:!) )
import Data.Bifunctor (lmap)
import Data.Bifunctor (lmap)
import Data.Either (Either(..))
import Data.Either (Either(..))
import Data.Foldable (class Foldable, foldMap, foldl, foldr)
import Data.Foldable (class Foldable, foldMap, foldl, foldr)
import Data.FoldableWithIndex (class FoldableWithIndex, foldMapWithIndex, foldlWithIndex, foldrWithIndex)
import Data.FoldableWithIndex (class FoldableWithIndex, foldMapWithIndex, foldlWithIndex, foldrWithIndex)
import Data.FunctorWithIndex (class FunctorWithIndex, mapWithIndex)
import Data.FunctorWithIndex (class FunctorWithIndex, mapWithIndex)
import Data.Newtype (class Newtype)
import Data.Lens (Iso', Lens', use, view, (%=), (.~), (?=), (^?))
import Data.Lens (Iso', Lens', use, view, (%=), (.~), (?=), (^?))
import Data.Lens.Common (_Just)
import Data.Lens.At (class At, at)
import Data.Lens.At (class At, at)
import Data.Lens.
Index (class Index, ix
)
import Data.Lens.
Common (_Just
)
import Data.Lens.Fold (folded, traverseOf_)
import Data.Lens.Fold (folded, traverseOf_)
import Data.Lens.
Record (prop
)
import Data.Lens.
Index (class Index, ix
)
import Data.Lens.Iso.Newtype (_Newtype)
import Data.Lens.Iso.Newtype (_Newtype)
import Data.Lens.Record (prop)
import Data.List ((:), List(Nil))
import Data.List ((:), List(Nil))
import Data.Map (Map)
import Data.Map (Map)
import Data.Map as Map
import Data.Map as Map
import Data.Maybe (Maybe(..), maybe, isNothing)
import Data.Maybe (Maybe(..), fromMaybe, isNothing, maybe)
import Data.Traversable (class Traversable, traverse, traverse_, sequence)
import Data.Newtype (class Newtype)
import Data.TraversableWithIndex (class TraversableWithIndex, traverseWithIndex)
import Data.Set (Set)
import Data.Set (Set)
import Data.Set as Set
import Data.Set as Set
import Data.String as S
import Data.String as S
import Data.String.Regex (Regex, regex, replace) as R
import Data.String.Regex (Regex, regex, replace) as R
import Data.String.Regex.Flags (global, multiline) as R
import Data.String.Regex.Flags (global, multiline) as R
import Data.Symbol (SProxy(..))
import Data.Symbol (SProxy(..))
import Data.Traversable (class Traversable, traverse, traverse_, sequence)
import Data.TraversableWithIndex (class TraversableWithIndex, traverseWithIndex)
import Data.Tuple (Tuple(..))
import Data.Tuple (Tuple(..))
-- import Debug.Trace
import Effect.Aff (Aff, error, throwError)
import Effect.Aff (Aff)
import Foreign.Object as FO
import Foreign.Object as FO
import Thermite (StateCoTransformer, modifyState_)
import Partial (crashWith)
import Partial.Unsafe (unsafePartial)
import Gargantext.Components.Table as T
import Gargantext.Components.Table as T
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, get, put, post)
import Gargantext.Sessions (Session, get, put, post)
import Gargantext.Types (
OrderBy(..), CTabNgramType(..), TabType, TermList(..), TermSize, ScoreType(..)
)
import Gargantext.Types (
CTabNgramType(..), Mode, OrderBy(..), ScoreType(..), TabType, TermList(..), TermSize, decodeMode
)
import Gargantext.Utils.KarpRabin (indicesOfAny)
import Gargantext.Utils.KarpRabin (indicesOfAny)
import Partial (crashWith)
import Partial.Unsafe (unsafePartial)
import Thermite (StateCoTransformer, modifyState_)
type CoreParams s =
type CoreParams s =
{ nodeId :: Int
{ nodeId :: Int
...
@@ -667,6 +667,52 @@ loadNgramsTable
...
@@ -667,6 +667,52 @@ loadNgramsTable
, termListFilter, termSizeFilter
, termListFilter, termSizeFilter
, searchQuery, scoreType } (Just nodeId)
, searchQuery, scoreType } (Just nodeId)
decodeLists :: FO.Object (Versioned Json) -> Either String NgramsList
decodeLists obj = do
tuples :: Array (Tuple Mode VersionedNgramsTable) <- traverse decodeModeMember $ FO.toUnfoldable obj
pure $ Map.fromFoldable tuples
where
decodeModeMember :: Tuple String (Versioned Json) -> Either String (Tuple Mode VersionedNgramsTable)
decodeModeMember (Tuple key versioned) = do
mode <- decodeMode key
versionedNgramsTable <- decodeVersionedNgramsTable versioned
pure $ Tuple mode versionedNgramsTable
decodeVersionedNgramsTable :: Versioned Json -> Either String VersionedNgramsTable
decodeVersionedNgramsTable (Versioned r) = do
dataObj :: FO.Object { size :: Int, list :: TermList, children :: Set NgramsTerm } <- decodeJson r."data"
let
(tuples :: Array _) =
FO.toUnfoldable dataObj <#> \(Tuple key values) ->
let ngrams = NormNgramsTerm key
in Tuple ngrams $ mkNgramsElement ngrams values
pure $ Versioned r { "data" = NgramsTable $ Map.fromFoldable tuples }
mkNgramsElement :: NgramsTerm -> { size :: Int, list :: TermList, children :: Set NgramsTerm } -> NgramsElement
mkNgramsElement ngrams r = NgramsElement
{ ngrams
, list: r.list
, children: r.children
, parent: Nothing
, root: Nothing
, occurrences: 1 -- TODO: to be fixed by using different route?
}
type NgramsList = (Map Mode VersionedNgramsTable)
loadNgramsTableAll :: PageParams -> Aff NgramsList
loadNgramsTableAll
{ nodeId, listIds, termListFilter, termSizeFilter, session, scoreType
, searchQuery, tabType, params: {offset, limit, orderBy}}
= do
obj <- get session query
case decodeLists obj of
Right x -> pure x
Left e -> throwError $ error $ "Failed to load ngrams list: " <> e
where query = ListsRoute listId
listId = fromMaybe 0 $ Array.head listIds -- listIds should be singleton list in main lists view
convOrderBy :: T.OrderByDirection T.ColumnName -> OrderBy
convOrderBy :: T.OrderByDirection T.ColumnName -> OrderBy
convOrderBy (T.ASC (T.ColumnName "Score")) = ScoreAsc
convOrderBy (T.ASC (T.ColumnName "Score")) = ScoreAsc
convOrderBy (T.DESC (T.ColumnName "Score")) = ScoreDesc
convOrderBy (T.DESC (T.ColumnName "Score")) = ScoreDesc
...
...
src/Gargantext/Ends.purs
View file @
0770e5ba
...
@@ -138,6 +138,7 @@ sessionPath (R.GetNgrams opts i) =
...
@@ -138,6 +138,7 @@ sessionPath (R.GetNgrams opts i) =
search s = "&search=" <> s
search s = "&search=" <> s
sessionPath (R.ListDocument lId dId) =
sessionPath (R.ListDocument lId dId) =
sessionPath $ R.NodeAPI NodeList lId ("document/" <> (show $ maybe 0 identity dId))
sessionPath $ R.NodeAPI NodeList lId ("document/" <> (show $ maybe 0 identity dId))
sessionPath (R.ListsRoute lId) = "lists/" <> show lId
sessionPath (R.PutNgrams t listId termList i) =
sessionPath (R.PutNgrams t listId termList i) =
sessionPath $ R.NodeAPI Node i
sessionPath $ R.NodeAPI Node i
$ "ngrams?ngramsType="
$ "ngrams?ngramsType="
...
...
src/Gargantext/Routes.purs
View file @
0770e5ba
...
@@ -35,6 +35,7 @@ data SessionRoute
...
@@ -35,6 +35,7 @@ data SessionRoute
| PutNgrams TabType (Maybe ListId) (Maybe TermList) (Maybe Id)
| PutNgrams TabType (Maybe ListId) (Maybe TermList) (Maybe Id)
-- ^ This name is not good. In particular this URL is used both in PUT and POST.
-- ^ This name is not good. In particular this URL is used both in PUT and POST.
| NodeAPI NodeType (Maybe Id) String
| NodeAPI NodeType (Maybe Id) String
| ListsRoute ListId
| ListDocument (Maybe ListId) (Maybe Id)
| ListDocument (Maybe ListId) (Maybe Id)
| Search SearchOpts (Maybe Id)
| Search SearchOpts (Maybe Id)
| CorpusMetrics CorpusMetricOpts (Maybe Id)
| CorpusMetrics CorpusMetricOpts (Maybe Id)
...
...
src/Gargantext/Types.purs
View file @
0770e5ba
module Gargantext.Types where
module Gargantext.Types where
import Prelude
import Prelude
import Data.Argonaut ( class DecodeJson, decodeJson, class EncodeJson, encodeJson, (.:), (:=), (~>), jsonEmptyObject)
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson, jsonEmptyObject, (.:), (:=), (~>))
import Data.Array as A
import Data.Array as A
import Data.Either (Either(..))
import Data.Either (Either(..))
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep (class Generic)
...
@@ -10,7 +11,6 @@ import Data.Generic.Rep.Ord (genericCompare)
...
@@ -10,7 +11,6 @@ import Data.Generic.Rep.Ord (genericCompare)
import Data.Generic.Rep.Show (genericShow)
import Data.Generic.Rep.Show (genericShow)
import Data.Int (toNumber)
import Data.Int (toNumber)
import Data.Maybe (Maybe(..), maybe)
import Data.Maybe (Maybe(..), maybe)
import Data.Tuple (Tuple)
import Effect.Aff (Aff)
import Effect.Aff (Aff)
import Prim.Row (class Union)
import Prim.Row (class Union)
import URI.Query (Query)
import URI.Query (Query)
...
@@ -426,6 +426,15 @@ data Mode = Authors | Sources | Institutes | Terms
...
@@ -426,6 +426,15 @@ data Mode = Authors | Sources | Institutes | Terms
derive instance genericMode :: Generic Mode _
derive instance genericMode :: Generic Mode _
decodeMode :: String -> Either String Mode
decodeMode tag =
case tag of
"Authors" -> Right Authors
"Institutes" -> Right Institutes
"Sources" -> Right Sources
"NgramsTerms" -> Right Terms
_ -> Left $ "Error decoding mode: unknown tag '" <> tag <> "'"
instance showMode :: Show Mode where
instance showMode :: Show Mode where
show = genericShow
show = genericShow
...
...
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