Commit b1c31559 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIX] adding database to query.

parent c05e1431
......@@ -60,9 +60,8 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
databaseInput :: R.State (Maybe Database) -> Array Database -> R.Element
databaseInput (db /\ setDB) dbs =
div { className: "input-group-btn search-panel dropdown" }
[
dropdownBtn db
, ul {className: "dropdown-menu", role: "menu"} (liItem <$> dbs)
[ dropdownBtn db
, ul {className: "dropdown-menu", role: "menu"} (liItem <$> dbs)
]
where
liItem db = li { onClick }
......@@ -92,4 +91,4 @@ submitButton (database /\ _) (term /\ _) (_ /\ setSearch) =
click = mkEffectFn1 $ \_ -> do
case term of
"" -> setSearch (const Nothing)
_ -> setSearch (const $ Just { database, term })
_ -> setSearch (const $ Just { database, term })
module Gargantext.Components.Search.Types where
import Control.Monad.Cont.Trans (lift)
import Data.Argonaut (class EncodeJson, jsonEmptyObject, (:=), (~>))
import Data.Argonaut (class EncodeJson, jsonEmptyObject, (:=), (~>), encodeJson)
import Data.Maybe (Maybe(..), fromMaybe, maybe)
import Data.Array (head)
import Data.Newtype (class Newtype)
import Data.Tuple (Tuple)
import Data.Tuple.Nested ((/\))
......@@ -22,10 +23,10 @@ import URI.Extra.QueryPairs as QP
data Database = All | PubMed | HAL | IsTex
instance showDatabase :: Show Database where
show All = "All"
show All = "All"
show PubMed = "PubMed"
show HAL = "HAL"
show IsTex = "IsTex"
show HAL = "HAL"
show IsTex = "IsTex"
readDatabase :: String -> Maybe Database
readDatabase "All" = Just All
......@@ -36,6 +37,10 @@ readDatabase _ = Nothing
derive instance eqDatabase :: Eq Database
instance encodeJsonDatabase :: EncodeJson Database where
encodeJson a = encodeJson (show a)
allDatabases :: Array Database
allDatabases = [All, HAL, IsTex, PubMed]
......@@ -85,8 +90,9 @@ instance searchQueryToQuery :: ToQuery SearchQuery where
[ QP.keyFromString k /\ Just (QP.valueFromString $ show v) ]
instance encodeJsonSearchQuery :: EncodeJson SearchQuery where
encodeJson (SearchQuery {query, corpus_id, files_id})
= "query" := query
~> "corpus_id" := fromMaybe 0 corpus_id
~> "files_id" := files_id
encodeJson (SearchQuery {query, databases, corpus_id, files_id})
= "query" := query
~> "databases" := databases
~> "corpus_id" := fromMaybe 0 corpus_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