Commit 2a06da0c authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FOREST][Search Form] cosmetics.

parent 52db2f1e
......@@ -137,6 +137,7 @@ fldr nt open = if open
color _ = " text-danger"
-}
-- START node text
type NodeTextProps =
( isSelected :: Boolean
......
......@@ -35,7 +35,7 @@ searchBarCpt = R.hooksComponent "G.C.Node.SearchBar.searchBar" cpt
cpt {session, databases, langs, node_id} _ = do
search <- R.useState' Nothing
onSearchChange session search
pure $ H.div { className: "" } [ searchField {databases, langs, search, node_id}]
pure $ H.div {} [ searchField {databases, langs, search, node_id}]
onSearchChange :: Session -> R.State (Maybe Search) -> R.Hooks Unit
......
......@@ -28,7 +28,7 @@ type Search = { database :: Maybe Database
}
defaultSearch :: Search
defaultSearch = { database: Just InGargantext
defaultSearch = { database: Just Gargantext
, term: ""
, lang: Nothing
, org : Nothing
......@@ -54,7 +54,7 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
cpt props@{node_id} _ = do
let search = maybe defaultSearch identity (fst props.search)
term <- R.useState' search.term
db@(curDb /\ setDb) <- R.useState' (Just InGargantext :: Maybe Database)
db@(curDb /\ setDb) <- R.useState' (Just Gargantext :: Maybe Database)
lang <- R.useState' (Nothing :: Maybe Lang)
org@(curOrg /\ setOrg) <- R.useState' (Nothing :: Maybe Org)
filters@(curFilters /\ setFilters) <- R.useState' (Nothing :: Maybe HAL_Filters)
......@@ -63,10 +63,8 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
div { className: "search-field-group" }
[ searchInput term
, langInput lang props.langs
, div {className: "text-primary center"} [text "in"]
, databaseInput db filters org props.databases
, if isHAL curDb
then orgInput org allOrgs
else div {} []
......@@ -99,8 +97,7 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
div {} []
else
div {} []
, div { className: "" }
[ submitButton node_id db term lang org filters props.search ]
, submitButton node_id db term lang org filters props.search
]
hasChanged p p' = (fst p.search /= fst p'.search)
|| (p.databases /= p'.databases )
......@@ -137,6 +134,22 @@ updateFilter org _ = Just $ HAL_IMT { imtOrgs: imtOrgs', structIds: Set.empty}
then Set.fromFoldable allIMTorgs
else Set.fromFoldable [org]
langInput :: R.State (Maybe Lang) -> Array Lang -> R.Element
langInput (lang /\ setLang) langs =
div { className: "form-group" }
[ div {className: "text-primary center"} [text "with lang"]
, R2.select { className: "form-control"
, on: { change: \e -> setLang
$ const
$ readLang
$ e .. "target" .. "value"
}
} (liItem <$> langs)
]
where
liItem :: Lang -> R.Element
liItem lang = option {className : "text-primary center"} [ text (show lang) ]
databaseInput :: R.State (Maybe Database)
-> R.State (Maybe HAL_Filters)
......@@ -145,7 +158,8 @@ databaseInput :: R.State (Maybe Database)
-> R.Element
databaseInput (db /\ setDB) (_ /\ setFilters) (_ /\ setOrg) dbs =
div { className: "form-group" }
[ R2.select { className: "form-control"
[ div {className: "text-primary center"} [text "in database"]
, R2.select { className: "form-control"
, on: { change: \e -> (setDB
$ const
$ readDatabase
......@@ -154,32 +168,17 @@ databaseInput (db /\ setDB) (_ /\ setFilters) (_ /\ setOrg) dbs =
*> (setFilters $ const Nothing)
}
} (liItem <$> dbs)
, div {className:"center"} [ text $ maybe "" doc db ]
]
where
liItem :: Database -> R.Element
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" }
[ div {className: "text-primary center"} [text "with lang"]
, R2.select { className: "form-control"
, on: { change: \e -> setLang
$ const
$ readLang
$ e .. "target" .. "value"
}
} (liItem <$> langs)
]
where
liItem :: Lang -> R.Element
liItem lang = option {className : "text-primary center"} [ text (show lang) ]
orgInput :: R.State (Maybe Org) -> Array Org -> R.Element
orgInput (org /\ setOrg) orgs =
div { className: "form-group" }
[ text "filter with organization: "
[ div {className: "text-primary center"} [text "filter with organization: "]
, R2.select { className: "form-control"
, on: { change: \e -> setOrg
$ const
......@@ -194,7 +193,7 @@ orgInput (org /\ setOrg) orgs =
filterInput :: R.State String -> R.Element
filterInput (term /\ setTerm) =
div {className: ""} [ input { defaultValue: term
div {className: "form-group"} [ input { defaultValue: term
, className: "form-control"
, type: "text"
, on: { change: \e -> setTerm
......@@ -229,12 +228,11 @@ submitButton :: Maybe Int
-> R.State (Maybe HAL_Filters)
-> R.State (Maybe Search)
-> R.Element
submitButton node_id (database /\ _) (term /\ _) (lang /\ _) (org/\_) (filters /\ _) (_ /\ setSearch) =
R.fragment [ div { className : "" } []
, button { className: "btn btn-primary"
submitButton node_id (database /\ _) (term /\ _) (lang /\ _) (org/\_) (filters /\ _) (_ /\ setSearch) = div { className : "panel-footer" }
[ button { className: "btn btn-primary"
, type: "button"
, on: {click: doSearch}
} [ text "Search" ]
} [ text "Launch Search" ]
]
where
doSearch = \_ -> do
......
......@@ -54,36 +54,51 @@ instance encodeJsonLang :: EncodeJson Lang where
------------------------------------------------------------------------
-- | Database search specifications
allDatabases :: Array Database
allDatabases = [ InGargantext
allDatabases = [ Gargantext
, PubMed
, HAL
, IsTex
, Isidore
-- , Web
]
data Database = All
| InGargantext
data Database = All_Databases
| Gargantext
| PubMed
| HAL
| IsTex
| Isidore
| Web
instance showDatabase :: Show Database where
show All = "All"
show InGargantext = "In Gargantext"
show All_Databases= "All Databases"
show Gargantext = "In Gargantext"
show PubMed = "PubMed"
show HAL = "HAL"
show IsTex = "IsTex"
show Isidore= "Isidore"
show Web = "Web"
class Doc a where
doc :: a -> String
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"
readDatabase :: String -> Maybe Database
readDatabase "All" = Just All
readDatabase "In Gargantext" = Just InGargantext
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 _ = 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