[NGRAM] add basic support for offset & limit

parent 1ce81014
...@@ -102,6 +102,12 @@ tabTypeDocs :: TabType -> UrlPath ...@@ -102,6 +102,12 @@ tabTypeDocs :: TabType -> UrlPath
tabTypeDocs (TabCorpus t) = "table?view=" <> show t tabTypeDocs (TabCorpus t) = "table?view=" <> show t
tabTypeDocs (TabPairing t) = "pairing?view=" <> show t tabTypeDocs (TabPairing t) = "pairing?view=" <> show t
limitUrl :: Limit -> UrlPath
limitUrl l = "&limit=" <> show l
offsetUrl :: Offset -> UrlPath
offsetUrl o = "&offset=" <> show o
tabTypeNgrams :: TabType -> UrlPath tabTypeNgrams :: TabType -> UrlPath
tabTypeNgrams (TabCorpus t) = "listGet?ngramsType=" <> show t tabTypeNgrams (TabCorpus t) = "listGet?ngramsType=" <> show t
tabTypeNgrams (TabPairing t) = "listGet?ngramsType=" <> show t -- TODO tabTypeNgrams (TabPairing t) = "listGet?ngramsType=" <> show t -- TODO
...@@ -109,18 +115,17 @@ tabTypeNgrams (TabPairing t) = "listGet?ngramsType=" <> show t -- TODO ...@@ -109,18 +115,17 @@ tabTypeNgrams (TabPairing t) = "listGet?ngramsType=" <> show t -- TODO
pathUrl :: Config -> Path -> Maybe Id -> UrlPath pathUrl :: Config -> Path -> Maybe Id -> UrlPath
pathUrl c (Tab t o l s) i = pathUrl c (Tab t o l s) i =
pathUrl c (NodeAPI Node) i <> pathUrl c (NodeAPI Node) i <>
"/" <> tabTypeDocs t <> "&offset=" <> show o "/" <> tabTypeDocs t <> offsetUrl o <> limitUrl l <> os
<> "&limit=" <> show l <> os
where where
os = maybe "" (\x -> "&order=" <> show x) s os = maybe "" (\x -> "&order=" <> show x) s
pathUrl c (Children n o l s) i = pathUrl c (Children n o l s) i =
pathUrl c (NodeAPI Node) i <> pathUrl c (NodeAPI Node) i <>
"/" <> "children?type=" <> show n <> "&offset=" <> show o "/" <> "children?type=" <> show n <> offsetUrl o <> limitUrl l <> os
<> "&limit=" <> show l <> os
where where
os = maybe "" (\x -> "&order=" <> show x) s os = maybe "" (\x -> "&order=" <> show x) s
pathUrl c (Ngrams t listid) i = pathUrl c (Ngrams t o l listid) i =
pathUrl c (NodeAPI Node) i <> "/" <> tabTypeNgrams t <> listid' pathUrl c (NodeAPI Node) i <> "/" <> tabTypeNgrams t
<> offsetUrl o <> limitUrl l <> listid'
where where
listid' = maybe "" (\x -> "&list=" <> show x) listid listid' = maybe "" (\x -> "&list=" <> show x) listid
pathUrl c Auth Nothing = c.prePath <> "auth" pathUrl c Auth Nothing = c.prePath <> "auth"
...@@ -183,7 +188,7 @@ data Path ...@@ -183,7 +188,7 @@ data Path
= Auth = Auth
| Tab TabType Offset Limit (Maybe OrderBy) | Tab TabType Offset Limit (Maybe OrderBy)
| Children NodeType Offset Limit (Maybe OrderBy) | Children NodeType Offset Limit (Maybe OrderBy)
| Ngrams TabType (Maybe TermList) | Ngrams TabType Offset Limit (Maybe TermList)
| NodeAPI NodeType | NodeAPI NodeType
data End = Back | Front data End = Back | Front
...@@ -241,9 +246,10 @@ data TabType ...@@ -241,9 +246,10 @@ data TabType
derive instance eqTabType :: Eq TabType derive instance eqTabType :: Eq TabType
derive instance genericTabType :: Generic TabType _
instance showTabType :: Show TabType where instance showTabType :: Show TabType where
show (TabCorpus t) = "Corpus" <> show t show = genericShow
show (TabPairing t) = "Pairing" <> show t
------------------------------------------------------------ ------------------------------------------------------------
nodeTypeUrl :: NodeType -> Url nodeTypeUrl :: NodeType -> Url
......
...@@ -18,7 +18,7 @@ import Unsafe.Coerce (unsafeCoerce) ...@@ -18,7 +18,7 @@ import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Types import Gargantext.Types
import Gargantext.Components.NgramsTable as NT import Gargantext.Components.NgramsTable as NT
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Config (PTabNgramType(..), End(..), Path(..), TabSubType(..), TabType(..), toUrl) import Gargantext.Config (PTabNgramType(..), Offset, Limit, End(..), Path(..), TabSubType(..), TabType(..), toUrl)
import Gargantext.Config.REST (get) import Gargantext.Config.REST (get)
import Gargantext.Components.Loader as Loader import Gargantext.Components.Loader as Loader
import Gargantext.Pages.Annuaire.User.Contacts.Types (Contact) import Gargantext.Pages.Annuaire.User.Contacts.Types (Contact)
...@@ -36,8 +36,10 @@ type Props = NT.Props Contact Mode ...@@ -36,8 +36,10 @@ type Props = NT.Props Contact Mode
type PageParams = NT.PageParams Mode type PageParams = NT.PageParams Mode
getTable :: PTabNgramType -> Maybe Int -> Aff NT.NgramsTable getTable :: PTabNgramType -> Maybe Int -> Offset -> Limit -> Aff NT.NgramsTable
getTable tab = get <<< toUrl Back (Ngrams (TabPairing (TabNgramType tab)) Nothing) getTable tab nodeId offset limit =
get $ toUrl Back (Ngrams (TabPairing (TabNgramType tab))
offset limit Nothing) nodeId
modeTabType :: Mode -> PTabNgramType modeTabType :: Mode -> PTabNgramType
modeTabType Patents = PTabPatents modeTabType Patents = PTabPatents
...@@ -45,7 +47,9 @@ modeTabType Books = PTabBooks ...@@ -45,7 +47,9 @@ modeTabType Books = PTabBooks
modeTabType Communication = PTabCommunication modeTabType Communication = PTabCommunication
loadPage :: PageParams -> Aff NT.NgramsTable loadPage :: PageParams -> Aff NT.NgramsTable
loadPage {nodeId, mode} = getTable (modeTabType mode) (Just nodeId) -- TODO this ignores params loadPage {nodeId, mode, params: {offset, limit}} =
getTable (modeTabType mode) (Just nodeId) offset limit
-- TODO this ignores orderBy
ngramsLoaderClass :: Loader.LoaderClass PageParams NT.NgramsTable ngramsLoaderClass :: Loader.LoaderClass PageParams NT.NgramsTable
ngramsLoaderClass = Loader.createLoaderClass "ContactsNgramsLoader" loadPage ngramsLoaderClass = Loader.createLoaderClass "ContactsNgramsLoader" loadPage
......
...@@ -17,7 +17,7 @@ import Gargantext.Types ...@@ -17,7 +17,7 @@ import Gargantext.Types
import Gargantext.Components.Node (NodePoly) import Gargantext.Components.Node (NodePoly)
import Gargantext.Components.NgramsTable as NT import Gargantext.Components.NgramsTable as NT
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Config (CTabNgramType(..), End(..), Path(..), TabSubType(..), TabType(..), toUrl) import Gargantext.Config (CTabNgramType(..), End(..), Offset, Limit, Path(..), TabSubType(..), TabType(..), toUrl)
import Gargantext.Config.REST (get) import Gargantext.Config.REST (get)
import Gargantext.Components.Loader as Loader import Gargantext.Components.Loader as Loader
import Gargantext.Pages.Corpus.Tabs.Types (CorpusInfo) import Gargantext.Pages.Corpus.Tabs.Types (CorpusInfo)
...@@ -35,8 +35,10 @@ type Props = NT.Props (NodePoly CorpusInfo) Mode ...@@ -35,8 +35,10 @@ type Props = NT.Props (NodePoly CorpusInfo) Mode
type PageParams = NT.PageParams Mode type PageParams = NT.PageParams Mode
getTable :: CTabNgramType -> Maybe Int -> Aff NT.NgramsTable getTable :: CTabNgramType -> Maybe Int -> Offset -> Limit -> Aff NT.NgramsTable
getTable tab = get <<< toUrl Back (Ngrams (TabCorpus (TabNgramType tab)) Nothing) getTable tab nodeId offset limit =
get $ toUrl Back (Ngrams (TabCorpus (TabNgramType tab))
offset limit Nothing) nodeId
modeTabType :: Mode -> CTabNgramType modeTabType :: Mode -> CTabNgramType
modeTabType Authors = CTabAuthors modeTabType Authors = CTabAuthors
...@@ -45,7 +47,9 @@ modeTabType Institutes = CTabInstitutes ...@@ -45,7 +47,9 @@ modeTabType Institutes = CTabInstitutes
modeTabType Terms = CTabTerms modeTabType Terms = CTabTerms
loadPage :: PageParams -> Aff NT.NgramsTable loadPage :: PageParams -> Aff NT.NgramsTable
loadPage {nodeId, mode} = getTable (modeTabType mode) (Just nodeId) -- TODO this ignores params loadPage {nodeId, mode, params: {offset, limit}} =
getTable (modeTabType mode) (Just nodeId) offset limit
-- TODO this ignores orderBy
ngramsLoaderClass :: Loader.LoaderClass PageParams NT.NgramsTable ngramsLoaderClass :: Loader.LoaderClass PageParams NT.NgramsTable
ngramsLoaderClass = Loader.createLoaderClass "CorpusNgramsLoader" loadPage ngramsLoaderClass = Loader.createLoaderClass "CorpusNgramsLoader" loadPage
......
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