Commit 03f40a8a authored by Alexandre Delanoë's avatar Alexandre Delanoë

[ANNOTATION] connecting backend WIP (needs listId of corpus view).

parent 2e58c066
......@@ -14,6 +14,9 @@ module Gargantext.Components.NgramsTable
, initialPageParams
, initialState
, mainNgramsTableSpec
, loadNgramsTable
, ngramsTableSpec
, ngramsLoaderClass
, ngramsLoader
, ngramsLoaderClass
, ngramsTableClass
......@@ -68,7 +71,7 @@ import Partial.Unsafe (unsafePartial)
import Gargantext.Utils.KarpRabin (indicesOfAny)
import Gargantext.Types (TermList(..), TermSize, readTermList, readTermSize, termLists, termSizes)
import Gargantext.Config (toUrl, End(..), Path(..), TabType(..), OrderBy(..))
import Gargantext.Config (toUrl, End(..), Path(..), TabType(..), OrderBy(..), NodeType(..))
import Gargantext.Config.REST (get, put)
import Gargantext.Components.AutoUpdate (autoUpdateElt)
import Gargantext.Components.Table as T
......@@ -117,10 +120,13 @@ derive instance eqNgramsTable :: Eq NgramsTable
_parent = prop (SProxy :: SProxy "parent")
_root = prop (SProxy :: SProxy "root")
_ngrams = prop (SProxy :: SProxy "ngrams")
_children :: forall row. Lens' { children :: Set NgramsTerm | row } (Set NgramsTerm)
_children = prop (SProxy :: SProxy "children")
_occurrences :: forall row. Lens' { occurrences :: Int | row } Int
_occurrences = prop (SProxy :: SProxy "occurrences")
_list :: forall a row. Lens' { list :: a | row } a
_list = prop (SProxy :: SProxy "list")
......@@ -702,8 +708,8 @@ ngramsTableSpec = simpleSpec performAction render
, delete: false
}
loadPage :: PageParams -> Aff VersionedNgramsTable
loadPage { nodeId, listIds, termListFilter, termSizeFilter
loadNgramsTable :: PageParams -> Aff VersionedNgramsTable
loadNgramsTable { nodeId, listIds, termListFilter, termSizeFilter
, searchQuery, tabType, params: {offset, limit, orderBy}} =
get $ toUrl Back
(GetNgrams { tabType, offset, limit, listIds
......@@ -716,7 +722,7 @@ loadPage { nodeId, listIds, termListFilter, termSizeFilter
convOrderBy _ = DateAsc -- TODO
ngramsLoaderClass :: Loader.LoaderClass PageParams VersionedNgramsTable
ngramsLoaderClass = Loader.createLoaderClass "NgramsTableLoader" loadPage
ngramsLoaderClass = Loader.createLoaderClass "NgramsTableLoader" loadNgramsTable
ngramsLoader :: Loader.Props' PageParams VersionedNgramsTable -> ReactElement
ngramsLoader props = React.createElement ngramsLoaderClass props []
......
......@@ -107,6 +107,7 @@ endPathUrl end = pathUrl <<< endOf end
tabTypeDocs :: TabType -> UrlPath
tabTypeDocs (TabCorpus t) = "table?view=" <> show t
tabTypeDocs (TabDocument t)= "table?view=" <> show t
tabTypeDocs (TabPairing t) = "pairing?view=" <> show t
limitUrl :: Limit -> UrlPath
......@@ -120,14 +121,17 @@ orderUrl = maybe "" (\x -> "&order=" <> show x)
showTabType' :: TabType -> String
showTabType' (TabCorpus t) = show t
showTabType' (TabDocument t) = show t
showTabType' (TabPairing t) = show t
tabTypeNgramsGet :: TabType -> UrlPath
tabTypeNgramsGet (TabCorpus t) = "listGet?ngramsType=" <> show t
tabTypeNgramsGet (TabDocument t) = "listGet?ngramsType=" <> show t
tabTypeNgramsGet (TabPairing t) = "listGet?ngramsType=" <> show t -- TODO
tabTypeNgramsPut :: TabType -> UrlPath
tabTypeNgramsPut (TabCorpus t) = "list?ngramsType=" <> show t
tabTypeNgramsPut (TabDocument t) = "list?ngramsType=" <> show t
tabTypeNgramsPut (TabPairing t) = "list?ngramsType=" <> show t -- TODO
pathUrl :: Config -> Path -> Maybe Id -> UrlPath
......@@ -146,7 +150,9 @@ pathUrl c (GetNgrams
, termSizeFilter: tsf
, searchQuery: q
}) i =
pathUrl c (NodeAPI Node) i <> "/" <> tabTypeNgramsGet t
base
<> "/"
<> tabTypeNgramsGet t
<> offsetUrl o <> limitUrl l
<> foldMap (\x -> "&list=" <> show x) listIds
<> foldMap (\x -> "&listType=" <> show x) tlf
......@@ -155,6 +161,12 @@ pathUrl c (GetNgrams
MultiTerm -> "&minTermSize=2"
) tsf
<> if q == "" then "" else ("&search=" <> q)
where
base = case t of
TabCorpus _ -> pathUrl c (NodeAPI Node) i
_ -> pathUrl c (NodeAPI Url_Document) i
pathUrl c (PutNgrams t listid) i =
pathUrl c (NodeAPI Node) i <> "/" <> tabTypeNgramsPut t <> listid'
where
......@@ -198,10 +210,9 @@ data NodeType = NodeUser
| Annuaire
| NodeContact
| Corpus
-- | NodeDocument
| Url_Document
| CorpusV3
| Dashboard
| Url_Document
| Error
| Folder
| Graph
......@@ -220,7 +231,6 @@ instance showNodeType :: Show NodeType where
show CorpusV3 = "NodeCorpusV3"
show Dashboard = "NodeDashboard"
show Url_Document = "NodeDocument"
--show NodeDocument = "NodeDocument"
show Error = "NodeError"
show Folder = "NodeFolder"
show Graph = "NodeGraph"
......@@ -325,6 +335,7 @@ instance showTabSubType :: Show a => Show (TabSubType a) where
data TabType
= TabCorpus (TabSubType CTabNgramType)
| TabPairing (TabSubType PTabNgramType)
| TabDocument (TabSubType CTabNgramType)
derive instance eqTabType :: Eq TabType
......
......@@ -18,10 +18,10 @@ import Unsafe.Coerce (unsafeCoerce)
import Control.Monad.Trans.Class (lift)
import Gargantext.Prelude
import Gargantext.Config (toUrl, NodeType(..), End(..))
import Gargantext.Config (toUrl, NodeType(..), End(..), TabSubType(..), TabType(..), CTabNgramType(..))
import Gargantext.Config.REST (get)
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.NgramsTable (NgramsTable(..), NgramsElement(..))
import Gargantext.Components.NgramsTable (NgramsTable(..), NgramsElement(..), loadNgramsTable, Versioned(..))
import Gargantext.Components.Annotation.AnnotatedField as AnnotatedField
import Gargantext.Types (TermList(..))
import Gargantext.Utils.Reactix ( scuff )
......@@ -39,14 +39,14 @@ testTable = NgramsTable $ Map.fromFoldable $ nge <$> words
type State =
{ document :: Maybe (NodePoly Document)
, ngramsTable :: NgramsTable
, ngramsTable :: Maybe NgramsTable
, inputValue :: String
}
initialState :: {} -> State
initialState {} =
{ document: Nothing
, ngramsTable: testTable
, ngramsTable: (Just testTable)
, inputValue: ""
}
......@@ -281,7 +281,18 @@ instance decodeDocument :: DecodeJson Document
performAction :: PerformAction State {} Action
performAction (Load nId) _ _ = do
node <- lift $ getNode (Just nId)
let listIds = [1]
(Versioned {version:_version, data:table}) <- lift $ loadNgramsTable {nodeId : nId
, listIds : listIds
, params : { offset : 0, limit : 100, orderBy: Nothing}
, tabType : (TabDocument (TabNgramType CTabTerms))
, searchQuery : ""
, termListFilter : Nothing
, termSizeFilter : Nothing
}
void $ modifyState $ _document ?~ node
void $ modifyState $ _ngramsTable ?~ table
logs $ "Node Document " <> show nId <> " fetched."
performAction (ChangeString ps) _ _ = pure unit
performAction (SetInput ps) _ _ = void <$> modifyState $ _ { inputValue = ps }
......@@ -292,6 +303,11 @@ getNode = get <<< toUrl Back Node
_document :: Lens' State (Maybe (NodePoly Document))
_document = lens (\s -> s.document) (\s ss -> s{document = ss})
_ngramsTable :: Lens' State (Maybe NgramsTable)
_ngramsTable = lens (\s -> s.ngramsTable) (\s ss -> s{ngramsTable = ss})
------------------------------------------------------------------------
docview :: Spec State {} Action
......@@ -330,7 +346,7 @@ docview = simpleSpec performAction render
]
]
where
annotate t = scuff $ AnnotatedField.annotatedField { ngrams: state.ngramsTable, text: t }
annotate t = scuff $ AnnotatedField.annotatedField { ngrams: maybe (NgramsTable Map.empty) identity state.ngramsTable, text: t }
li' = li [className "list-group-item justify-content-between"]
text' x = text $ maybe "Nothing" identity x
badge s = span [className "badge badge-default badge-pill"] [text s]
......
......@@ -35,7 +35,7 @@ routing =
<|> Corpus <$> (route "corpus" *> int)
<|> Document <$> (route "document" *> int)
<|> Dashboard <$ route "dashboard"
<|> PGraphExplorer <$> (route "graph" *> int )
<|> PGraphExplorer <$> (route "graph" *> int)
<|> Annuaire <$> (route "annuaire" *> int)
<|> UserPage <$> (route "user" *> int)
<|> ContactPage <$> (route "contact" *> int)
......
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