Commit 360cb569 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[SEARCH FORM][WIP] Before Fun with Types.

parent c297207e
module Gargantext.Components.Search.SearchField module Gargantext.Components.Search.SearchField
( Search, Props, searchField, searchFieldComponent )where ( Search, Props, searchField, searchFieldComponent )where
import Prelude (bind, const, identity, pure, show, ($), (/=), (<$>), (||), (==), map, (<>), (&&), (*>), (>>=), (>=>)) import Prelude (bind, const, identity, pure, show, ($), (/=), (<$>), (||), (==), map, (<>), (&&), (*>), (>>=), (>=>), (<))
import Data.Maybe (Maybe(..), maybe, isJust) import Data.Maybe (Maybe(..), maybe, isJust)
import Data.String (length)
import Data.Set as Set import Data.Set as Set
import Data.Tuple (fst) import Data.Tuple (fst)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
...@@ -65,14 +66,18 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged ...@@ -65,14 +66,18 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
pure $ pure $
div { className: "search-field-group" } div { className: "search-field-group" }
[ searchInput term [ searchInput term
, if curTerm == "" , if length curTerm < 3
then div {}[] then
else div {} [ langNav lang props.langs div {}[]
else
div {} [ langNav lang props.langs
, if curLg == Nothing , if curLg == Nothing
then div {}[] then
else div {} [ dataFieldNav df dataFields div {}[]
else
div {} [ dataFieldNav df dataFields
, if curDf == Just (External Nothing) , if curDf == Just (External Nothing)
then databaseInput db filters org props.databases then databaseInput df db filters org props.databases
else div {} [] else div {} []
, if isHAL curDb , if isHAL curDb
...@@ -87,9 +92,9 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged ...@@ -87,9 +92,9 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
[ ul {} $ map ( \org' -> li {} [ ul {} $ map ( \org' -> li {}
[ input { type: "checkbox" [ input { type: "checkbox"
, checked: isInFilters org' curFilters , checked: isInFilters org' curFilters
, on: {change: \_ -> setFilters , on: {change: \_ -> (setFilters
$ const $ const
$ updateFilter org' curFilters $ updateFilter org' curFilters)
} }
} }
, if org' == All_IMT , if org' == All_IMT
...@@ -107,9 +112,9 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged ...@@ -107,9 +112,9 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
div {} [] div {} []
else else
div {} [] div {} []
, 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) hasChanged p p' = (fst p.search /= fst p'.search)
|| (p.databases /= p'.databases ) || (p.databases /= p'.databases )
...@@ -183,6 +188,7 @@ dataFieldNav :: R.State (Maybe DataField) -> Array DataField -> R.Element ...@@ -183,6 +188,7 @@ dataFieldNav :: R.State (Maybe DataField) -> Array DataField -> R.Element
dataFieldNav (df /\ setDf) datafields = dataFieldNav (df /\ setDf) datafields =
R.fragment [ div {className: "text-primary center"} [text "with DataField"] R.fragment [ div {className: "text-primary center"} [text "with DataField"]
, div { className: "nav nav-tabs"} (liItem <$> dataFields) , div { className: "nav nav-tabs"} (liItem <$> dataFields)
, div {className:"center"} [ text $ maybe "" doc df ]
] ]
where where
liItem :: DataField -> R.Element liItem :: DataField -> R.Element
...@@ -193,12 +199,13 @@ dataFieldNav (df /\ setDf) datafields = ...@@ -193,12 +199,13 @@ dataFieldNav (df /\ setDf) datafields =
------------------------------------------------------------------------ ------------------------------------------------------------------------
databaseInput :: R.State (Maybe Database) databaseInput :: R.State (Maybe DataField)
-> R.State (Maybe Database)
-> R.State (Maybe HAL_Filters) -> R.State (Maybe HAL_Filters)
-> R.State (Maybe Org) -> R.State (Maybe Org)
-> Array Database -> Array Database
-> R.Element -> R.Element
databaseInput (db /\ setDB) (_ /\ setFilters) (_ /\ setOrg) dbs = databaseInput (df /\ setDf) (db /\ setDB) (_ /\ setFilters) (_ /\ setOrg) dbs =
div { className: "form-group" } div { className: "form-group" }
[ div {className: "text-primary center"} [text "in database"] [ div {className: "text-primary center"} [text "in database"]
, R2.select { className: "form-control" , R2.select { className: "form-control"
...@@ -208,6 +215,7 @@ databaseInput (db /\ setDB) (_ /\ setFilters) (_ /\ setOrg) dbs = ...@@ -208,6 +215,7 @@ databaseInput (db /\ setDB) (_ /\ setFilters) (_ /\ setOrg) dbs =
$ e .. "target" .. "value") $ e .. "target" .. "value")
*> (setOrg $ const Nothing) *> (setOrg $ const Nothing)
*> (setFilters $ const Nothing) *> (setFilters $ const Nothing)
*> (setDf $ const $ Just $ External db)
} }
} (liItem <$> dbs) } (liItem <$> dbs)
, div {className:"center"} [ text $ maybe "" doc db ] , div {className:"center"} [ text $ maybe "" doc db ]
......
...@@ -60,28 +60,33 @@ instance encodeJsonLang :: EncodeJson Lang where ...@@ -60,28 +60,33 @@ instance encodeJsonLang :: EncodeJson Lang where
dataFields :: Array DataField dataFields :: Array DataField
dataFields = [ Gargantext dataFields = [ Gargantext
, External Nothing
, Web , Web
, External Nothing
, Files
] ]
data DataField = Gargantext data DataField = Gargantext
| External (Maybe Database) | External (Maybe Database)
| Web | Web
| Files
instance showDataField :: Show DataField where instance showDataField :: Show DataField where
show Gargantext = "In Gargantext" show Gargantext = "In Gargantext"
show (External _) = "Ext.Database" show (External _) = "Ext.Database"
show Web = "Web" show Web = "Web"
show Files = "Files"
instance docDataField :: Doc DataField where instance docDataField :: Doc DataField where
doc Gargantext = "All Gargantext Database" doc Gargantext = "All Gargantext Database"
doc (External _) = "External (scientific) databases" doc (External _) = "External (scientific) databases"
doc Web = "All the web crawled with meta-search-engine SearX" doc Web = "All the web crawled with meta-search-engine SearX"
doc Files = "Zip files with formats.."
instance eqDataField :: Eq DataField where instance eqDataField :: Eq DataField where
eq Gargantext Gargantext = true eq Gargantext Gargantext = true
eq (External _) (External _) = true eq (External _) (External _) = true
eq Web Web = true eq Web Web = true
eq Files Files = true
eq _ _ = false eq _ _ = false
------------------------------------------------------------------------ ------------------------------------------------------------------------
......
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