[NGRAM] add basic support for offset & limit

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