Commit c57c60c8 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[list selection] some improvements to list selection

Also, implemented list selection on the Corpus/New screen.
parent 9ca6ad41
......@@ -14,6 +14,8 @@ import Gargantext.Components.Forest.Tree.Node.Action.Search.Frame (searchIframes
import Gargantext.Components.Forest.Tree.Node.Action.Search.Types (DataField(..), Database(..), IMT_org(..), Org(..), SearchQuery(..), allIMTorgs, allOrgs, dataFields, defaultSearchQuery, doc, performSearch, datafield2database, Search)
import Gargantext.Components.InputWithEnter (inputWithEnter)
import Gargantext.Components.Lang (Lang)
import Gargantext.Components.ListSelection as ListSelection
import Gargantext.Components.ListSelection.Types as ListSelection
import Gargantext.Config.Utils (handleRESTError)
import Gargantext.Sessions (Session)
import Gargantext.Types (FrontendError)
......@@ -51,49 +53,19 @@ searchField = R.createElement searchFieldCpt
searchFieldCpt :: R.Component Props
searchFieldCpt = here.component "searchField" cpt
where
cpt props@{ errors, onSearch, search, session } _ = do
search' <- T.useLive T.unequal search
iframeRef <- R.useRef null
let params =
[ searchInput { search } []
-- , if length s.term < 3 -- search with love : <3
-- then
-- H.div {}[]
-- else
, H.div {}
[ dataFieldNav { datafields: dataFields, search } []
, if isExternal search'.datafield
then databaseInput { databases: props.databases, search } []
else H.div {} []
, if isHAL search'.datafield
then orgInput { orgs: allOrgs, search } []
else H.div {} []
, if isIMT search'.datafield
then componentIMT { search } []
else H.div {} []
, if isCNRS search'.datafield
then componentCNRS { search } []
else H.div {} []
, if needsLang search'.datafield
then langNav { langs: props.langs, search } []
else H.div {} []
, H.div {} [ searchIframes { iframeRef, search } [] ]
]
]
let button = submitButton { errors, onSearch, search, session } []
cpt { databases, errors, langs, onSearch, search, session } _ = do
selection <- T.useBox ListSelection.MyListsFirst
pure $
H.div { className: "search-field" }
[
R.fragment params
,
button
[ searchInput { search } []
-- , if length s.term < 3 -- search with love : <3
-- then
-- H.div {}[]
-- else
, datafieldInput { databases, langs, search } []
, ListSelection.selection { selection, session } []
, submitButton { errors, onSearch, search, selection, session } []
]
--pure $ panel params button
......@@ -381,6 +353,45 @@ filterInput (term /\ setTerm) =
]
-}
type DatafieldInputProps =
( databases :: Array Database
, langs :: Array Lang
, search :: T.Box Search )
datafieldInput :: R2.Component DatafieldInputProps
datafieldInput = R.createElement datafieldInputCpt
datafieldInputCpt :: R.Component DatafieldInputProps
datafieldInputCpt = here.component "datafieldInput" cpt where
cpt { databases, langs, search } _ = do
search' <- T.useLive T.unequal search
iframeRef <- R.useRef null
pure $ H.div {}
[ dataFieldNav { datafields: dataFields, search } []
, if isExternal search'.datafield
then databaseInput { databases, search } []
else H.div {} []
, if isHAL search'.datafield
then orgInput { orgs: allOrgs, search } []
else H.div {} []
, if isIMT search'.datafield
then componentIMT { search } []
else H.div {} []
, if isCNRS search'.datafield
then componentCNRS { search } []
else H.div {} []
, if needsLang search'.datafield
then langNav { langs, search } []
else H.div {} []
, H.div {} [ searchIframes { iframeRef, search } [] ]
]
type SearchInputProps =
(
search :: T.Box Search
......@@ -426,10 +437,11 @@ searchInputCpt = here.component "searchInput" cpt
-- setSearch $ _ { term = value }
type SubmitButtonProps =
( errors :: T.Box (Array FrontendError)
, onSearch :: GT.AsyncTaskWithType -> Effect Unit
, search :: T.Box Search
, session :: Session
( errors :: T.Box (Array FrontendError)
, onSearch :: GT.AsyncTaskWithType -> Effect Unit
, search :: T.Box Search
, selection :: T.Box ListSelection.Selection
, session :: Session
)
submitButton :: R2.Component SubmitButtonProps
......@@ -437,57 +449,70 @@ submitButton = R.createElement submitButtonComponent
submitButtonComponent :: R.Component SubmitButtonProps
submitButtonComponent = here.component "submitButton" cpt
where
cpt { errors, onSearch, search, session } _ = do
cpt { errors, onSearch, search, selection, session } _ = do
search' <- T.useLive T.unequal search
selection' <- T.useLive T.unequal selection
pure $
H.button { className: "btn btn-primary"
, "type" : "button"
, on : { click: doSearch onSearch errors session search' }
, on : { click: doSearch onSearch errors session selection' search' }
, style : { width: "100%" }
}
[ H.text "Launch Search" ]
doSearch os errors s q = \_ -> do
log2 "[submitButton] searching" q
triggerSearch os errors s q
doSearch onSearch errors session selection search = \_ -> do
log2 "[submitButton] searching" search
triggerSearch { onSearch, errors, session, selection, search }
--case search.term of
-- "" -> setSearch $ const defaultSearch
-- _ -> setSearch $ const q
triggerSearch :: (GT.AsyncTaskWithType -> Effect Unit)
-> T.Box (Array FrontendError)
-> Session
-> Search
type TriggerSearch =
( errors :: T.Box (Array FrontendError)
, onSearch :: GT.AsyncTaskWithType -> Effect Unit
, search :: T.Box Search
, selection :: T.Box ListSelection.Selection
, session :: Session
)
triggerSearch :: { onSearch :: (GT.AsyncTaskWithType -> Effect Unit)
, errors :: T.Box (Array FrontendError)
, session :: Session
, selection :: ListSelection.Selection
, search :: Search }
-> Effect Unit
triggerSearch os errors s q =
triggerSearch { onSearch, errors, session, selection, search } =
launchAff_ $ do
liftEffect $ do
let here' = "[triggerSearch] Searching "
log2 (here' <> "databases: ") (show q.databases)
log2 (here' <> "datafield: ") (show q.datafield)
log2 (here' <> "term: ") q.term
log2 (here' <> "lang: ") (show q.lang)
log2 (here' <> "databases: ") (show search.databases)
log2 (here' <> "datafield: ") (show search.datafield)
log2 (here' <> "term: ") search.term
log2 (here' <> "lang: ") (show search.lang)
case q.node_id of
case search.node_id of
Nothing -> liftEffect $ log "[triggerSearch] node_id is Nothing, don't know what to do"
Just id -> do
eTask <- performSearch s id $ searchQuery q
eTask <- performSearch session id $ searchQuery selection search
handleRESTError errors eTask $ \task -> liftEffect $ do
log2 "[triggerSearch] task" task
os task
onSearch task
--liftEffect $ do
-- log2 "Return:" r
-- modalShow "addCorpus"
searchQuery :: Search -> SearchQuery
searchQuery {datafield: Nothing, term} =
over SearchQuery (_ {query=term}) defaultSearchQuery
searchQuery {databases, datafield, lang, term, node_id} =
over SearchQuery (_ { databases= databases
, datafield= datafield
, lang = lang
, query = term
, node_id = node_id
searchQuery :: ListSelection.Selection -> Search -> SearchQuery
searchQuery selection { datafield: Nothing, term } =
over SearchQuery (_ { query = term
, selection = selection }) defaultSearchQuery
searchQuery selection { databases, datafield, lang, term, node_id } =
over SearchQuery (_ { databases = databases
, datafield = datafield
, lang = lang
, node_id = node_id
, query = term
, selection = selection
}) defaultSearchQuery
......@@ -19,6 +19,7 @@ import URI.Query as Q
import Gargantext.Prelude
import Gargantext.Components.Lang (Lang)
import Gargantext.Components.ListSelection.Types as ListSelection
import Gargantext.Config.REST (RESTError)
import Gargantext.Ends (class ToUrl, backendUrl)
import Gargantext.Routes as GR
......@@ -330,21 +331,23 @@ newtype SearchQuery = SearchQuery
, node_id :: Maybe Int
, offset :: Maybe Int
, order :: Maybe SearchOrder
, selection :: ListSelection.Selection
}
derive instance Generic SearchQuery _
derive instance Newtype SearchQuery _
defaultSearchQuery :: SearchQuery
defaultSearchQuery = SearchQuery
{ query: ""
, databases: Empty
, datafield: Nothing
, files_id : []
, lang : Nothing
, limit : Nothing
, node_id : Nothing
, offset : Nothing
, order : Nothing
{ query : ""
, databases : Empty
, datafield : Nothing
, files_id : []
, lang : Nothing
, limit : Nothing
, node_id : Nothing
, offset : Nothing
, order : Nothing
, selection : ListSelection.MyListsFirst
}
instance ToUrl Session SearchQuery where
......
......@@ -60,7 +60,7 @@ idsSelectorCpt :: R.Component IdsSelectorProps
idsSelectorCpt = here.component "idsSelector" cpt where
cpt { selection, session } _ = do
pure $ H.div { className: "ids-selector" }
[ listTree { name: "", root, selection, session } ] -- $ map checkbox [1, 2, 3, 4]
[ listTree { name: "", nodeType: NodeUser, root, selection, session } ] -- $ map checkbox [1, 2, 3, 4]
where
Session { treeId: root } = session
......@@ -77,6 +77,7 @@ loadTreeChildren { root, session } = do
type ListTreeProps =
( name :: String
, nodeType :: NodeType
, root :: ID
, selection :: T.Box Selection
, session :: Session )
......@@ -85,10 +86,10 @@ listTree :: R2.Leaf ListTreeProps
listTree props = R.createElement listTreeCpt props []
listTreeCpt :: R.Component ListTreeProps
listTreeCpt = here.component "listTree" cpt where
cpt { name, root, selection, session } _ = do
cpt { name, nodeType, root, selection, session } _ = do
pure $ H.div { className: "tree" }
[ H.div { className: "root" }
[ H.i { className: fldr Corpus true } []
[ H.i { className: fldr nodeType true } []
, H.text $ "[" <> show root <> "] " <> name ]
, listTreeChildren { render: listTree
, root
......@@ -136,8 +137,16 @@ listTreeChildrenLoadedCpt = here.component "listTreeChildrenLoaded" cpt where
cpt { loaded, render, root, selection, session } _ = do
pure $ H.div { className: "children" } (element <$> loaded)
where
element (NodeSimple { id, name, nodeType: Corpus }) =
render { root: id, name, selection, session }
element (NodeSimple { id, name, nodeType: nodeType@Folder }) =
render { root: id, name, nodeType, selection, session }
element (NodeSimple { id, name, nodeType: nodeType@FolderPrivate }) =
render { root: id, name, nodeType, selection, session }
element (NodeSimple { id, name, nodeType: nodeType@FolderPublic }) =
render { root: id, name, nodeType, selection, session }
element (NodeSimple { id, name, nodeType: nodeType@FolderShared }) =
render { root: id, name, nodeType, selection, session }
element (NodeSimple { id, name, nodeType: nodeType@Corpus }) =
render { root: id, name, nodeType, selection, session }
element (NodeSimple { id, name, nodeType: NodeList}) =
renderListElement { id, name, selection }
element _ = H.div {} []
......@@ -156,12 +165,8 @@ renderListElementCpt = here.component "renderListElement" cpt where
let ids = selectedListIds selection'
R.useEffect' $ do
here.log2 "[renderListElement] ids" ids
here.log2 "[renderListElement] value" $ A.elem id ids
pure $ H.div { className: "leaf" }
[ H.input { checked: A.elem id ids
[ H.input { defaultChecked: A.elem id ids
, on: { click: click ids }
, type: "checkbox" }
, H.i { className: fldr NodeList true } []
......
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