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 ...@@ -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 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." ] (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 (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."]] 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 ...@@ -13,12 +13,15 @@ import Reactix as R
import DOM.Simple.Console (log2) import DOM.Simple.Console (log2)
import Effect.Aff (Aff, launchAff_) import Effect.Aff (Aff, launchAff_)
import Reactix.DOM.HTML as H 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.Modals.Modal (modalShow)
import Gargantext.Components.Search.SearchField (Search, searchField) import Gargantext.Components.Search.SearchField (Search, searchField)
import Gargantext.Sessions (Session) 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 :: Record Props -> R.Element
searchBar props = R.createElement searchBarCpt props [] searchBar props = R.createElement searchBarCpt props []
...@@ -26,10 +29,10 @@ searchBar props = R.createElement searchBarCpt props [] ...@@ -26,10 +29,10 @@ searchBar props = R.createElement searchBarCpt props []
searchBarCpt :: R.Component Props searchBarCpt :: R.Component Props
searchBarCpt = R.hooksComponent "G.C.Node.SearchBar.searchBar" cpt searchBarCpt = R.hooksComponent "G.C.Node.SearchBar.searchBar" cpt
where where
cpt {session, databases} _ = do cpt {session, databases, langs} _ = do
search <- R.useState' Nothing search <- R.useState' Nothing
onSearchChange session search 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 onSearchChange :: Session -> R.State (Maybe Search) -> R.Hooks Unit
...@@ -49,8 +52,8 @@ onSearchChange session (search /\ setSearch) = ...@@ -49,8 +52,8 @@ onSearchChange session (search /\ setSearch) =
log2 "Return:" r log2 "Return:" r
modalShow "addCorpus" modalShow "addCorpus"
searchQuery {database: Nothing, term} = searchQuery {database: Nothing, lang, term} =
over SearchQuery (_ {query=term}) defaultSearchQuery over SearchQuery (_ {query=term}) defaultSearchQuery
searchQuery {database: Just db, term} = searchQuery {database: Just db, lang, term} =
over SearchQuery (_ {databases=[db], query=term}) defaultSearchQuery over SearchQuery (_ {databases=[db], lang=lang, query=term}) defaultSearchQuery
...@@ -10,7 +10,7 @@ import Effect.Uncurried (mkEffectFn1) ...@@ -10,7 +10,7 @@ import Effect.Uncurried (mkEffectFn1)
import FFI.Simple ((..)) import FFI.Simple ((..))
import Reactix as R import Reactix as R
import Reactix.DOM.HTML (text, button, div, input, span, ul, li, a, option) 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. select :: forall props.
R.IsComponent String props (Array R.Element) R.IsComponent String props (Array R.Element)
...@@ -19,14 +19,23 @@ select :: forall props. ...@@ -19,14 +19,23 @@ select :: forall props.
-> R.Element -> R.Element
select = R.createElement "select" select = R.createElement "select"
type Search = { database :: Maybe Database, term :: String }
type Search = { database :: Maybe Database
, term :: String
, lang :: Maybe Lang
}
defaultSearch :: Search defaultSearch :: Search
defaultSearch = { database: Nothing, term: "" } defaultSearch = { database: Nothing
, term: ""
, lang: Nothing
}
type Props = type Props =
-- list of databases to search, or parsers to use on uploads -- list of databases to search, or parsers to use on uploads
( databases :: Array Database ( databases :: Array Database
, langs :: Array Lang
-- State hook for a search, how we get data in and out -- State hook for a search, how we get data in and out
, search :: R.State (Maybe Search) , search :: R.State (Maybe Search)
) )
...@@ -45,15 +54,18 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged ...@@ -45,15 +54,18 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
let search = maybe defaultSearch identity (fst props.search) let search = maybe defaultSearch identity (fst props.search)
term <- R.useState' search.term term <- R.useState' search.term
db <- R.useState' (Nothing :: Maybe Database) db <- R.useState' (Nothing :: Maybe Database)
lang <- R.useState' (Nothing :: Maybe Lang)
pure $ pure $
div { className: "search-field-group" } div { className: "search-field-group" }
[ searchInput term [ searchInput term
, div {className: "text-primary center"} [text "in"] , div {className: "text-primary center"} [text "in"]
, databaseInput db props.databases , databaseInput db props.databases
, div { className: "panel-footer" } [ submitButton db term props.search ] , langInput lang props.langs
, div { className: "panel-footer" } [ submitButton db term lang props.search ]
] ]
hasChanged p p' = (fst p.search /= fst p'.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 databaseInput :: R.State (Maybe Database) -> Array Database -> R.Element
...@@ -72,6 +84,21 @@ databaseInput (db /\ setDB) dbs = ...@@ -72,6 +84,21 @@ databaseInput (db /\ setDB) dbs =
liItem db = option {className : "text-primary center"} [ text (show db) ] 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 :: R.State String -> R.Element
searchInput (term /\ setTerm) = searchInput (term /\ setTerm) =
...@@ -83,8 +110,12 @@ searchInput (term /\ setTerm) = ...@@ -83,8 +110,12 @@ searchInput (term /\ setTerm) =
where onChange = mkEffectFn1 $ \e -> setTerm $ const $ e .. "target" .. "value" where onChange = mkEffectFn1 $ \e -> setTerm $ const $ e .. "target" .. "value"
submitButton :: R.State (Maybe Database) -> R.State String -> R.State (Maybe Search) -> R.Element submitButton :: R.State (Maybe Database)
submitButton (database /\ _) (term /\ _) (_ /\ setSearch) = -> 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" button { className: "btn btn-primary text-center"
, type: "button" , type: "button"
, onClick: click , onClick: click
...@@ -93,4 +124,4 @@ submitButton (database /\ _) (term /\ _) (_ /\ setSearch) = ...@@ -93,4 +124,4 @@ submitButton (database /\ _) (term /\ _) (_ /\ setSearch) =
click = mkEffectFn1 $ \_ -> do click = mkEffectFn1 $ \_ -> do
case term of case term of
"" -> setSearch $ const Nothing "" -> setSearch $ const Nothing
_ -> setSearch $ const $ Just { database, term } _ -> setSearch $ const $ Just { database, lang, term }
...@@ -18,61 +18,64 @@ import Gargantext.Utils (id) ...@@ -18,61 +18,64 @@ import Gargantext.Utils (id)
import URI.Extra.QueryPairs as QP import URI.Extra.QueryPairs as QP
import URI.Query as Q 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 :: Array Database
allDatabases = [All, PubMed allDatabases = [All, PubMed
, HAL_EN , HAL
, HAL_FR , IsTex
, IsTex_EN , Isidore
, IsTex_FR
, Isidore_EN, Isidore_FR
] ]
data Database = All | PubMed data Database = All | PubMed
| HAL_EN | HAL_FR | HAL
| IsTex_EN | IsTex_FR | IsTex
| Isidore_EN | Isidore_FR | Isidore
data Langs = FR | EN
-- | 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 instance showDatabase :: Show Database where
show All = "In Gargantext" show All = "In Gargantext"
show PubMed = "PubMed" show PubMed = "PubMed"
show HAL = "HAL"
show HAL_EN = "HAL_" <> show EN show IsTex = "IsTex"
show HAL_FR = "HAL_" <> show FR show Isidore= "Isidore"
show IsTex_EN = "IsTex_" <> show EN
show IsTex_FR = "IsTex_" <> show FR
show Isidore_EN = "Isidore_" <> show EN
show Isidore_FR = "Isidore_" <> show FR
readDatabase :: String -> Maybe Database readDatabase :: String -> Maybe Database
readDatabase "All" = Just All readDatabase "All" = Just All
readDatabase "PubMed" = Just PubMed readDatabase "PubMed" = Just PubMed
readDatabase "HAL" = Just HAL
readDatabase "HAL_EN" = Just HAL_EN readDatabase "IsTex" = Just IsTex
readDatabase "HAL_FR" = Just HAL_FR readDatabase "Isidore"= Just Isidore
readDatabase _ = Nothing
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
derive instance eqDatabase :: Eq Database derive instance eqDatabase :: Eq Database
instance encodeJsonDatabase :: EncodeJson Database where instance encodeJsonDatabase :: EncodeJson Database where
encodeJson a = encodeJson (show a) encodeJson a = encodeJson (show a)
data SearchOrder data SearchOrder
= DateAsc = DateAsc
| DateDesc | DateDesc
...@@ -90,13 +93,15 @@ instance showSearchOrder :: Show SearchOrder where ...@@ -90,13 +93,15 @@ instance showSearchOrder :: Show SearchOrder where
show ScoreDesc = "ScoreDesc" show ScoreDesc = "ScoreDesc"
newtype SearchQuery = SearchQuery newtype SearchQuery = SearchQuery
{ query :: String { query :: String
, databases :: Array Database , databases :: Array Database
, corpus_id :: Maybe Int , lang :: Maybe Lang
, node_id :: Maybe Int
, files_id :: Array String , files_id :: Array String
, offset :: Maybe Int , offset :: Maybe Int
, limit :: Maybe Int , limit :: Maybe Int
, order :: Maybe SearchOrder } , order :: Maybe SearchOrder
}
derive instance newtypeSearchQuery :: Newtype SearchQuery _ derive instance newtypeSearchQuery :: Newtype SearchQuery _
...@@ -104,7 +109,8 @@ defaultSearchQuery :: SearchQuery ...@@ -104,7 +109,8 @@ defaultSearchQuery :: SearchQuery
defaultSearchQuery = SearchQuery defaultSearchQuery = SearchQuery
{ query: "" { query: ""
, databases: allDatabases , databases: allDatabases
, corpus_id: Nothing , lang : Nothing
, node_id: Nothing
, files_id : [] , files_id : []
, offset: Nothing , offset: Nothing
, limit: Nothing , limit: Nothing
...@@ -123,10 +129,10 @@ instance searchQueryToQuery :: ToQuery SearchQuery where ...@@ -123,10 +129,10 @@ instance searchQueryToQuery :: ToQuery SearchQuery where
[ QP.keyFromString k /\ Just (QP.valueFromString $ show v) ] [ QP.keyFromString k /\ Just (QP.valueFromString $ show v) ]
instance encodeJsonSearchQuery :: EncodeJson SearchQuery where instance encodeJsonSearchQuery :: EncodeJson SearchQuery where
encodeJson (SearchQuery {query, databases, corpus_id, files_id}) encodeJson (SearchQuery {query, databases, node_id, files_id})
= "query" := query = "query" := query
~> "databases" := databases ~> "databases" := databases
~> "corpus_id" := fromMaybe 0 corpus_id ~> "node_id" := fromMaybe 0 node_id
~> "files_id" := files_id ~> "files_id" := files_id
~> jsonEmptyObject ~> 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