Commit 10f470b7 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Tree] async query fixes

parent 212708d7
...@@ -152,7 +152,7 @@ performAction session (_ /\ setReload) (s@{tree: NTree (LNode {id}) _} /\ setTre ...@@ -152,7 +152,7 @@ performAction session (_ /\ setReload) (s@{tree: NTree (LNode {id}) _} /\ setTre
performAction session _ ({tree: NTree (LNode {id}) _} /\ setTree) (SearchQuery task) = do performAction session _ ({tree: NTree (LNode {id}) _} /\ setTree) (SearchQuery task) = do
liftEffect $ setTree $ \t@{asyncTasks} -> t { asyncTasks = A.cons task asyncTasks } liftEffect $ setTree $ \t@{asyncTasks} -> t { asyncTasks = A.cons task asyncTasks }
liftEffect $ log2 "search query, task:" task liftEffect $ log2 "[performAction] SearchQuery task:" task
performAction session _ ({tree: NTree (LNode {id}) _} /\ setTree) (Submit name) = do performAction session _ ({tree: NTree (LNode {id}) _} /\ setTree) (Submit name) = do
void $ renameNode session id $ RenameValue {name} void $ renameNode session id $ RenameValue {name}
......
...@@ -29,23 +29,26 @@ select :: forall props. ...@@ -29,23 +29,26 @@ select :: forall props.
-> R.Element -> R.Element
select = R.createElement "select" select = R.createElement "select"
type Search = { datafield :: Maybe DataField type Search = { databases :: Array Database
, term :: String , datafield :: Maybe DataField
, lang :: Maybe Lang , lang :: Maybe Lang
, node_id :: Maybe Int , node_id :: Maybe Int
, term :: String
} }
eqSearch :: Search -> Search -> Boolean eqSearch :: Search -> Search -> Boolean
eqSearch s s' = (s.datafield == s'.datafield) eqSearch s s' = (s.databases == s'.databases)
&& (s.datafield == s'.datafield)
&& (s.term == s'.term) && (s.term == s'.term)
&& (s.lang == s'.lang) && (s.lang == s'.lang)
&& (s.node_id == s'.node_id) && (s.node_id == s'.node_id)
defaultSearch :: Search defaultSearch :: Search
defaultSearch = { datafield: Nothing defaultSearch = { databases: []
, term: "" , datafield: Nothing
, lang: Nothing
, node_id: Nothing , node_id: Nothing
, lang: Nothing
, term: ""
} }
type Props = type Props =
...@@ -368,7 +371,8 @@ searchQuery :: Search -> SearchQuery ...@@ -368,7 +371,8 @@ searchQuery :: Search -> SearchQuery
searchQuery {datafield: Nothing, term} = searchQuery {datafield: Nothing, term} =
over SearchQuery (_ {query=term}) defaultSearchQuery over SearchQuery (_ {query=term}) defaultSearchQuery
searchQuery {databases, datafield, lang, term, node_id} = searchQuery {databases, datafield, lang, term, node_id} =
over SearchQuery (_ { datafield=datafield over SearchQuery (_ { databases=databases
, datafield=datafield
, lang=lang , lang=lang
, query=term , query=term
, node_id=node_id , node_id=node_id
......
...@@ -304,14 +304,16 @@ instance showSearchOrder :: Show SearchOrder where ...@@ -304,14 +304,16 @@ instance showSearchOrder :: Show SearchOrder where
show ScoreDesc = "ScoreDesc" show ScoreDesc = "ScoreDesc"
------------------------------------------------------------------------ ------------------------------------------------------------------------
newtype SearchQuery = SearchQuery newtype SearchQuery = SearchQuery
{ query :: String { query :: String
, databases :: Array Database
, datafield :: Maybe DataField , datafield :: Maybe DataField
, files_id :: Array String
, lang :: Maybe Lang , lang :: Maybe Lang
, limit :: Maybe Int
, node_id :: Maybe Int , node_id :: Maybe Int
, files_id :: Array String
, offset :: Maybe Int , offset :: Maybe Int
, limit :: Maybe Int
, order :: Maybe SearchOrder , order :: Maybe SearchOrder
} }
...@@ -320,12 +322,13 @@ derive instance newtypeSearchQuery :: Newtype SearchQuery _ ...@@ -320,12 +322,13 @@ derive instance newtypeSearchQuery :: Newtype SearchQuery _
defaultSearchQuery :: SearchQuery defaultSearchQuery :: SearchQuery
defaultSearchQuery = SearchQuery defaultSearchQuery = SearchQuery
{ query: "" { query: ""
, databases: []
, datafield: Nothing , datafield: Nothing
, files_id : []
, lang : Nothing , lang : Nothing
, limit: Nothing
, node_id : Nothing , node_id : Nothing
, files_id : []
, offset: Nothing , offset: Nothing
, limit: Nothing
, order: Nothing , order: Nothing
} }
...@@ -344,12 +347,13 @@ instance searchQueryToQuery :: GT.ToQuery SearchQuery where ...@@ -344,12 +347,13 @@ instance searchQueryToQuery :: GT.ToQuery SearchQuery where
[ 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, datafield, node_id, lang}) encodeJson (SearchQuery {query, databases, datafield, node_id, lang})
= "query" := query = "query" := query
~> "datafield" := "" -- fromMaybe "" datafield -- ~> "datafield" := "" -- fromMaybe "" datafield
~> "databases" := databases
~> "lang" := maybe "EN" show lang
~> "node_id" := fromMaybe 0 node_id ~> "node_id" := fromMaybe 0 node_id
-- ~> "files_id" := files_id -- ~> "files_id" := files_id
~> "lang" := maybe "EN" show lang
~> jsonEmptyObject ~> jsonEmptyObject
performSearch :: Session -> Int -> SearchQuery -> Aff GT.AsyncTaskWithType performSearch :: Session -> Int -> SearchQuery -> Aff GT.AsyncTaskWithType
......
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