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
performAction session _ ({tree: NTree (LNode {id}) _} /\ setTree) (SearchQuery task) = do
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
void $ renameNode session id $ RenameValue {name}
......
......@@ -29,23 +29,26 @@ select :: forall props.
-> R.Element
select = R.createElement "select"
type Search = { datafield :: Maybe DataField
, term :: String
type Search = { databases :: Array Database
, datafield :: Maybe DataField
, lang :: Maybe Lang
, node_id :: Maybe Int
, term :: String
}
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.lang == s'.lang)
&& (s.node_id == s'.node_id)
defaultSearch :: Search
defaultSearch = { datafield: Nothing
, term: ""
, lang: Nothing
defaultSearch = { databases: []
, datafield: Nothing
, node_id: Nothing
, lang: Nothing
, term: ""
}
type Props =
......@@ -368,7 +371,8 @@ searchQuery :: Search -> SearchQuery
searchQuery {datafield: Nothing, term} =
over SearchQuery (_ {query=term}) defaultSearchQuery
searchQuery {databases, datafield, lang, term, node_id} =
over SearchQuery (_ { datafield=datafield
over SearchQuery (_ { databases=databases
, datafield=datafield
, lang=lang
, query=term
, node_id=node_id
......
......@@ -304,14 +304,16 @@ instance showSearchOrder :: Show SearchOrder where
show ScoreDesc = "ScoreDesc"
------------------------------------------------------------------------
newtype SearchQuery = SearchQuery
{ query :: String
, databases :: Array Database
, datafield :: Maybe DataField
, files_id :: Array String
, lang :: Maybe Lang
, limit :: Maybe Int
, node_id :: Maybe Int
, files_id :: Array String
, offset :: Maybe Int
, limit :: Maybe Int
, order :: Maybe SearchOrder
}
......@@ -320,12 +322,13 @@ derive instance newtypeSearchQuery :: Newtype SearchQuery _
defaultSearchQuery :: SearchQuery
defaultSearchQuery = SearchQuery
{ query: ""
, databases: []
, datafield: Nothing
, files_id : []
, lang : Nothing
, limit: Nothing
, node_id : Nothing
, files_id : []
, offset: Nothing
, limit: Nothing
, order: Nothing
}
......@@ -344,12 +347,13 @@ instance searchQueryToQuery :: GT.ToQuery SearchQuery where
[ QP.keyFromString k /\ Just (QP.valueFromString $ show v) ]
instance encodeJsonSearchQuery :: EncodeJson SearchQuery where
encodeJson (SearchQuery {query, datafield, node_id, lang})
encodeJson (SearchQuery {query, databases, datafield, node_id, lang})
= "query" := query
~> "datafield" := "" -- fromMaybe "" datafield
-- ~> "datafield" := "" -- fromMaybe "" datafield
~> "databases" := databases
~> "lang" := maybe "EN" show lang
~> "node_id" := fromMaybe 0 node_id
-- ~> "files_id" := files_id
~> "lang" := maybe "EN" show lang
~> jsonEmptyObject
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