Commit c33ac2ee authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FEAT PUBLIC] API ok (needs some fixes) WIP

parent 3f66f5fa
...@@ -282,14 +282,14 @@ performAction (ShareTeam username) p@{ reload: (_ /\ setReload) ...@@ -282,14 +282,14 @@ performAction (ShareTeam username) p@{ reload: (_ /\ setReload)
, tree: (NTree (LNode {id}) _) , tree: (NTree (LNode {id}) _)
} = } =
do do
void $ Share.share session id $ Share.ShareTeam {username} void $ Share.shareReq session id $ Share.ShareTeamParams {username}
performAction SharePublic p@{ reload: (_ /\ setReload) performAction (SharePublic {params}) p@{session} =
, session case params of
, tree: (NTree (LNode {id}) _) Nothing -> performAction NoAction p
} = Just (SubTreeOut {in:inId,out}) -> do
do void $ Share.shareReq session inId $ Share.SharePublicParams {node_id:out}
void $ Share.share session id $ Share.SharePublic {rights:"public"} performAction RefreshTree p
------- -------
performAction (AddNode name nodeType) p@{ openNodes: (_ /\ setOpenNodes) performAction (AddNode name nodeType) p@{ openNodes: (_ /\ setOpenNodes)
......
...@@ -23,30 +23,32 @@ data Action = AddNode String GT.NodeType ...@@ -23,30 +23,32 @@ data Action = AddNode String GT.NodeType
| DeleteNode GT.NodeType | DeleteNode GT.NodeType
| RenameNode String | RenameNode String
| UpdateNode UpdateNodeParams | UpdateNode UpdateNodeParams
| ShareTeam String
| SharePublic
| DoSearch GT.AsyncTaskWithType | DoSearch GT.AsyncTaskWithType
| UploadFile GT.NodeType FileType (Maybe String) UploadFileContents | UploadFile GT.NodeType FileType (Maybe String) UploadFileContents
| DownloadNode | DownloadNode
| RefreshTree | RefreshTree
| MoveNode {params :: Maybe SubTreeOut} | ShareTeam String
| MergeNode {params :: Maybe SubTreeOut} | SharePublic {params :: Maybe SubTreeOut}
| LinkNode {params :: Maybe SubTreeOut} | MoveNode {params :: Maybe SubTreeOut}
| MergeNode {params :: Maybe SubTreeOut}
| LinkNode {params :: Maybe SubTreeOut}
| NoAction | NoAction
subTreeOut :: Action -> Maybe SubTreeOut subTreeOut :: Action -> Maybe SubTreeOut
subTreeOut (MoveNode {params}) = params subTreeOut (MoveNode {params}) = params
subTreeOut (MergeNode {params}) = params subTreeOut (MergeNode {params}) = params
subTreeOut (LinkNode {params}) = params subTreeOut (LinkNode {params}) = params
subTreeOut (SharePublic {params}) = params
subTreeOut _ = Nothing subTreeOut _ = Nothing
setTreeOut :: Action -> Maybe SubTreeOut -> Action setTreeOut :: Action -> Maybe SubTreeOut -> Action
setTreeOut (MoveNode {params:_}) p = MoveNode {params: p} setTreeOut (MoveNode {params:_}) p = MoveNode {params: p}
setTreeOut (MergeNode {params:_}) p = MergeNode {params: p} setTreeOut (MergeNode {params:_}) p = MergeNode {params: p}
setTreeOut (LinkNode {params:_}) p = LinkNode {params: p} setTreeOut (LinkNode {params:_}) p = LinkNode {params: p}
setTreeOut (SharePublic {params:_}) p = SharePublic {params: p}
setTreeOut a _ = a setTreeOut a _ = a
...@@ -56,7 +58,7 @@ instance showShow :: Show Action where ...@@ -56,7 +58,7 @@ instance showShow :: Show Action where
show (RenameNode _ )= "RenameNode" show (RenameNode _ )= "RenameNode"
show (UpdateNode _ )= "UpdateNode" show (UpdateNode _ )= "UpdateNode"
show (ShareTeam _ )= "ShareTeam" show (ShareTeam _ )= "ShareTeam"
show (SharePublic )= "SharePublic" show (SharePublic _ )= "SharePublic"
show (DoSearch _ )= "SearchQuery" show (DoSearch _ )= "SearchQuery"
show (UploadFile _ _ _ _)= "UploadFile" show (UploadFile _ _ _ _)= "UploadFile"
show RefreshTree = "RefreshTree" show RefreshTree = "RefreshTree"
...@@ -73,7 +75,7 @@ icon (DeleteNode _) = glyphiconNodeAction Delete ...@@ -73,7 +75,7 @@ icon (DeleteNode _) = glyphiconNodeAction Delete
icon (RenameNode _) = glyphiconNodeAction Config icon (RenameNode _) = glyphiconNodeAction Config
icon (UpdateNode _) = glyphiconNodeAction Refresh icon (UpdateNode _) = glyphiconNodeAction Refresh
icon (ShareTeam _) = glyphiconNodeAction Share icon (ShareTeam _) = glyphiconNodeAction Share
icon (SharePublic ) = glyphiconNodeAction Publish icon (SharePublic _ ) = glyphiconNodeAction (Publish { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (DoSearch _) = glyphiconNodeAction SearchBox icon (DoSearch _) = glyphiconNodeAction SearchBox
icon (UploadFile _ _ _ _) = glyphiconNodeAction Upload icon (UploadFile _ _ _ _) = glyphiconNodeAction Upload
icon RefreshTree = glyphiconNodeAction Refresh icon RefreshTree = glyphiconNodeAction Refresh
...@@ -92,7 +94,7 @@ text (DeleteNode _ )= "Delete !" ...@@ -92,7 +94,7 @@ text (DeleteNode _ )= "Delete !"
text (RenameNode _ )= "Rename !" text (RenameNode _ )= "Rename !"
text (UpdateNode _ )= "Update !" text (UpdateNode _ )= "Update !"
text (ShareTeam _ )= "Share with team !" text (ShareTeam _ )= "Share with team !"
text (SharePublic )= "Publish !" text (SharePublic _ )= "Publish !"
text (DoSearch _ )= "Launch search !" text (DoSearch _ )= "Launch search !"
text (UploadFile _ _ _ _)= "Upload File !" text (UploadFile _ _ _ _)= "Upload File !"
text RefreshTree = "Refresh Tree !" text RefreshTree = "Refresh Tree !"
......
...@@ -17,6 +17,7 @@ import Reactix.DOM.HTML as H ...@@ -17,6 +17,7 @@ import Reactix.DOM.HTML as H
deleteNode :: Session -> NodeType -> GT.ID -> Aff GT.ID deleteNode :: Session -> NodeType -> GT.ID -> Aff GT.ID
deleteNode session nt nodeId = deleteNode session nt nodeId =
case nt of case nt of
NodePublic FolderPublic -> delete session $ NodeAPI GT.Node (Just nodeId) ""
NodePublic _ -> put_ session $ NodeAPI GT.Node (Just nodeId) "unpublish" NodePublic _ -> put_ session $ NodeAPI GT.Node (Just nodeId) "unpublish"
_ -> delete session $ NodeAPI GT.Node (Just nodeId) "" _ -> delete session $ NodeAPI GT.Node (Just nodeId) ""
......
...@@ -13,6 +13,19 @@ import Gargantext.Routes as GR ...@@ -13,6 +13,19 @@ import Gargantext.Routes as GR
import Gargantext.Sessions (Session, post) import Gargantext.Sessions (Session, post)
import Gargantext.Components.Forest.Tree.Node.Tools as Tools import Gargantext.Components.Forest.Tree.Node.Tools as Tools
import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
import Gargantext.Components.Forest.Tree.Node.Action (Action)
import Gargantext.Components.Forest.Tree.Node.Action as Action
import Gargantext.Components.Forest.Tree.Node.Tools (submitButton, panel)
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (subTreeView, SubTreeParamsIn)
import Gargantext.Prelude
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, put_)
import Gargantext.Types as GT
import Reactix as R
import Reactix.DOM.HTML as H
import Data.Argonaut as Argonaut import Data.Argonaut as Argonaut
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
...@@ -22,40 +35,57 @@ import Data.Maybe (Maybe(..)) ...@@ -22,40 +35,57 @@ import Data.Maybe (Maybe(..))
import Gargantext.Prelude (class Eq, class Read, class Show) import Gargantext.Prelude (class Eq, class Read, class Show)
------------------------------------------------------------------------ ------------------------------------------------------------------------
share :: Session -> ID -> ShareNode -> Aff ID shareReq :: Session -> ID -> ShareNodeParams -> Aff ID
share session nodeId = shareReq session nodeId =
post session $ GR.NodeAPI GT.Node (Just nodeId) "share" post session $ GR.NodeAPI GT.Node (Just nodeId) "share"
shareAction :: String -> Action shareAction :: String -> Action
shareAction username = Action.ShareTeam username shareAction username = Action.ShareTeam username
------------------------------------------------------------------------
newtype ShareValue = ShareValue
{ text :: String }
instance encodeJsonShareValue :: EncodeJson ShareValue where
encodeJson (ShareValue {text})
= "username" := text
~> jsonEmptyObject
------------------------------------------------------------------------ ------------------------------------------------------------------------
textInputBox :: Record Tools.TextInputBoxProps -> R.Element textInputBox :: Record Tools.TextInputBoxProps -> R.Element
textInputBox = Tools.textInputBox textInputBox = Tools.textInputBox
------------------------------------------------------------------------ ------------------------------------------------------------------------
data ShareNodeParams = ShareTeamParams { username :: String }
| SharePublicParams { node_id :: Int }
data ShareNode = ShareTeam { username :: String } derive instance eqShareNodeParams :: Eq ShareNodeParams
| SharePublic { rights :: String }
derive instance eqShareNode :: Eq ShareNode derive instance genericShareNodeParams :: Generic ShareNodeParams _
derive instance genericShareNode :: Generic ShareNode _ instance showShareNodeParams :: Show ShareNodeParams where
instance showShareNode :: Show ShareNode where
show = genericShow show = genericShow
instance decodeJsonShareNode :: Argonaut.DecodeJson ShareNode where instance decodeJsonShareNodeParams :: Argonaut.DecodeJson ShareNodeParams where
decodeJson = genericSumDecodeJson decodeJson = genericSumDecodeJson
instance encodeJsonShareNode :: Argonaut.EncodeJson ShareNode where instance encodeJsonShareNodeParams :: Argonaut.EncodeJson ShareNodeParams where
encodeJson = genericSumEncodeJson encodeJson = genericSumEncodeJson
------------------------------------------------------------------------
shareNode :: Record SubTreeParamsIn -> R.Element
shareNode p = R.createElement shareNodeCpt p []
shareNodeCpt :: R.Component SubTreeParamsIn
shareNodeCpt = R.hooksComponent "G.C.F.T.N.A.M.shareNode" cpt
where
cpt p@{dispatch, subTreeParams, id, nodeType, session} _ = do
action@(valAction /\ setAction) :: R.State Action <- R.useState' (Action.SharePublic {params: Nothing})
let button = case valAction of
Action.SharePublic {params} -> case params of
Just val -> submitButton (Action.SharePublic {params: Just val}) dispatch
Nothing -> H.div {} []
_ -> H.div {} []
pure $ panel [ subTreeView { action
, dispatch
, id
, nodeType
, session
, subTreeParams
}
] button
...@@ -295,11 +295,11 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt ...@@ -295,11 +295,11 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt
, id , id
, text: "username" , text: "username"
, isOpen , isOpen
} }
] ]
cpt {action : Publish, dispatch } _ = do cpt {action : Publish {subTreeParams}, dispatch, id, nodeType, session } _ = do
pure $ H.div {className:"center"} [ submitButton SharePublic dispatch ] pure $ Share.shareNode {dispatch, id, nodeType, session, subTreeParams}
cpt props@{action: SearchBox, id, session, dispatch, nodePopup} _ = cpt props@{action: SearchBox, id, session, dispatch, nodePopup} _ =
......
...@@ -20,7 +20,7 @@ data NodeAction = Documentation NodeType ...@@ -20,7 +20,7 @@ data NodeAction = Documentation NodeType
| Download | Upload | Refresh | Config | Download | Upload | Refresh | Config
| Delete | Delete
| Share | Share
| Publish | Publish { subTreeParams :: SubTreeParams }
| Add (Array NodeType) | Add (Array NodeType)
| Merge { subTreeParams :: SubTreeParams } | Merge { subTreeParams :: SubTreeParams }
| Move { subTreeParams :: SubTreeParams } | Move { subTreeParams :: SubTreeParams }
...@@ -42,7 +42,7 @@ instance eqNodeAction :: Eq NodeAction where ...@@ -42,7 +42,7 @@ instance eqNodeAction :: Eq NodeAction where
eq (Add x) (Add y) = x == y eq (Add x) (Add y) = x == y
eq (Merge x) (Merge y) = x == y eq (Merge x) (Merge y) = x == y
eq Config Config = true eq Config Config = true
eq Publish Publish = true eq (Publish x) (Publish y) = x == y
eq _ _ = false eq _ _ = false
instance showNodeAction :: Show NodeAction where instance showNodeAction :: Show NodeAction where
...@@ -59,7 +59,7 @@ instance showNodeAction :: Show NodeAction where ...@@ -59,7 +59,7 @@ instance showNodeAction :: Show NodeAction where
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 (Merge t) = "Merge with subtree" <> show t show (Merge t) = "Merge with subtree" <> show t
show Publish = "Publish" show (Publish x) = "Publish" <> show x
glyphiconNodeAction :: NodeAction -> String glyphiconNodeAction :: NodeAction -> String
glyphiconNodeAction (Documentation _) = "question-circle" glyphiconNodeAction (Documentation _) = "question-circle"
...@@ -74,7 +74,7 @@ glyphiconNodeAction Refresh = "refresh" ...@@ -74,7 +74,7 @@ glyphiconNodeAction Refresh = "refresh"
glyphiconNodeAction Config = "wrench" glyphiconNodeAction Config = "wrench"
glyphiconNodeAction Share = "user-plus" glyphiconNodeAction Share = "user-plus"
glyphiconNodeAction (Move _) = "share-square-o" glyphiconNodeAction (Move _) = "share-square-o"
glyphiconNodeAction Publish = fldr FolderPublic true glyphiconNodeAction (Publish _) = fldr FolderPublic true
glyphiconNodeAction _ = "" glyphiconNodeAction _ = ""
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -135,11 +135,9 @@ settingsBox FolderShared = ...@@ -135,11 +135,9 @@ settingsBox FolderShared =
settingsBox FolderPublic = settingsBox FolderPublic =
SettingsBox { show : true SettingsBox { show : true
, edit : false , edit : true
, doc : Documentation FolderPublic , doc : Documentation FolderPublic
, buttons : [ Add [ Corpus , buttons : [ Add [ FolderPublic ]
, Folder
]
-- , Delete -- , Delete
] ]
} }
...@@ -197,7 +195,7 @@ settingsBox Graph = ...@@ -197,7 +195,7 @@ settingsBox Graph =
, buttons : [ Refresh , buttons : [ Refresh
, Config , Config
, Download -- TODO as GEXF or JSON , Download -- TODO as GEXF or JSON
, Publish , Publish publishParams
, Delete , Delete
] ]
} }
...@@ -211,6 +209,22 @@ settingsBox (NodePublic Graph) = ...@@ -211,6 +209,22 @@ settingsBox (NodePublic Graph) =
] ]
} }
settingsBox (NodePublic Dashboard) =
SettingsBox { show : true
, edit : true
, doc : Documentation Dashboard
, buttons : [ Delete
]
}
settingsBox (NodePublic FolderPublic) =
SettingsBox { show : true
, edit : true
, doc : Documentation FolderPublic
, buttons : [ Delete
, Add [FolderPublic]
]
}
settingsBox NodeList = settingsBox NodeList =
...@@ -241,6 +255,7 @@ settingsBox Dashboard = ...@@ -241,6 +255,7 @@ settingsBox Dashboard =
, edit : false , edit : false
, doc : Documentation Dashboard , doc : Documentation Dashboard
, buttons : [ Refresh , buttons : [ Refresh
, Publish publishParams
, Delete , Delete
] ]
} }
...@@ -343,3 +358,13 @@ linkParams = { subTreeParams : SubTreeParams ...@@ -343,3 +358,13 @@ linkParams = { subTreeParams : SubTreeParams
} }
} }
publishParams = { subTreeParams : SubTreeParams
{ showtypes: [ FolderPublic
]
, valitypes: [ FolderPublic
]
}
}
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