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

[SEARCH FORM][WIP] Advanced option tree.

parent c45116fb
......@@ -19,7 +19,8 @@ select :: forall props.
-> R.Element
select = R.createElement "select"
type Search = { database :: Maybe Database
type Search = { datafield :: Maybe DataField
, database :: Maybe Database
, term :: String
, lang :: Maybe Lang
, org :: Maybe Org
......@@ -28,9 +29,10 @@ type Search = { database :: Maybe Database
}
defaultSearch :: Search
defaultSearch = { database: Just Gargantext
defaultSearch = { datafield: Just Gargantext
, database: Just PubMed
, term: ""
, lang: Nothing
, lang: Just EN
, org : Nothing
, filters: Nothing
, node_id: Nothing
......@@ -53,17 +55,25 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
where
cpt props@{node_id} _ = do
let search = maybe defaultSearch identity (fst props.search)
term <- R.useState' search.term
db@(curDb /\ setDb) <- R.useState' (Just Gargantext :: Maybe Database)
lang <- R.useState' (Nothing :: Maybe Lang)
term@(curTerm /\ _) <- R.useState' search.term
df@(curDf /\ setDf) <- R.useState' (Just Gargantext :: Maybe DataField)
db@(curDb /\ setDb) <- R.useState' (Nothing :: Maybe Database)
lang@(curLg /\ _) <- R.useState' (Nothing :: Maybe Lang)
org@(curOrg /\ setOrg) <- R.useState' (Nothing :: Maybe Org)
filters@(curFilters /\ setFilters) <- R.useState' (Nothing :: Maybe HAL_Filters)
fi <- R.useState' ""
pure $
div { className: "search-field-group" }
[ searchInput term
, langInput lang props.langs
, databaseInput db filters org props.databases
, if curTerm == ""
then div {}[]
else div {} [ langNav lang props.langs
, if curLg == Nothing
then div {}[]
else div {} [ dataFieldNav df dataFields
, if curDf == Just (External Nothing)
then databaseInput db filters org props.databases
else div {} []
, if isHAL curDb
then orgInput org allOrgs
......@@ -99,6 +109,8 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
div {} []
, submitButton node_id db term lang org filters props.search
]
]
]
hasChanged p p' = (fst p.search /= fst p'.search)
|| (p.databases /= p'.databases )
|| (p.langs /= p'.langs )
......@@ -128,14 +140,18 @@ updateFilter org (Just (HAL_IMT {imtOrgs})) =
then Set.fromFoldable allIMTorgs
else Set.insert org imtOrgs
updateFilter org _ = Just $ HAL_IMT { imtOrgs: imtOrgs', structIds: Set.empty}
updateFilter org _ = Just $ HAL_IMT { imtOrgs: imtOrgs'
, structIds: Set.empty
}
where
imtOrgs' = if org == All_IMT
then Set.fromFoldable allIMTorgs
else Set.fromFoldable [org]
langInput :: R.State (Maybe Lang) -> Array Lang -> R.Element
langInput (lang /\ setLang) langs =
------------------------------------------------------------------------
langList :: R.State (Maybe Lang) -> Array Lang -> R.Element
langList (lang /\ setLang) langs =
div { className: "form-group" }
[ div {className: "text-primary center"} [text "with lang"]
, R2.select { className: "form-control"
......@@ -150,7 +166,33 @@ langInput (lang /\ setLang) langs =
liItem :: Lang -> R.Element
liItem lang = option {className : "text-primary center"} [ text (show lang) ]
langNav :: R.State (Maybe Lang) -> Array Lang -> R.Element
langNav (lang /\ setLang) langs =
R.fragment [ div {className: "text-primary center"} [text "with lang"]
, div { className: "nav nav-tabs"} (liItem <$> langs)
]
where
liItem :: Lang -> R.Element
liItem lang' = div { className : "nav-item nav-link" <> if (Just lang') == lang then " active" else ""
, on: { click: \_ -> setLang $ const $ Just lang' }
} [ text (show lang') ]
------------------------------------------------------------------------
dataFieldNav :: R.State (Maybe DataField) -> Array DataField -> R.Element
dataFieldNav (df /\ setDf) datafields =
R.fragment [ div {className: "text-primary center"} [text "with DataField"]
, div { className: "nav nav-tabs"} (liItem <$> dataFields)
]
where
liItem :: DataField -> R.Element
liItem df' = div { className : "nav-item nav-link" <> if (Just df') == df then " active" else ""
, on: { click: \_ -> setDf $ const $ Just df'
}
} [ text (show df') ]
------------------------------------------------------------------------
databaseInput :: R.State (Maybe Database)
-> R.State (Maybe HAL_Filters)
-> R.State (Maybe Org)
......@@ -238,4 +280,4 @@ submitButton node_id (database /\ _) (term /\ _) (lang /\ _) (org/\_) (filters /
doSearch = \_ -> do
case term of
"" -> setSearch $ const Nothing
_ -> setSearch $ const $ Just { database, lang, filters, term, org, node_id}
_ -> setSearch $ const $ Just {datafield: Nothing, database, lang, filters, term, org, node_id}
......@@ -22,6 +22,10 @@ import Gargantext.Utils (id)
import URI.Extra.QueryPairs as QP
import URI.Query as Q
------------------------------------------------------------------------
class Doc a where
doc :: a -> String
------------------------------------------------------------------------
-- | Lang search specifications
allLangs :: Array Lang
......@@ -51,11 +55,40 @@ readLang _ = Nothing
instance encodeJsonLang :: EncodeJson Lang where
encodeJson a = encodeJson (show a)
------------------------------------------------------------------------
-- | DataField search specifications
dataFields :: Array DataField
dataFields = [ Gargantext
, External Nothing
, Web
]
data DataField = Gargantext
| External (Maybe Database)
| Web
instance showDataField :: Show DataField where
show Gargantext = "In Gargantext"
show (External _) = "Ext.Database"
show Web = "Web"
instance docDataField :: Doc DataField where
doc Gargantext = "All Gargantext Database"
doc (External _) = "External (scientific) databases"
doc Web = "All the web crawled with meta-search-engine SearX"
instance eqDataField :: Eq DataField where
eq Gargantext Gargantext = true
eq (External _) (External _) = true
eq Web Web = true
eq _ _ = false
------------------------------------------------------------------------
-- | Database search specifications
allDatabases :: Array Database
allDatabases = [ Gargantext
, PubMed
allDatabases = [ PubMed
, HAL
, IsTex
, Isidore
......@@ -65,50 +98,40 @@ allDatabases = [ Gargantext
]
data Database = All_Databases
| Gargantext
| PubMed
| HAL
| IsTex
| Isidore
| Web
| News
| SocialNetworks
-- | News
-- | SocialNetworks
instance showDatabase :: Show Database where
show All_Databases= "All Databases"
show Gargantext = "In Gargantext"
show PubMed = "PubMed"
show HAL = "HAL"
show IsTex = "IsTex"
show Isidore= "Isidore"
show Web = "Web"
show News = "News"
show SocialNetworks = "Social Networks"
class Doc a where
doc :: a -> String
-- show News = "News"
-- show SocialNetworks = "Social Networks"
instance docDatabase :: Doc Database where
doc All_Databases = "All databases"
doc Gargantext = "All Gargantext Database"
doc PubMed = "All Medical publications"
doc HAL = "All open science (archives ouvertes)"
doc IsTex = "All Elsevier enriched by CNRS/INIST"
doc Isidore = "All (French) Social Sciences"
doc Web = "All the web crawled with meta-search-engine SearX"
doc News = "Web filtered by News"
doc SocialNetworks = "Web filtered by MicroBlogs"
-- doc News = "Web filtered by News"
-- doc SocialNetworks = "Web filtered by MicroBlogs"
readDatabase :: String -> Maybe Database
readDatabase "All Databases" = Just All_Databases
readDatabase "Gargantext" = Just Gargantext
readDatabase "PubMed" = Just PubMed
readDatabase "HAL" = Just HAL
readDatabase "IsTex" = Just IsTex
readDatabase "Isidore"= Just Isidore
readDatabase "Web" = Just Web
readDatabase "News" = Just News
readDatabase "Social Networks" = Just SocialNetworks
-- readDatabase "Web" = Just Web
-- readDatabase "News" = Just News
-- readDatabase "Social Networks" = Just SocialNetworks
readDatabase _ = Nothing
derive instance eqDatabase :: Eq Database
......
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