Commit 9f93eb2b authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[forest] refactor node popup view

parent 1aaa37f8
...@@ -22,6 +22,7 @@ data NodeAction = Documentation NodeType ...@@ -22,6 +22,7 @@ data NodeAction = Documentation NodeType
| Move | Clone | Delete | Move | Clone | Delete
| Share | Link NodeType | Share | Link NodeType
| Add (Array NodeType) | Add (Array NodeType)
| CopyFromCorpus
instance eqNodeAction :: Eq NodeAction where instance eqNodeAction :: Eq NodeAction where
...@@ -36,6 +37,7 @@ instance eqNodeAction :: Eq NodeAction where ...@@ -36,6 +37,7 @@ instance eqNodeAction :: Eq NodeAction where
eq Share Share = true eq Share Share = true
eq (Link x) (Link y) = true && (x == y) eq (Link x) (Link y) = true && (x == y)
eq (Add x) (Add y) = true && (x == y) eq (Add x) (Add y) = true && (x == y)
eq CopyFromCorpus CopyFromCorpus = true
eq _ _ = false eq _ _ = false
instance showNodeAction :: Show NodeAction where instance showNodeAction :: Show NodeAction where
...@@ -50,6 +52,7 @@ instance showNodeAction :: Show NodeAction where ...@@ -50,6 +52,7 @@ instance showNodeAction :: Show NodeAction where
show Share = "Share" show Share = "Share"
show (Link x) = "Link to " <> show x show (Link x) = "Link to " <> show x
show (Add xs) = foldl (\a b -> a <> show b) "Add " xs show (Add xs) = foldl (\a b -> a <> show b) "Add " xs
show CopyFromCorpus = "Copy from corpus"
glyphiconNodeAction :: NodeAction -> String glyphiconNodeAction :: NodeAction -> String
...@@ -60,6 +63,7 @@ glyphiconNodeAction SearchBox = "search" ...@@ -60,6 +63,7 @@ glyphiconNodeAction SearchBox = "search"
glyphiconNodeAction Upload = "upload" glyphiconNodeAction Upload = "upload"
glyphiconNodeAction (Link _) = "transfer" glyphiconNodeAction (Link _) = "transfer"
glyphiconNodeAction Download = "download" glyphiconNodeAction Download = "download"
glyphiconNodeAction CopyFromCorpus = "random"
glyphiconNodeAction _ = "" glyphiconNodeAction _ = ""
...@@ -183,6 +187,7 @@ settingsBox NodeList = SettingsBox { ...@@ -183,6 +187,7 @@ settingsBox NodeList = SettingsBox {
, edit : false , edit : false
, doc : Documentation NodeList , doc : Documentation NodeList
, buttons : [ Upload , buttons : [ Upload
, CopyFromCorpus
, Download , Download
, Delete , Delete
] ]
......
...@@ -33,7 +33,7 @@ uploadFileView :: (Action -> Aff Unit) -> Record Props -> R.Element ...@@ -33,7 +33,7 @@ uploadFileView :: (Action -> Aff Unit) -> Record Props -> R.Element
uploadFileView d props = R.createElement (uploadFileViewCpt d) props [] uploadFileView d props = R.createElement (uploadFileViewCpt d) props []
uploadFileViewCpt :: (Action -> Aff Unit) -> R.Component Props uploadFileViewCpt :: (Action -> Aff Unit) -> R.Component Props
uploadFileViewCpt d = R.hooksComponent "UploadFileView" cpt uploadFileViewCpt d = R.hooksComponent "G.C.F.T.N.A.U.UploadFileView" cpt
where where
cpt {id, nodeType} _ = do cpt {id, nodeType} _ = do
mContents :: R.State (Maybe UploadFileContents) <- R.useState' Nothing mContents :: R.State (Maybe UploadFileContents) <- R.useState' Nothing
...@@ -234,3 +234,12 @@ uploadFile session nodeType id fileType (UploadFileContents fileContents) = do ...@@ -234,3 +234,12 @@ uploadFile session nodeType id fileType (UploadFileContents fileContents) = do
Tuple "_wf_data" (Just fileContents) Tuple "_wf_data" (Just fileContents)
, Tuple "_wf_filetype" (Just $ show fileType) , Tuple "_wf_filetype" (Just $ show fileType)
] ]
uploadTermListView :: (Action -> Aff Unit) -> Record Props -> R.Element
uploadTermListView d props = R.createElement (uploadFileViewCpt d) props []
uploadTermListViewCpt :: (Action -> Aff Unit) -> R.Component Props
uploadTermListViewCpt d = R.hooksComponent "G.C.F.T.N.A.U.UploadTermListView" cpt
where
cpt {id, nodeType} _ = do
pure $ H.div {} [ H.text "Upload term list" ]
...@@ -21,7 +21,7 @@ import Gargantext.Components.Forest.Tree.Node (NodeAction(..), SettingsBox(..), ...@@ -21,7 +21,7 @@ import Gargantext.Components.Forest.Tree.Node (NodeAction(..), SettingsBox(..),
import Gargantext.Components.Forest.Tree.Node.Action (Action(..), DroppedFile(..), FileType(..), ID, Name, UploadFileContents(..)) import Gargantext.Components.Forest.Tree.Node.Action (Action(..), DroppedFile(..), FileType(..), ID, Name, UploadFileContents(..))
import Gargantext.Components.Forest.Tree.Node.Action.Add (NodePopup(..), createNodeView) import Gargantext.Components.Forest.Tree.Node.Action.Add (NodePopup(..), createNodeView)
import Gargantext.Components.Forest.Tree.Node.Action.Rename (renameBox) import Gargantext.Components.Forest.Tree.Node.Action.Rename (renameBox)
import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadFileView, fileTypeView) import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadFileView, fileTypeView, uploadTermListView)
import Gargantext.Components.Forest.Tree.Node.ProgressBar (asyncProgressBar) import Gargantext.Components.Forest.Tree.Node.ProgressBar (asyncProgressBar)
import Gargantext.Components.Data.Lang (allLangs, Lang(EN)) import Gargantext.Components.Data.Lang (allLangs, Lang(EN))
import Gargantext.Components.Search.SearchBar (searchBar) import Gargantext.Components.Search.SearchBar (searchBar)
...@@ -104,13 +104,15 @@ nodeMainSpan d p folderOpen session frontends = R.createElement el p [] ...@@ -104,13 +104,15 @@ nodeMainSpan d p folderOpen session frontends = R.createElement el p []
mNodePopupView _ _ (Nothing /\ _) _ = H.div {} [] mNodePopupView _ _ (Nothing /\ _) _ = H.div {} []
mNodePopupView _ _ _ (Nothing /\ _) = H.div {} [] mNodePopupView _ _ _ (Nothing /\ _) = H.div {} []
mNodePopupView props@{asyncTasks, id, nodeType} true popupOpen (Just position /\ _) = mNodePopupView props@{asyncTasks, id, nodeType} true popupOpen (Just position /\ _) =
nodePopupView d { id nodePopupView { id
, action: Nothing , action: Nothing
, dispatch: d
, name: name' props , name: name' props
, nodePopupState: popupOpen
, nodeType , nodeType
, position , position
, session , session
} popupOpen }
dropProps droppedFile isDragOver = dropProps droppedFile isDragOver =
{ className: dropClass droppedFile isDragOver { className: dropClass droppedFile isDragOver
...@@ -182,7 +184,9 @@ mCorpusId _ = Nothing ...@@ -182,7 +184,9 @@ mCorpusId _ = Nothing
type NodePopupProps = type NodePopupProps =
( id :: ID ( id :: ID
, action :: Maybe NodeAction , action :: Maybe NodeAction
, dispatch :: Action -> Aff Unit
, name :: Name , name :: Name
, nodePopupState :: R.State (Maybe NodePopup)
, nodeType :: GT.NodeType , nodeType :: GT.NodeType
, position :: R2.Point , position :: R2.Point
, session :: Session , session :: Session
...@@ -194,35 +198,43 @@ iconAStyle = { color : "black" ...@@ -194,35 +198,43 @@ iconAStyle = { color : "black"
, paddingBottom : "6px" , paddingBottom : "6px"
} }
nodePopupView :: (Action -> Aff Unit) nodePopupView :: Record NodePopupProps -> R.Element
-> Record NodePopupProps nodePopupView p = R.createElement nodePopupCpt p []
-> R.State (Maybe NodePopup)
-> R.Element nodePopupCpt :: R.Component NodePopupProps
nodePopupView d p mPop@(Just NodePopup /\ setPopupOpen) = R.createElement el p [] nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt
where where
el = R.hooksComponent "NodePopupView" cpt cpt p@{nodePopupState: mPop@(Just NodePopup /\ setPopupOpen)} _ = do
cpt {id, action, name, nodeType, position, session} _ = do
renameBoxOpen <- R.useState' false renameBoxOpen <- R.useState' false
nodePopupState@(nodePopup /\ setNodePopup) <- R.useState' {id, name, nodeType, action} nodePopupState@(nodePopup /\ setNodePopup) <- R.useState' {action: p.action, id: p.id, name: p.name, nodeType: p.nodeType}
search <- R.useState' $ defaultSearch { node_id = Just id } search <- R.useState' $ defaultSearch { node_id = Just p.id }
pure $ H.div (tooltipProps position) $ pure $ H.div (tooltipProps p.position) $
[ H.div {id: "arrow"} [] [ H.div {id: "arrow"} []
, H.div { className: "popup-container" } , H.div { className: "popup-container" }
[ H.div { className: "panel panel-default" } [ H.div { className: "panel panel-default" }
[ H.div {className: ""} [ H.div {className: ""}
[ H.div { className : "col-md-11"} [ H.div { className : "col-md-11"}
[ H.h3 { className: GT.fldr nodeType true} [H.text $ show nodeType] [ H.h3 { className: GT.fldr p.nodeType true} [H.text $ show p.nodeType]
, H.p {className: "text-primary center"} [H.text name] , H.p {className: "text-primary center"} [H.text p.name]
] ]
] ]
, panelHeading renameBoxOpen , panelHeading renameBoxOpen p
, panelBody nodePopupState d , panelBody nodePopupState p
, panelAction d {id, name, nodeType, action:nodePopup.action, session, search} mPop , panelAction {
action: nodePopup.action
, dispatch: p.dispatch
, id: p.id
, name: p.name
, nodePopupState: mPop
, nodeType: p.nodeType
, search
, session: p.session
}
] ]
, if nodePopup.action == Just SearchBox then , if nodePopup.action == Just SearchBox then
H.div {} H.div {}
[ [
searchIsTexIframe id session search searchIsTexIframe p search
] ]
else else
H.div {} [] H.div {} []
...@@ -238,16 +250,7 @@ nodePopupView d p mPop@(Just NodePopup /\ setPopupOpen) = R.createElement el p [ ...@@ -238,16 +250,7 @@ nodePopupView d p mPop@(Just NodePopup /\ setPopupOpen) = R.createElement el p [
style: { top: y - 65.0, left: x + 10.0 } style: { top: y - 65.0, left: x + 10.0 }
} }
SettingsBox {edit, doc, buttons} = settingsBox nodeType panelHeading renameBoxOpen@(open /\ _) {dispatch: d, id, name, nodeType} =
removeCircleGeneral (Just _) setNodePopup = removeCircle setNodePopup
removeCircleGeneral Nothing _ = H.div {} []
removeCircle setNodePopup =
H.div { className: glyphicon "remove-circle"
, onClick : setNodePopup $ const {id, name, nodeType, action :Nothing}
} []
panelHeading renameBoxOpen@(open /\ _) =
H.div {className: "panel-heading"} H.div {className: "panel-heading"}
[ R2.row [ R2.row
[ H.div {className: "col-md-8"} [ H.div {className: "col-md-8"}
...@@ -266,6 +269,7 @@ nodePopupView d p mPop@(Just NodePopup /\ setPopupOpen) = R.createElement el p [ ...@@ -266,6 +269,7 @@ nodePopupView d p mPop@(Just NodePopup /\ setPopupOpen) = R.createElement el p [
] ]
] ]
where where
SettingsBox {edit, doc, buttons} = settingsBox nodeType
editIcon (false /\ setRenameBoxOpen) = editIcon (false /\ setRenameBoxOpen) =
H.div {className : "col-md-1"} H.div {className : "col-md-1"}
[ H.a { className: glyphicon "pencil" [ H.a { className: glyphicon "pencil"
...@@ -278,14 +282,16 @@ nodePopupView d p mPop@(Just NodePopup /\ setPopupOpen) = R.createElement el p [ ...@@ -278,14 +282,16 @@ nodePopupView d p mPop@(Just NodePopup /\ setPopupOpen) = R.createElement el p [
] ]
editIcon (true /\ _) = H.div {} [] editIcon (true /\ _) = H.div {} []
panelBody nodePopupState d' = panelBody nodePopupState {dispatch: d, nodeType} =
H.div {className: "panel-body flex-space-between"} H.div {className: "panel-body flex-space-between"}
[ H.div {className: "flex-center"} [buttonClick nodePopupState d' doc] [ H.div {className: "flex-center"} [buttonClick nodePopupState d doc]
, H.div {className: "flex-center"} , H.div {className: "flex-center"}
$ map (buttonClick nodePopupState d') buttons $ map (buttonClick nodePopupState d) buttons
] ]
where
SettingsBox {edit, doc, buttons} = settingsBox nodeType
searchIsTexIframe _id _session search@(search' /\ _) = searchIsTexIframe {nodeType} search@(search' /\ _) =
if isIsTex search'.datafield then if isIsTex search'.datafield then
H.div { className: "istex-search panel panel-default" } H.div { className: "istex-search panel panel-default" }
[ [
...@@ -307,9 +313,6 @@ nodePopupView d p mPop@(Just NodePopup /\ setPopupOpen) = R.createElement el p [ ...@@ -307,9 +313,6 @@ nodePopupView d p mPop@(Just NodePopup /\ setPopupOpen) = R.createElement el p [
Tuple (NQP.keyFromString "query") (Just (NQP.valueFromString term)) Tuple (NQP.keyFromString "query") (Just (NQP.valueFromString term))
] ]
nodePopupView _ p _ = R.createElement el p []
where
el = R.hooksComponent "CreateNodeView" cpt
cpt _ _ = pure $ H.div {} [] cpt _ _ = pure $ H.div {} []
...@@ -352,44 +355,67 @@ type Open = Boolean ...@@ -352,44 +355,67 @@ type Open = Boolean
type PanelActionProps = type PanelActionProps =
( id :: ID ( id :: ID
, action :: Maybe NodeAction , action :: Maybe NodeAction
, dispatch :: Action -> Aff Unit
, name :: Name , name :: Name
, nodePopupState :: R.State (Maybe NodePopup)
, nodeType :: GT.NodeType , nodeType :: GT.NodeType
, session :: Session , session :: Session
, search :: R.State Search , search :: R.State Search
) )
panelAction :: (Action -> Aff Unit) panelAction :: Record PanelActionProps -> R.Element
-> Record PanelActionProps panelAction p = R.createElement panelActionCpt p []
-> R.State (Maybe NodePopup)
-> R.Element panelActionCpt :: R.Component PanelActionProps
panelAction d {id, name, nodeType, action, session, search} p = case action of panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt
(Just (Documentation GT.NodeUser)) -> R.fragment [H.div {style: {margin: "10px"}} [ infoTitle GT.NodeUser where
cpt {action: Just (Documentation GT.NodeUser)} _ = do
pure $ R.fragment [
H.div {style: {margin: "10px"}} [ infoTitle GT.NodeUser
, H.p {} [ H.text "This account is personal"] , H.p {} [ H.text "This account is personal"]
, H.p {} [ H.text "See the instances terms of uses."] , H.p {} [ H.text "See the instances terms of uses."]
] ]
] ]
(Just (Documentation GT.FolderPrivate)) -> fragmentPT "This folder and its children are private only!" cpt {action: Just (Documentation GT.FolderPrivate)} _ = do
(Just (Documentation GT.FolderPublic)) -> fragmentPT "Soon, you will be able to build public folders to share your work with the world!" pure $ fragmentPT "This folder and its children are private only!"
(Just (Documentation GT.FolderShared)) -> fragmentPT "Soon, you will be able to build teams folders to share your work" cpt {action: Just (Documentation GT.FolderPublic)} _ = do
(Just (Documentation x)) -> fragmentPT $ "More information on" <> show nodeType pure $ fragmentPT "Soon, you will be able to build public folders to share your work with the world!"
cpt {action: Just (Documentation GT.FolderShared)} _ = do
(Just (Link _)) -> fragmentPT "Soon, you will be able to link the corpus with your Annuaire (and reciprocally)." pure $ fragmentPT "Soon, you will be able to build teams folders to share your work"
(Just Upload) -> uploadFileView d {id, nodeType, session} cpt {action: Just (Documentation x), nodeType} _ = do
(Just Download) -> fragmentPT "Soon, you will be able to dowload your file here" pure $ fragmentPT $ "More information on" <> show nodeType
(Just SearchBox) -> R.fragment [ H.p {"style": {"margin" :"10px"}} [ H.text $ "Search and create a private corpus with the search query as corpus name." ] cpt {action: Just (Link _)} _ = do
, searchBar {langs: allLangs, onSearch, search, session} pure $ fragmentPT "Soon, you will be able to link the corpus with your Annuaire (and reciprocally)."
cpt {action: Just Upload, dispatch: d, id, nodeType: GT.NodeList, session} _ = do
pure $ uploadTermListView d {id, nodeType: GT.NodeList, session}
cpt {action: Just Upload, dispatch: d, id, nodeType, session} _ = do
pure $ uploadFileView d {id, nodeType, session}
cpt {action: Just Download} _ = do
pure $ fragmentPT "Soon, you will be able to dowload your file here"
cpt props@{action: Just SearchBox, search, session} _ = do
pure $ R.fragment [
H.p {"style": {"margin" :"10px"}} [ H.text $ "Search and create a private corpus with the search query as corpus name." ]
, searchBar {langs: allLangs, onSearch: onSearch props, search, session}
] ]
(Just Delete) -> case nodeType of cpt {action: Just Delete, nodeType: GT.NodeUser} _ = do
GT.NodeUser -> R.fragment [ H.div {style: {margin: "10px"}} [H.text "Yes, we are RGPD compliant! But you can not delete User Node yet (we are still on development). Thanks for your comprehensin."]] pure $ R.fragment [
_ -> R.fragment [ H.div {style: {margin: "10px"}} (map (\t -> H.p {} [H.text t]) ["Are your sure you want to delete it ?", "If yes, click again below."]), reallyDelete d] H.div {style: {margin: "10px"}} [H.text "Yes, we are RGPD compliant! But you can not delete User Node yet (we are still on development). Thanks for your comprehensin."]
(Just (Add xs)) -> createNodeView d {id, name, nodeType} p xs ]
_ -> H.div {} [] cpt {action: Just Delete, dispatch: d} _ = do
where pure $ R.fragment [
H.div {style: {margin: "10px"}} (map (\t -> H.p {} [H.text t]) ["Are your sure you want to delete it ?", "If yes, click again below."])
, reallyDelete d
]
cpt {action: Just (Add xs), dispatch: d, id, name, nodePopupState: p, nodeType} _ = do
pure $ createNodeView d {id, name, nodeType} p xs
cpt _ _ = do
pure $ H.div {} []
fragmentPT text = H.div {style: {margin: "10px"}} [H.text text] fragmentPT text = H.div {style: {margin: "10px"}} [H.text text]
onSearch :: GT.AsyncTaskWithType -> Effect Unit onSearch :: Record PanelActionProps -> GT.AsyncTaskWithType -> Effect Unit
onSearch task = do onSearch {dispatch: d, nodePopupState: p} task = do
_ <- launchAff $ d (SearchQuery task) _ <- launchAff $ d (SearchQuery task)
-- close popup -- close popup
snd p $ const Nothing snd p $ const Nothing
......
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