Commit 04eb4bb0 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FOREST][SEARCH] split database and lang.

parent b01a7fe6
......@@ -317,7 +317,7 @@ panelAction d {id,name,nodeType,action, session} p = case action of
(Just Download) -> R.fragment [ H.p {} [H.text $ "Soon, you will be able to dowload your file here"]]
(Just SearchBox) -> R.fragment [ H.p {} [ H.text $ "Search and create a private corpus with the search query as corpus name." ]
, searchBar {session, databases:allDatabases}
, searchBar {session, databases:allDatabases, langs:allLangs}
]
(Just Delete) -> case nodeType of
NodeUser -> R.fragment [ H.div {} [H.text "Yes, we are RGPD compliant! But you can not delete User Node yet (we are still on development). Thanks for your comprehensin."]]
......
......@@ -13,12 +13,15 @@ import Reactix as R
import DOM.Simple.Console (log2)
import Effect.Aff (Aff, launchAff_)
import Reactix.DOM.HTML as H
import Gargantext.Components.Search.Types (Database, SearchQuery(..), defaultSearchQuery, performSearch)
import Gargantext.Components.Search.Types (Database, SearchQuery(..), defaultSearchQuery, performSearch, Lang(..))
import Gargantext.Components.Modals.Modal (modalShow)
import Gargantext.Components.Search.SearchField (Search, searchField)
import Gargantext.Sessions (Session)
type Props = ( session :: Session, databases :: Array Database )
type Props = ( session :: Session
, databases :: Array Database
, langs :: Array Lang
)
searchBar :: Record Props -> R.Element
searchBar props = R.createElement searchBarCpt props []
......@@ -26,10 +29,10 @@ searchBar props = R.createElement searchBarCpt props []
searchBarCpt :: R.Component Props
searchBarCpt = R.hooksComponent "G.C.Node.SearchBar.searchBar" cpt
where
cpt {session, databases} _ = do
cpt {session, databases, langs} _ = do
search <- R.useState' Nothing
onSearchChange session search
pure $ H.div { className: "" } [ searchField {databases, search }]
pure $ H.div { className: "" } [ searchField {databases, langs, search}]
onSearchChange :: Session -> R.State (Maybe Search) -> R.Hooks Unit
......@@ -49,8 +52,8 @@ onSearchChange session (search /\ setSearch) =
log2 "Return:" r
modalShow "addCorpus"
searchQuery {database: Nothing, term} =
searchQuery {database: Nothing, lang, term} =
over SearchQuery (_ {query=term}) defaultSearchQuery
searchQuery {database: Just db, term} =
over SearchQuery (_ {databases=[db], query=term}) defaultSearchQuery
searchQuery {database: Just db, lang, term} =
over SearchQuery (_ {databases=[db], lang=lang, query=term}) defaultSearchQuery
......@@ -10,7 +10,7 @@ import Effect.Uncurried (mkEffectFn1)
import FFI.Simple ((..))
import Reactix as R
import Reactix.DOM.HTML (text, button, div, input, span, ul, li, a, option)
import Gargantext.Components.Search.Types (Database(..), readDatabase)
import Gargantext.Components.Search.Types (Database(..), readDatabase, Lang(..), readLang)
select :: forall props.
R.IsComponent String props (Array R.Element)
......@@ -19,14 +19,23 @@ select :: forall props.
-> R.Element
select = R.createElement "select"
type Search = { database :: Maybe Database, term :: String }
type Search = { database :: Maybe Database
, term :: String
, lang :: Maybe Lang
}
defaultSearch :: Search
defaultSearch = { database: Nothing, term: "" }
defaultSearch = { database: Nothing
, term: ""
, lang: Nothing
}
type Props =
-- list of databases to search, or parsers to use on uploads
( databases :: Array Database
, langs :: Array Lang
-- State hook for a search, how we get data in and out
, search :: R.State (Maybe Search)
)
......@@ -45,15 +54,18 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
let search = maybe defaultSearch identity (fst props.search)
term <- R.useState' search.term
db <- R.useState' (Nothing :: Maybe Database)
lang <- R.useState' (Nothing :: Maybe Lang)
pure $
div { className: "search-field-group" }
[ searchInput term
, div {className: "text-primary center"} [text "in"]
, databaseInput db props.databases
, div { className: "panel-footer" } [ submitButton db term props.search ]
, databaseInput db props.databases
, langInput lang props.langs
, div { className: "panel-footer" } [ submitButton db term lang props.search ]
]
hasChanged p p' = (fst p.search /= fst p'.search)
|| (p.databases /= p'.databases)
|| (p.databases /= p'.databases )
|| (p.langs /= p'.langs )
databaseInput :: R.State (Maybe Database) -> Array Database -> R.Element
......@@ -72,6 +84,21 @@ databaseInput (db /\ setDB) dbs =
liItem db = option {className : "text-primary center"} [ text (show db) ]
langInput :: R.State (Maybe Lang) -> Array Lang -> R.Element
langInput (lang /\ setLang) langs =
div { className: "form-group" }
[ R2.select { className: "form-control"
, onChange: mkEffectFn1
$ \e -> setLang
$ const
$ readLang
$ e .. "target" .. "value"
} (liItem <$> langs)
]
where
liItem :: Lang -> R.Element
liItem lang = option {className : "text-primary center"} [ text (show lang) ]
searchInput :: R.State String -> R.Element
searchInput (term /\ setTerm) =
......@@ -83,8 +110,12 @@ searchInput (term /\ setTerm) =
where onChange = mkEffectFn1 $ \e -> setTerm $ const $ e .. "target" .. "value"
submitButton :: R.State (Maybe Database) -> R.State String -> R.State (Maybe Search) -> R.Element
submitButton (database /\ _) (term /\ _) (_ /\ setSearch) =
submitButton :: R.State (Maybe Database)
-> R.State String
-> R.State (Maybe Lang)
-> R.State (Maybe Search)
-> R.Element
submitButton (database /\ _) (term /\ _) (lang /\ _) (_ /\ setSearch) =
button { className: "btn btn-primary text-center"
, type: "button"
, onClick: click
......@@ -93,4 +124,4 @@ submitButton (database /\ _) (term /\ _) (_ /\ setSearch) =
click = mkEffectFn1 $ \_ -> do
case term of
"" -> setSearch $ const Nothing
_ -> setSearch $ const $ Just { database, term }
_ -> setSearch $ const $ Just { database, lang, term }
......@@ -18,61 +18,64 @@ import Gargantext.Utils (id)
import URI.Extra.QueryPairs as QP
import URI.Query as Q
------------------------------------------------------------------------
-- | Lang search specifications
allLangs :: Array Lang
allLangs = [ EN
, FR
, Universal
]
data Lang = FR | EN | Universal
instance showLang :: Show Lang where
show FR = "FR"
show EN = "EN"
show Universal = "Universal"
derive instance eqLang :: Eq Lang
readLang :: String -> Maybe Lang
readLang "FR" = Just FR
readLang "EN" = Just EN
readLang "Universal" = Just Universal
readLang _ = Nothing
------------------------------------------------------------------------
-- | Database search specifications
allDatabases :: Array Database
allDatabases = [All, PubMed
, HAL_EN
, HAL_FR
, IsTex_EN
, IsTex_FR
, Isidore_EN, Isidore_FR
, HAL
, IsTex
, Isidore
]
data Database = All | PubMed
| HAL_EN | HAL_FR
| IsTex_EN | IsTex_FR
| Isidore_EN | Isidore_FR
data Langs = FR | EN
| HAL
| IsTex
| Isidore
-- | Types needed for now maybe not useful later (we could factorize the Type with Database Lang but no need for now)
instance showLangs :: Show Langs where
show FR = "FR"
show EN = "EN"
instance showDatabase :: Show Database where
show All = "In Gargantext"
show PubMed = "PubMed"
show HAL_EN = "HAL_" <> show EN
show HAL_FR = "HAL_" <> show FR
show IsTex_EN = "IsTex_" <> show EN
show IsTex_FR = "IsTex_" <> show FR
show Isidore_EN = "Isidore_" <> show EN
show Isidore_FR = "Isidore_" <> show FR
show HAL = "HAL"
show IsTex = "IsTex"
show Isidore= "Isidore"
readDatabase :: String -> Maybe Database
readDatabase "All" = Just All
readDatabase "All" = Just All
readDatabase "PubMed" = Just PubMed
readDatabase "HAL_EN" = Just HAL_EN
readDatabase "HAL_FR" = Just HAL_FR
readDatabase "IsTex_EN" = Just IsTex_EN
readDatabase "IsTex_FR" = Just IsTex_FR
readDatabase "Isidore_EN" = Just Isidore_EN
readDatabase "Isidore_FR" = Just Isidore_FR
readDatabase _ = Nothing
readDatabase "HAL" = Just HAL
readDatabase "IsTex" = Just IsTex
readDatabase "Isidore"= Just Isidore
readDatabase _ = Nothing
derive instance eqDatabase :: Eq Database
instance encodeJsonDatabase :: EncodeJson Database where
encodeJson a = encodeJson (show a)
data SearchOrder
= DateAsc
| DateDesc
......@@ -90,13 +93,15 @@ instance showSearchOrder :: Show SearchOrder where
show ScoreDesc = "ScoreDesc"
newtype SearchQuery = SearchQuery
{ query :: String
{ query :: String
, databases :: Array Database
, corpus_id :: Maybe Int
, lang :: Maybe Lang
, node_id :: Maybe Int
, files_id :: Array String
, offset :: Maybe Int
, limit :: Maybe Int
, order :: Maybe SearchOrder }
, offset :: Maybe Int
, limit :: Maybe Int
, order :: Maybe SearchOrder
}
derive instance newtypeSearchQuery :: Newtype SearchQuery _
......@@ -104,7 +109,8 @@ defaultSearchQuery :: SearchQuery
defaultSearchQuery = SearchQuery
{ query: ""
, databases: allDatabases
, corpus_id: Nothing
, lang : Nothing
, node_id: Nothing
, files_id : []
, offset: Nothing
, limit: Nothing
......@@ -123,10 +129,10 @@ instance searchQueryToQuery :: ToQuery SearchQuery where
[ QP.keyFromString k /\ Just (QP.valueFromString $ show v) ]
instance encodeJsonSearchQuery :: EncodeJson SearchQuery where
encodeJson (SearchQuery {query, databases, corpus_id, files_id})
encodeJson (SearchQuery {query, databases, node_id, files_id})
= "query" := query
~> "databases" := databases
~> "corpus_id" := fromMaybe 0 corpus_id
~> "node_id" := fromMaybe 0 node_id
~> "files_id" := files_id
~> jsonEmptyObject
......
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