Commit 3e4ae118 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[WIP][SECU] Doc ngrams: needs GetNgrams and PutNGrams.

parent 6104d122
......@@ -89,8 +89,12 @@ import Gargantext.Sessions (Session, get, put, post)
import Gargantext.Types (OrderBy(..), CTabNgramType(..), TabType, TermList(..), TermSize)
import Gargantext.Utils.KarpRabin (indicesOfAny)
data NodeId = NodeId { corpusId :: Int
, documentId :: Maybe Int
}
type CoreParams s =
{ nodeId :: Int
{ nodeId :: NodeId
-- ^ This node can be a corpus or contact.
, listIds :: Array Int
, tabType :: TabType
......@@ -597,10 +601,12 @@ loadNgramsTable
{ nodeId, listIds, termListFilter, termSizeFilter, session
, searchQuery, tabType, params: {offset, limit, orderBy}}
= get session query
where query = GetNgrams { tabType, offset, limit, listIds
where
NodeId {corpusId, documentId} = nodeId
query = GetNgrams { tabType, offset, limit, listIds
, orderBy: convOrderBy <$> orderBy
, termListFilter, termSizeFilter
, searchQuery } (Just nodeId)
, searchQuery } (Just corpusId) documentId
convOrderBy :: T.OrderByDirection T.ColumnName -> OrderBy
convOrderBy (T.ASC (T.ColumnName "Score (Occurrences)")) = ScoreAsc
......
......@@ -364,19 +364,19 @@ documentLayoutCpt = R.hooksComponent "G.P.Corpus.Document.documentLayout" cpt
R2.createElement' docViewClass {path, loaded} []
where
tabType = TabDocument (TabNgramType CTabTerms)
path = {session, nodeId, listIds: [listId], corpusId, tabType}
path = {session, nodeId, listIds: [listId], corpusId, tabType}
------------------------------------------------------------------------
loadDocument :: Session -> Int -> Aff NodeDocument
loadDocument session nodeId = get session $ NodeAPI Node (Just nodeId) ""
loadDocument :: Session -> Maybe Int -> Int -> Aff NodeDocument
loadDocument session corpusId nodeId =
get session $ SessionCorpusDocument corpusId (Just nodeId)
loadData :: DocPath -> Aff LoadedData
loadData {session, nodeId, listIds, tabType} = do
document <- loadDocument session nodeId
loadData {session, nodeId, corpusId, listIds, tabType} = do
document <- loadDocument session corpusId nodeId
ngramsTable <- loadNgramsTable
{ session
, nodeId
, NodeId corpusId (Just nodeId)
, listIds
, params: { offset : 0, limit : 100, orderBy: Nothing}
, tabType
......
......@@ -117,26 +117,27 @@ sessionPath :: R.SessionRoute -> String
sessionPath (R.Tab t i) = sessionPath (R.NodeAPI Node i (showTabType' t))
sessionPath (R.Children n o l s i) = sessionPath (R.NodeAPI Node i ("children?type=" <> show n <> offsetUrl o <> limitUrl l <> orderUrl s))
sessionPath (R.NodeAPI Phylo pId p) = "phyloscape?nodeId=" <> (show $ maybe 0 identity pId) <> p
sessionPath (R.GetNgrams opts i) =
sessionPath (R.GetNgrams opts c i) =
base opts.tabType
$ "ngrams?ngramsType="
<> showTabType' opts.tabType
<> offsetUrl opts.offset
<> limitUrl opts.limit
<> orderByUrl opts.orderBy
<> foldMap (\x -> "&list=" <> show x) opts.listIds
<> offsetUrl opts.offset
<> limitUrl opts.limit
<> orderByUrl opts.orderBy
<> foldMap (\x -> "&list=" <> show x) opts.listIds
<> foldMap (\x -> "&listType=" <> show x) opts.termListFilter
<> foldMap termSizeFilter opts.termSizeFilter
<> search opts.searchQuery
where
base (TabCorpus _) = sessionPath <<< R.NodeAPI Node i
base _ = sessionPath <<< R.NodeAPI Url_Document i
termSizeFilter MonoTerm = "&minTermSize=0&maxTermSize=1"
base :: TabType -> String
base (TabCorpus _) = sessionPath <<< R.NodeAPI Node c
base _ = sessionPath <<< (R.SessionCorpusDocument c i)
termSizeFilter MonoTerm = "&minTermSize=0&maxTermSize=1"
termSizeFilter MultiTerm = "&minTermSize=2"
search "" = ""
search s = "&search=" <> s
sessionPath (R.ListDocument lId dId) =
sessionPath $ R.NodeAPI NodeList lId ("document/" <> (show $ maybe 0 identity dId))
search s = "&search=" <> s
sessionPath (R.SessionCorpusDocument cId dId) =
sessionPath $ R.NodeAPI Corpus cId ("document/" <> (show $ maybe 0 identity dId))
sessionPath (R.PutNgrams t listId termList i) =
sessionPath $ R.NodeAPI Node i
$ "ngrams?ngramsType="
......
......@@ -22,11 +22,11 @@ data AppRoute
data SessionRoute
= Tab TabType (Maybe Id)
| Children NodeType Offset Limit (Maybe OrderBy) (Maybe Id)
| GetNgrams NgramsGetOpts (Maybe Id)
| GetNgrams NgramsGetOpts (Maybe Id) (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.
| NodeAPI NodeType (Maybe Id) String
| ListDocument (Maybe ListId) (Maybe Id)
| SessionCorpusDocument (Maybe Id) (Maybe Id)
| Search SearchOpts (Maybe Id)
| CorpusMetrics CorpusMetricOpts (Maybe Id)
| Chart ChartOpts (Maybe Id)
......
......@@ -103,7 +103,7 @@ instance optionalInstance :: Union r t s => Optional r s
showTabType' :: TabType -> String
showTabType' (TabCorpus t) = show t
showTabType' (TabDocument t) = show t
showTabType' (TabPairing t) = show t
showTabType' (TabPairing t) = show t
data TabPostQuery = TabPostQuery {
offset :: 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