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