Commit 8c5aa0b4 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[SEARCH FORM] filters added.

parent 7d4298be
......@@ -222,6 +222,9 @@ let additions =
]
"https://github.com/slamdata/purescript-uri"
"v7.0.0"
, read = mkPackage ["purescript-prelude", "purescript-maybe", "purescript-string"]
"https://github.com/truqu/purescript-read"
"v1.0.1"
}
in upstream // overrides // additions
......@@ -25,6 +25,7 @@
"psci-support",
"random",
"reactix",
"read",
"routing",
"sequences",
"spec-discovery",
......
......@@ -11,5 +11,8 @@ loadingSpinner props = R.createElement loadingSpinnerCpt props []
loadingSpinnerCpt :: R.Component Props
loadingSpinnerCpt = R.staticComponent "LoadingSpinner" cpt
where
cpt _ _ = H.i {className: "fa fa-circle-o-notch fa-spin fa-3x fa-fw"} [H.text ""]
--cpt _ _ = H.i {className: "fa fa-spinner fa-pulse fa-3x fa-fw"} [H.text ""]
cpt _ _ = H.i {className: "fa fa-smile-o fa-spin fa-3x fa-fw"} [H.text ""]
-- cpt _ _ = H.i {className: "fa fa-globe fa-spin fa-3x fa-fw"} [H.text ""]
-- cpt _ _ = H.i {className: "fa fa-circle-o-notch fa-spin fa-3x fa-fw"} [H.text ""]
-- cpt _ _ = H.i {className: "fa fa-spinner fa-pulse fa-3x fa-fw"} [H.text ""]
......@@ -2,8 +2,10 @@ module Gargantext.Components.Search.SearchBar
( Props, searchBar, searchBarCpt
) where
import Prelude (Unit, bind, discard, not, pure, show, ($), (<>))
import Prelude (Unit, bind, discard, not, pure, show, ($), (<>), map)
import Data.Maybe (Maybe(..))
import Data.Array (nub, concat)
import Data.Set as Set
import Data.Newtype (over)
import Data.Traversable (traverse_)
import Data.Tuple (snd)
......@@ -45,6 +47,7 @@ onSearchChange session (search /\ setSearch) =
liftEffect $ do
log2 "Searching db: " $ show q.database
log2 "Searching term: " q.term
log2 "Searching filters: " q.filters
r <- (performSearch session $ searchQuery q) :: Aff Unit
......@@ -55,5 +58,10 @@ onSearchChange session (search /\ setSearch) =
searchQuery {database: Nothing, lang, term} =
over SearchQuery (_ {query=term}) defaultSearchQuery
searchQuery {database: Just db, lang, term} =
over SearchQuery (_ {databases=[db], lang=lang, query=term}) defaultSearchQuery
searchQuery {database: Just db, lang, term, filters} =
over SearchQuery (_ {databases=[db], lang=lang, query=term, filters=filters'}) defaultSearchQuery
where
filters' = toInt filters
toInt (Just (HAL_StructId {structIds})) = Set.toUnfoldable structIds
toInt (Just (HAL_IMT {imtOrgs, structIds})) = nub $ (concat $ map imtStructId $ Set.toUnfoldable imtOrgs) <> (Set.toUnfoldable structIds)
toInt _ = []
......@@ -98,7 +98,7 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
div {} []
else
div {} []
, div { className: "panel-footer" }
, div { className: "" }
[ submitButton db term lang org filters props.search ]
]
hasChanged p p' = (fst p.search /= fst p'.search)
......@@ -196,8 +196,16 @@ filterInput (term /\ setTerm) =
div {className: ""} [ input { defaultValue: term
, className: "form-control"
, type: "text"
, on: { change: \e -> setTerm $ const $ e .. "target" .. "value"}
, placeholder : "Filter with struct_Ids as integer" }
, on: { change: \e -> setTerm
$ const
$ e .. "target" .. "value"
}
, "required pattern": "[[0-9]+[ ]+]*"
-- TODO ^FIXME not sure about the regex comprehension: that should match "123 2334 44545" only (Integers separated by one space)
-- form validation with CSS
-- DOC: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation
, placeholder : "Filter with struct_Ids as integer"
}
]
......@@ -221,13 +229,13 @@ submitButton :: R.State (Maybe Database)
-> R.Element
submitButton (database /\ _) (term /\ _) (lang /\ _) (org/\_) (filters /\ _) (_ /\ setSearch) =
R.fragment [ div { className : "" } []
, button { className: "btn btn-primary text-center"
, button { className: "btn btn-primary"
, type: "button"
, on: {change: click}
, on: {click: doSearch}
} [ text "Search" ]
]
where
click = \_ -> do
doSearch = \_ -> do
case term of
"" -> setSearch $ const Nothing
_ -> setSearch $ const $ Just { database, lang, filters, term, org}
......@@ -272,6 +272,7 @@ newtype SearchQuery = SearchQuery
{ query :: String
, databases :: Array Database
, lang :: Maybe Lang
, filters :: (Array Int)
, node_id :: Maybe Int
, files_id :: Array String
, offset :: Maybe Int
......@@ -287,10 +288,12 @@ defaultSearchQuery = SearchQuery
, databases: allDatabases
, lang : Nothing
, node_id : Nothing
, filters : []
, files_id : []
, offset: Nothing
, limit: Nothing
, order: Nothing }
, order: Nothing
}
instance toUrlSessionSearchQuery :: ToUrl Session SearchQuery where
toUrl (Session {backend}) q = backendUrl backend q2
......@@ -298,18 +301,21 @@ instance toUrlSessionSearchQuery :: ToUrl Session SearchQuery where
instance searchQueryToQuery :: ToQuery SearchQuery where
toQuery (SearchQuery {offset, limit, order}) =
QP.print id id $ QP.QueryPairs $
pair "offset" offset <> pair "limit" limit <> pair "order" order
QP.print id id $ QP.QueryPairs
$ pair "offset" offset
<> pair "limit" limit
<> pair "order" order
where pair :: forall a. Show a => String -> Maybe a -> Array (Tuple QP.Key (Maybe QP.Value))
pair k = maybe [] $ \v ->
[ QP.keyFromString k /\ Just (QP.valueFromString $ show v) ]
instance encodeJsonSearchQuery :: EncodeJson SearchQuery where
encodeJson (SearchQuery {query, databases, node_id, files_id})
encodeJson (SearchQuery {query, databases, node_id, files_id, filters})
= "query" := query
~> "databases" := databases
~> "node_id" := fromMaybe 0 node_id
~> "files_id" := files_id
~> "filters" := filters
~> 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