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