Commit 6000141a authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FEAT][FOREST] create corpus / edit / color according to rights.

parent bde5be08
......@@ -54,8 +54,6 @@ treeLoadView reload p = R.createElement el p []
useLoader root (loadNode session) $ \loaded ->
loadedTreeView reload {tree: loaded, mCurrentRoute, session, frontends}
----------------
type TreeViewProps = ( tree :: FTree
, mCurrentRoute :: Maybe AppRoute
, frontends :: Frontends
......
......@@ -22,17 +22,12 @@ filterWithRights (show action if user can only)
data SettingsBox =
SettingsBox { show :: Boolean
, edit :: Boolean
, add :: Array NodeType
, buttons :: Array NodeAction
}
settingsBox :: NodeType -> SettingsBox
settingsBox NodeUser = SettingsBox { show : true
, edit : false
, add : [ FolderPrivate
, FolderShared
, FolderPublic
]
, buttons : [Documentation NodeUser
, Add [ FolderPrivate
, FolderShared
......@@ -44,44 +39,48 @@ settingsBox NodeUser = SettingsBox { show : true
settingsBox FolderPrivate = SettingsBox { show: true
, edit : false
, add : [ Folder
, Corpus
]
, buttons : [Documentation FolderPrivate, Delete]
, buttons : [Documentation FolderPrivate
, Add [ Corpus
, Folder
]
, Delete]
}
settingsBox FolderShared = SettingsBox { show: true
, edit : false
, add : [ Folder
, Corpus
]
, buttons : [Documentation FolderShared, Delete]
, buttons : [Documentation FolderShared
, Add [ Corpus
, Folder
]
, Delete]
}
settingsBox FolderPublic = SettingsBox { show: true
, edit : false
, add : [ Folder
, Corpus
]
, buttons : [Documentation FolderPublic, Delete]
, buttons : [Documentation FolderPublic
, Add [ Corpus
, Folder
]
, Delete
]
}
settingsBox Folder = SettingsBox { show : true
, edit : true
, add : [ Folder
, Corpus
]
, buttons : [Documentation Folder, Delete]
, buttons : [ Documentation Folder
, Add [ Corpus
, Folder
]
, Delete]
}
settingsBox Corpus = SettingsBox { show : true
, edit : true
, add : [ NodeList
, Dashboard
, Graph
, Phylo
]
, buttons : [ Documentation Corpus
, Add [ NodeList
, Graph
, Dashboard
]
, Search
, Upload
, Download
......@@ -94,7 +93,6 @@ settingsBox Corpus = SettingsBox { show : true
settingsBox Texts = SettingsBox { show : true
, edit : false
, add : []
, buttons : [ Documentation Texts
, Upload
, Download
......@@ -103,7 +101,6 @@ settingsBox Texts = SettingsBox { show : true
settingsBox Graph = SettingsBox { show : true
, edit : false
, add : [Graph]
, buttons : [ Documentation Graph
, Download
]
......@@ -111,7 +108,6 @@ settingsBox Graph = SettingsBox { show : true
settingsBox NodeList = SettingsBox { show : true
, edit : false
, add : [NodeList]
, buttons : [ Documentation NodeList
, Upload
, Download
......@@ -120,17 +116,13 @@ settingsBox NodeList = SettingsBox { show : true
settingsBox Dashboard = SettingsBox { show : true
, edit : false
, add : []
, buttons : [ Documentation Dashboard
]
}
settingsBox _ = SettingsBox { show : false
, edit : false
, add : []
, buttons : []
}
......@@ -143,6 +135,7 @@ data NodeAction = Documentation NodeType
| Share
| Add (Array NodeType)
instance eqNodeAction :: Eq NodeAction where
eq (Documentation x) (Documentation y) = true && (x == y)
eq Search Search = true
......@@ -156,29 +149,4 @@ instance eqNodeAction :: Eq NodeAction where
eq (Add x) (Add y) = true && (x == y)
eq _ _ = false
data ButtonType = Click | Pop
instance eqButtonType :: Eq ButtonType where
eq Click Click = true
eq Pop Pop = true
eq _ _ = false
buttonType :: NodeAction -> ButtonType
buttonType Search = Pop
buttonType _ = Click
data Buttons = Buttons { click :: Array NodeAction
, pop :: Array NodeAction
}
{-
buttons nt = Buttons {click, pop}
where
click = init
pop = rest
{init, rest} = span buttonType (nodeActions nt)
-}
---------------------------------------------------------
......@@ -2,7 +2,7 @@ module Gargantext.Components.Forest.Tree.Node.Action.Add where
import DOM.Simple.Console (log2)
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.:), (:=), (~>))
import Data.Array (filter, null, length, head)
import Data.Array (filter, null, length, head, elem)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Data.Generic.Rep.Show (genericShow)
......@@ -48,42 +48,19 @@ type CreateNodeProps =
createNodeView :: (Action -> Aff Unit)
-> Record CreateNodeProps
-> R.State (Maybe NodePopup)
-> Array NodeType
-> R.Element
createNodeView d p@{nodeType} (Just CreatePopup /\ setPopupOpen) = R.createElement el p []
createNodeView d p@{nodeType} (_ /\ setPopupOpen) nodeTypes = R.createElement el p []
where
el = R.hooksComponent "CreateNodeView" cpt
cpt {id, name} _ = do
nodeName <- R.useState' ""
nodeType <- R.useState' $ fromMaybe NodeUser $ head nodeTypes
pure $ H.div tooltipProps $
[ H.div {className: "panel panel-default"}
[ panelHeading
, panelBody readNodeType nodeName nodeType
pure $ H.div {}
[ panelBody readNodeType nodeName nodeType
, panelFooter nodeName nodeType
]
]
where
SettingsBox {add:nodeTypes} = settingsBox nodeType
tooltipProps = { className: ""
, id: "create-node-tooltip"
, title: "Add new node"
, data: {toggle: "tooltip", placement: "right"}
}
panelHeading =
H.div {className: "panel-heading"}
[ H.div {className: "row"}
[ H.div {className: "col-md-10"}
[ H.h5 {} [H.text "Add"] ]
, H.div {className: "col-md-2"}
[ H.a { className: "btn glyphitem glyphicon glyphicon-remove-circle"
, onClick: mkEffectFn1 $ \_ -> setPopupOpen $ const Nothing
, title: "Close"} []
]
]
]
panelBody :: (String -> NodeType)
-> R.State String
-> R.State NodeType
......@@ -92,37 +69,49 @@ createNodeView d p@{nodeType} (Just CreatePopup /\ setPopupOpen) = R.createEleme
H.div {className: "panel-body"}
[ H.div {className: "row"}
[ H.div {className: "col-md-10"}
[ H.form {className: "form-horizontal"}
[ {- H.div {className: "form-group"}
[ H.input { type: "text"
, placeholder: "Node name"
, defaultValue: name
, className: "form-control"
, onInput: mkEffectFn1 $ \e -> setNodeName $ const $ e .. "target" .. "value"
}
]
, -}
if length nodeTypes > 1
then
R.fragment [H.div {className: "form-group"} $ [ R2.select { className: "form-control"
, onChange: mkEffectFn1 $ \e -> setNodeType
$ const
$ readIt
$ e .. "target" .. "value"
}
(map (\opt -> H.option {} [ H.text $ show opt ]) nodeTypes)
]
, showConfig nt
]
else
H.button { className : "btn btn-success"
, type : "button"
, onClick : mkEffectFn1 $ \_ -> setNodeType (const $ fromMaybe nt $ head nodeTypes)
} [showConfig nt]
]
[ H.form {className: "form-horizontal"} $ maybeChoose <> maybeEdit ]
]
]
]
where
SettingsBox {edit} = settingsBox nt
maybeEdit = [ if edit
then
H.div {className: "form-group"}
[ H.input { type: "text"
, placeholder: "Node name"
, defaultValue: "Chose name"
, className: "form-control"
, onInput: mkEffectFn1 $ \e -> setNodeName
$ const
$ e .. "target" .. "value"
}
]
else
H.div {} []
]
maybeChoose = [ if length nodeTypes > 1
then
R.fragment [H.div {className: "form-group"} $ [ R2.select { className: "form-control"
, onChange: mkEffectFn1 $ \e -> setNodeType
$ const
$ readIt
$ e .. "target" .. "value"
}
(map (\opt -> H.option {} [ H.text $ show opt ]) nodeTypes)
]
-- , showConfig nt
]
else
H.button { className : "btn btn-success"
, type : "button"
, onClick : mkEffectFn1 $ \_ -> setNodeType ( const
$ fromMaybe nt
$ head nodeTypes
)
} []
]
panelFooter :: R.State String -> R.State NodeType -> R.Element
......@@ -132,11 +121,11 @@ createNodeView d p@{nodeType} (Just CreatePopup /\ setPopupOpen) = R.createEleme
, type: "button"
, onClick: mkEffectFn1 $ \_ -> do
setPopupOpen $ const Nothing
launchAff $ d $ CreateSubmit name' nt
launchAff $ d $ CreateSubmit name' nt
} [H.text "Add"]
]
createNodeView _ _ _ = R.createElement el {} []
createNodeView _ _ _ _ = R.createElement el {} []
where
el = R.hooksComponent "CreateNodeView" cpt
cpt props _ = pure $ H.div {} []
......@@ -148,6 +137,6 @@ showConfig NodeUser = H.div {} []
showConfig FolderPrivate = H.div {} [H.text "This folder will be private only"]
showConfig FolderShared = H.div {} [H.text "This folder will be shared"]
showConfig FolderPublic = H.div {} [H.text "This folder will be public"]
showConfig nt = H.div {} [H.h1 {} [H.text $ "Config of " <> show nt ]]
showConfig nt = H.div {} [H.h4 {} [H.text $ "Config of " <> show nt ]]
......@@ -54,7 +54,7 @@ nodeMainSpan d p folderOpen session frontends = R.createElement el p []
isDragOver <- R.useState' false
pure $ H.span (dropProps droppedFile isDragOver) $
[ folderIcon folderOpen
[ folderIcon nodeType folderOpen
, H.a { href: (url frontends (NodePath (sessionId session) nodeType (Just id)))
, style: {marginLeft: "22px"}
}
......@@ -68,20 +68,16 @@ nodeMainSpan d p folderOpen session frontends = R.createElement el p []
, action: Nothing
} popupOpen
else H.div {} []
--, addButton popupOpen
, fileTypeView d {id, nodeType} droppedFile isDragOver
]
where
name' = if nodeType == NodeUser then show session else name
SettingsBox {show:showBox, add} = settingsBox nodeType
addButton p = if null add
then H.div {} []
else createNodeView d {id, name, nodeType} p
SettingsBox {show:showBox} = settingsBox nodeType
folderIcon folderOpen'@(open /\ _) =
folderIcon nodeType folderOpen'@(open /\ _) =
H.a {onClick: R2.effToggler folderOpen'}
[ H.i {className: fldr open} [] ]
[ H.i {className: fldr nodeType open} [] ]
popOverIcon (popOver /\ setPopOver) =
H.a { className: "glyphicon glyphicon-cog"
......@@ -126,10 +122,14 @@ nodeMainSpan d p folderOpen session frontends = R.createElement el p []
onDragLeave (_ /\ setIsDragOver) _ = setIsDragOver $ const false
fldr :: Boolean -> String
fldr open = if open
then "glyphicon glyphicon-folder-open"
else "glyphicon glyphicon-folder-close"
fldr :: NodeType -> Boolean -> String
fldr nt open = if open
then "glyphicon glyphicon-folder-open" <> color nt
else "glyphicon glyphicon-folder-close" <> color nt
where
color FolderPublic = " text-danger"
color FolderShared = " text-warning"
color _ = ""
-- START node text
......@@ -170,7 +170,7 @@ nodePopupView :: (Action -> Aff Unit)
-> Record NodePopupProps
-> R.State (Maybe NodePopup)
-> R.Element
nodePopupView d p (Just NodePopup /\ setPopupOpen) = R.createElement el p []
nodePopupView d p mPop@(Just NodePopup /\ setPopupOpen) = R.createElement el p []
where
el = R.hooksComponent "NodePopupView" cpt
cpt {id, name, nodeType, action} _ = do
......@@ -190,7 +190,7 @@ nodePopupView d p (Just NodePopup /\ setPopupOpen) = R.createElement el p []
, onClick : setNodePopup $ const {id,name,nodeType,action :Nothing}
} []
else H.div {} []
, panelAction nodeType nodePopup.action d
, panelAction d {id,name,nodeType,action:nodePopup.action} mPop
]
]
where
......@@ -201,7 +201,7 @@ nodePopupView d p (Just NodePopup /\ setPopupOpen) = R.createElement el p []
, placement: "right"}
}
SettingsBox {edit, add, buttons} = settingsBox nodeType
SettingsBox {edit, buttons} = settingsBox nodeType
panelHeading renameBoxOpen@(open /\ _) =
H.div {className: "panel-heading"}
......@@ -248,9 +248,8 @@ nodePopupView _ p _ = R.createElement el p []
cpt _ _ = pure $ H.div {} []
-- buttonAction :: NodeAction -> R.Element
buttonClick ({id,name,nodeType,action} /\ setNodePopup) _ todo@(Documentation x) = H.div {className: "col-md-1"}
buttonClick ({id,name,nodeType,action} /\ setNodePopup) _ todo@(Documentation x) = H.div {className: "col-md-2"}
[ H.a { style: iconAStyle
, className: "btn glyphitem glyphicon glyphicon-question-sign" <> if action == (Just todo) then " active" else ""
, id: "doc"
......@@ -260,7 +259,7 @@ buttonClick ({id,name,nodeType,action} /\ setNodePopup) _ todo@(Documentation x)
[]
]
buttonClick ({id,name,nodeType,action} /\ setNodePopup) d Delete = H.div {className: "col-md-1"}
buttonClick ({id,name,nodeType,action} /\ setNodePopup) d Delete = H.div {className: "col-md-2"}
[ H.a { style: iconAStyle
, className: "btn glyphitem glyphicon glyphicon-trash" <> if action == (Just Delete) then " active" else ""
--, className: (glyphicon "trash")
......@@ -272,13 +271,13 @@ buttonClick ({id,name,nodeType,action} /\ setNodePopup) d Delete = H.div {classN
[]
]
buttonClick ({id,name,nodeType,action} /\ setNodePopup) d (Add xs) = H.div {className: "col-md-1"}
buttonClick (node@{action} /\ setNodePopup) d (Add xs) = H.div {className: "col-md-2"}
[ H.a { style: iconAStyle
, className: "btn glyphitem glyphicon glyphicon-plus" <> if action == (Just $ Add xs) then " active" else ""
--, className: (glyphicon "trash")
, id: "add"
, title: "add"
, onClick: mkEffectFn1 $ \_ -> setNodePopup $ const {id, name, nodeType, action : Just $ Add xs}
, onClick: mkEffectFn1 $ \_ -> setNodePopup $ const $ node { action = Just $ Add xs}
--, onClick: mkEffectFn1 $ \_ -> launchAff $ d $ DeleteNode}
}
[]
......@@ -317,8 +316,35 @@ buttonPop f = H.div {className: "col-md-4"}
-- END Popup View
panelAction _ (Just (Documentation x)) _ = R.fragment [ H.div {} [H.text "more information"]]
panelAction NodeUser (Just Delete) _ = R.fragment [ H.div {} [H.text "Yes, we are RGPD compliant!"]]
panelAction _ (Just Delete) _ = R.fragment [ H.div {} [H.text "Are your sure you want to delete ?"]]
panelAction _ (Just (Add xs)) _ = R.fragment [ H.div {} [H.text "Adding configuration"]]
panelAction _ _ _ = H.div {} []
type NodeProps =
( id :: ID
, name :: Name
, nodeType :: NodeType
)
type Open = Boolean
panelAction :: (Action -> Aff Unit)
-> Record NodePopupProps
-> R.State (Maybe NodePopup)
-> R.Element
panelAction d {id,name,nodeType,action} p = case action of
(Just (Documentation x)) -> R.fragment [ H.div {} [H.text $ "More information on" <> show nodeType]]
(Just Delete) -> case nodeType of
NodeUser -> R.fragment [ H.div {} [H.text "Yes, we are RGPD compliant! But you can not delete User Node yet (we are still on development). Thanks for your comprehensin."]]
_ -> R.fragment [ H.div {} [H.text "Are your sure you want to delete, if yes, click again ?"], reallyDelete d]
(Just (Add xs)) -> createNodeView d {id, name, nodeType} p xs
--R.fragment [ H.div {} [H.text "Adding configuration"]]
_ -> H.div {} []
reallyDelete d = H.div {className: "panel-footer"}
[ H.a { type: "button"
, className: "btn glyphicon glyphicon-trash"
, id: "delete"
, title: "Delete"
, onClick: mkEffectFn1 $ \_ -> launchAff $ d $ DeleteNode}
[H.text "Yes, delete!"]
]
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