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