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