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

[SEARCH FORM] filters added.

parent 7d4298be
...@@ -222,6 +222,9 @@ let additions = ...@@ -222,6 +222,9 @@ let additions =
] ]
"https://github.com/slamdata/purescript-uri" "https://github.com/slamdata/purescript-uri"
"v7.0.0" "v7.0.0"
, read = mkPackage ["purescript-prelude", "purescript-maybe", "purescript-string"]
"https://github.com/truqu/purescript-read"
"v1.0.1"
} }
in upstream // overrides // additions in upstream // overrides // additions
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
"psci-support", "psci-support",
"random", "random",
"reactix", "reactix",
"read",
"routing", "routing",
"sequences", "sequences",
"spec-discovery", "spec-discovery",
......
...@@ -11,5 +11,8 @@ loadingSpinner props = R.createElement loadingSpinnerCpt props [] ...@@ -11,5 +11,8 @@ loadingSpinner props = R.createElement loadingSpinnerCpt props []
loadingSpinnerCpt :: R.Component Props loadingSpinnerCpt :: R.Component Props
loadingSpinnerCpt = R.staticComponent "LoadingSpinner" cpt loadingSpinnerCpt = R.staticComponent "LoadingSpinner" cpt
where where
cpt _ _ = H.i {className: "fa fa-circle-o-notch fa-spin 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-spinner fa-pulse 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 ...@@ -2,8 +2,10 @@ module Gargantext.Components.Search.SearchBar
( Props, searchBar, searchBarCpt ( Props, searchBar, searchBarCpt
) where ) where
import Prelude (Unit, bind, discard, not, pure, show, ($), (<>)) import Prelude (Unit, bind, discard, not, pure, show, ($), (<>), map)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Array (nub, concat)
import Data.Set as Set
import Data.Newtype (over) import Data.Newtype (over)
import Data.Traversable (traverse_) import Data.Traversable (traverse_)
import Data.Tuple (snd) import Data.Tuple (snd)
...@@ -45,6 +47,7 @@ onSearchChange session (search /\ setSearch) = ...@@ -45,6 +47,7 @@ onSearchChange session (search /\ setSearch) =
liftEffect $ do liftEffect $ do
log2 "Searching db: " $ show q.database log2 "Searching db: " $ show q.database
log2 "Searching term: " q.term log2 "Searching term: " q.term
log2 "Searching filters: " q.filters
r <- (performSearch session $ searchQuery q) :: Aff Unit r <- (performSearch session $ searchQuery q) :: Aff Unit
...@@ -55,5 +58,10 @@ onSearchChange session (search /\ setSearch) = ...@@ -55,5 +58,10 @@ onSearchChange session (search /\ setSearch) =
searchQuery {database: Nothing, lang, term} = searchQuery {database: Nothing, lang, term} =
over SearchQuery (_ {query=term}) defaultSearchQuery over SearchQuery (_ {query=term}) defaultSearchQuery
searchQuery {database: Just db, lang, term} = searchQuery {database: Just db, lang, term, filters} =
over SearchQuery (_ {databases=[db], lang=lang, query=term}) defaultSearchQuery 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 ...@@ -98,7 +98,7 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
div {} [] div {} []
else else
div {} [] div {} []
, div { className: "panel-footer" } , div { className: "" }
[ submitButton db term lang org filters props.search ] [ submitButton 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)
...@@ -108,7 +108,7 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged ...@@ -108,7 +108,7 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
isHAL :: Maybe Database -> Boolean isHAL :: Maybe Database -> Boolean
isHAL (Just HAL) = true isHAL (Just HAL) = true
isHAL _ = false isHAL _ = false
isInFilters :: IMT_org -> Maybe HAL_Filters -> Boolean isInFilters :: IMT_org -> Maybe HAL_Filters -> Boolean
isInFilters org (Just (HAL_IMT { imtOrgs })) = Set.member org imtOrgs isInFilters org (Just (HAL_IMT { imtOrgs })) = Set.member org imtOrgs
...@@ -194,11 +194,19 @@ orgInput (org /\ setOrg) orgs = ...@@ -194,11 +194,19 @@ orgInput (org /\ setOrg) orgs =
filterInput :: R.State String -> R.Element filterInput :: R.State String -> R.Element
filterInput (term /\ setTerm) = filterInput (term /\ setTerm) =
div {className: ""} [ input { defaultValue: term div {className: ""} [ input { defaultValue: term
, className: "form-control" , className: "form-control"
, type: "text" , type: "text"
, on: { change: \e -> setTerm $ const $ e .. "target" .. "value"} , on: { change: \e -> setTerm
, placeholder : "Filter with struct_Ids as integer" } $ 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"
}
]
searchInput :: R.State String -> R.Element searchInput :: R.State String -> R.Element
...@@ -221,13 +229,13 @@ submitButton :: R.State (Maybe Database) ...@@ -221,13 +229,13 @@ submitButton :: R.State (Maybe Database)
-> R.Element -> R.Element
submitButton (database /\ _) (term /\ _) (lang /\ _) (org/\_) (filters /\ _) (_ /\ setSearch) = submitButton (database /\ _) (term /\ _) (lang /\ _) (org/\_) (filters /\ _) (_ /\ setSearch) =
R.fragment [ div { className : "" } [] R.fragment [ div { className : "" } []
, button { className: "btn btn-primary text-center" , button { className: "btn btn-primary"
, type: "button" , type: "button"
, on: {change: click} , on: {click: doSearch}
} [ text "Search" ] } [ text "Search" ]
] ]
where where
click = \_ -> do doSearch = \_ -> do
case term of case term of
"" -> setSearch $ const Nothing "" -> setSearch $ const Nothing
_ -> setSearch $ const $ Just { database, lang, filters, term, org} _ -> setSearch $ const $ Just { database, lang, filters, term, org}
...@@ -271,12 +271,13 @@ instance showSearchOrder :: Show SearchOrder where ...@@ -271,12 +271,13 @@ instance showSearchOrder :: Show SearchOrder where
newtype SearchQuery = SearchQuery newtype SearchQuery = SearchQuery
{ query :: String { query :: String
, databases :: Array Database , databases :: Array Database
, lang :: Maybe Lang , lang :: Maybe Lang
, filters :: (Array Int)
, node_id :: Maybe Int , node_id :: Maybe Int
, files_id :: Array String , files_id :: Array String
, offset :: Maybe Int , offset :: Maybe Int
, limit :: Maybe Int , limit :: Maybe Int
, order :: Maybe SearchOrder , order :: Maybe SearchOrder
} }
derive instance newtypeSearchQuery :: Newtype SearchQuery _ derive instance newtypeSearchQuery :: Newtype SearchQuery _
...@@ -287,10 +288,12 @@ defaultSearchQuery = SearchQuery ...@@ -287,10 +288,12 @@ defaultSearchQuery = SearchQuery
, databases: allDatabases , databases: allDatabases
, lang : Nothing , lang : Nothing
, node_id : Nothing , node_id : Nothing
, filters : []
, files_id : [] , files_id : []
, offset: Nothing , offset: Nothing
, limit: Nothing , limit: Nothing
, order: Nothing } , order: Nothing
}
instance toUrlSessionSearchQuery :: ToUrl Session SearchQuery where instance toUrlSessionSearchQuery :: ToUrl Session SearchQuery where
toUrl (Session {backend}) q = backendUrl backend q2 toUrl (Session {backend}) q = backendUrl backend q2
...@@ -298,18 +301,21 @@ instance toUrlSessionSearchQuery :: ToUrl Session SearchQuery where ...@@ -298,18 +301,21 @@ instance toUrlSessionSearchQuery :: ToUrl Session SearchQuery where
instance searchQueryToQuery :: ToQuery SearchQuery where instance searchQueryToQuery :: ToQuery SearchQuery where
toQuery (SearchQuery {offset, limit, order}) = toQuery (SearchQuery {offset, limit, order}) =
QP.print id id $ QP.QueryPairs $ QP.print id id $ QP.QueryPairs
pair "offset" offset <> pair "limit" limit <> pair "order" order $ 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)) where pair :: forall a. Show a => String -> Maybe a -> Array (Tuple QP.Key (Maybe QP.Value))
pair k = maybe [] $ \v -> pair k = maybe [] $ \v ->
[ QP.keyFromString k /\ Just (QP.valueFromString $ show v) ] [ QP.keyFromString k /\ Just (QP.valueFromString $ show v) ]
instance encodeJsonSearchQuery :: EncodeJson SearchQuery where instance encodeJsonSearchQuery :: EncodeJson SearchQuery where
encodeJson (SearchQuery {query, databases, node_id, files_id}) encodeJson (SearchQuery {query, databases, node_id, files_id, filters})
= "query" := query = "query" := query
~> "databases" := databases ~> "databases" := databases
~> "node_id" := fromMaybe 0 node_id ~> "node_id" := fromMaybe 0 node_id
~> "files_id" := files_id ~> "files_id" := files_id
~> "filters" := filters
~> jsonEmptyObject ~> 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