Commit ccf44a9c authored by Nicolas Pouillard's avatar Nicolas Pouillard Committed by James Laver

[NGRAMS] refactoring some routes and adding POST for new ngrams

parent b411135a
......@@ -74,7 +74,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(..), NodeType(..))
import Gargantext.Config.REST (get, put)
import Gargantext.Config.REST (get, put, post)
import Gargantext.Components.AutoUpdate (autoUpdateElt)
import Gargantext.Components.Table as T
import Gargantext.Prelude
......@@ -515,6 +515,7 @@ data Action
-- applied to `initTable`.
-- TODO more docs
| Refresh
| AddNewNgram NgramsTerm
type Dispatch = Action -> Effect Unit
......@@ -607,6 +608,13 @@ tableContainer { pageParams
, button [className "btn btn-primary", onClick $ const $ dispatch $ AddTermChildren] [text "Save"]
, button [className "btn btn-secondary", onClick $ const $ dispatch $ SetParentResetChildren Nothing] [text "Cancel"]
]) ngramsParent)
, div [] (
if A.null props.tableBody && pageParams.searchQuery /= "" then [
button [ className "btn btn-primary"
, onClick $ const $ dispatch $ AddNewNgram pageParams.searchQuery
] [text $ "Add " <> pageParams.searchQuery]
] else []
)
, div [ _id "terms_table", className "panel-body" ]
[ table [ className "table able" ]
[ thead [ className "tableHeader"] [props.tableHead]
......@@ -678,6 +686,8 @@ ngramsTableSpec = simpleSpec performAction render
pt = PatchMap $ Map.fromFoldable [Tuple parent pe]
-- TODO ROOT-UPDATE
-- patch the root of the child to be equal to the root of the parent.
performAction (AddNewNgram ngram) {path: {nodeId, listIds, tabType}} _ =
lift $ post (toUrl Back (PutNgrams tabType (head listIds)) $ Just nodeId) [ngram]
render :: Render State Props' Action
render dispatch { path: pageParams
......
......@@ -132,16 +132,6 @@ 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) = "ngrams?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
pathUrl c (Tab t o l s) i =
pathUrl c (NodeAPI Node) i <>
......@@ -160,8 +150,7 @@ pathUrl c (GetNgrams
, searchQuery: q
}) i =
base
<> "/"
<> tabTypeNgramsGet t
<> "/ngrams?ngramsType=" <> showTabType' t
<> offsetUrl o <> limitUrl l
<> orderByUrl orderBy
<> foldMap (\x -> "&list=" <> show x) listIds
......@@ -178,7 +167,7 @@ pathUrl c (GetNgrams
pathUrl c (PutNgrams t listid) i =
pathUrl c (NodeAPI Node) i <> "/" <> tabTypeNgramsPut t <> listid'
pathUrl c (NodeAPI Node) i <> "/ngrams?ngramsType=" <> showTabType' t <> listid'
where
listid' = maybe "" (\x -> "&list=" <> show x) listid
pathUrl c Auth Nothing = c.prePath <> "auth"
......@@ -189,7 +178,7 @@ pathUrl c (Search {limit,offset,orderBy}) _TODO =
<> offsetUrl offset <> limitUrl limit <> orderUrl orderBy
pathUrl c (CorpusMetrics {tabType, listId, limit}) i =
pathUrl c (NodeAPI Corpus) i <> "/metrics"
<> "?list=" <> show listId
<> "?ngrams=" <> show listId
<> "&ngramsType=" <> showTabType' tabType
<> maybe "" (\x -> "&limit=" <> show x) limit
-- TODO fix this url path
......@@ -286,6 +275,7 @@ data Path
, searchQuery :: String
}
| PutNgrams TabType (Maybe ListId)
-- ^ The name is not good. In particular this URL is used both in PUT and POST.
| NodeAPI NodeType
| Search { {-id :: Int
, query :: Array String
......
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