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

[FIX] unpublish public node is ok now

parent 5d754a86
...@@ -18,7 +18,7 @@ import Gargantext.Components.Forest.Tree.Node (nodeMainSpan) ...@@ -18,7 +18,7 @@ import Gargantext.Components.Forest.Tree.Node (nodeMainSpan)
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree.Types (SubTreeOut(..)) import Gargantext.Components.Forest.Tree.Node.Tools.SubTree.Types (SubTreeOut(..))
import Gargantext.Components.Forest.Tree.Node.Action (Action(..)) import Gargantext.Components.Forest.Tree.Node.Action (Action(..))
import Gargantext.Components.Forest.Tree.Node.Action.Add (AddNodeValue(..), addNode) import Gargantext.Components.Forest.Tree.Node.Action.Add (AddNodeValue(..), addNode)
import Gargantext.Components.Forest.Tree.Node.Action.Delete (deleteNode) import Gargantext.Components.Forest.Tree.Node.Action.Delete (deleteNode, unpublishNode)
import Gargantext.Components.Forest.Tree.Node.Action.Move (moveNodeReq) import Gargantext.Components.Forest.Tree.Node.Action.Move (moveNodeReq)
import Gargantext.Components.Forest.Tree.Node.Action.Merge (mergeNodeReq) import Gargantext.Components.Forest.Tree.Node.Action.Merge (mergeNodeReq)
import Gargantext.Components.Forest.Tree.Node.Action.Link (linkNodeReq) import Gargantext.Components.Forest.Tree.Node.Action.Link (linkNodeReq)
...@@ -193,8 +193,9 @@ toHtml p@{ asyncTasks ...@@ -193,8 +193,9 @@ toHtml p@{ asyncTasks
<> childNodes ( Record.merge commonProps <> childNodes ( Record.merge commonProps
{ asyncTasks { asyncTasks
, children: if isPublic nodeType , children: if isPublic nodeType
then map (\t -> map (\(LNode {id:id',name:name',nodeType:nt}) then map (\t -> map (\(LNode n@{ nodeType:nt } )
-> (LNode {id:id',name:name',nodeType: publicize nt})) t) ary -> (LNode (n { nodeType= publicize nt }))
) t) ary
else ary else ary
, folderOpen , folderOpen
} }
...@@ -238,10 +239,14 @@ performAction :: Action ...@@ -238,10 +239,14 @@ performAction :: Action
performAction (DeleteNode nt) p@{ openNodes: (_ /\ setOpenNodes) performAction (DeleteNode nt) p@{ openNodes: (_ /\ setOpenNodes)
, reload: (_ /\ setReload) , reload: (_ /\ setReload)
, session , session
, tree: (NTree (LNode {id}) _) , tree: (NTree (LNode {id, parent_id}) _)
} = } =
do do
void $ deleteNode session nt id case nt of
GT.NodePublic GT.FolderPublic -> void $ deleteNode session nt id
GT.NodePublic _ -> void $ unpublishNode session parent_id id
_ -> void $ deleteNode session nt id
liftEffect $ setOpenNodes (Set.delete (mkNodeId session id)) liftEffect $ setOpenNodes (Set.delete (mkNodeId session id))
performAction RefreshTree p performAction RefreshTree p
......
...@@ -15,11 +15,19 @@ import Reactix.DOM.HTML as H ...@@ -15,11 +15,19 @@ import Reactix.DOM.HTML as H
-- TODO Delete with asyncTaskWithType -- TODO Delete with asyncTaskWithType
deleteNode :: Session -> NodeType -> GT.ID -> Aff GT.ID deleteNode :: Session -> NodeType -> GT.ID -> Aff GT.ID
deleteNode session nt nodeId = deleteNode session nt nodeId = delete session $ NodeAPI GT.Node (Just nodeId) ""
{-
case nt of case nt of
NodePublic FolderPublic -> delete session $ NodeAPI GT.Node (Just nodeId) "" 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) ""
-}
type ParentID = GT.ID
unpublishNode :: Session -> Maybe ParentID -> GT.ID -> Aff GT.ID
unpublishNode s p n = put_ s $ NodeAPI GT.Node p ("unpublish/" <> show n)
-- | Action : Delete -- | Action : Delete
actionDelete :: NodeType -> (Action -> Aff Unit) -> R.Hooks R.Element actionDelete :: NodeType -> (Action -> Aff Unit) -> R.Hooks R.Element
......
...@@ -221,8 +221,8 @@ settingsBox (NodePublic FolderPublic) = ...@@ -221,8 +221,8 @@ settingsBox (NodePublic FolderPublic) =
SettingsBox { show : true SettingsBox { show : true
, edit : true , edit : true
, doc : Documentation FolderPublic , doc : Documentation FolderPublic
, buttons : [ Delete , buttons : [ Add [FolderPublic]
, Add [FolderPublic] , Delete
] ]
} }
......
module Gargantext.Components.Forest.Tree.Node.Tools.FTree where module Gargantext.Components.Forest.Tree.Node.Tools.FTree where
import Data.Maybe (Maybe(..))
import Data.Argonaut (class DecodeJson, decodeJson, (.:)) import Data.Argonaut (class DecodeJson, decodeJson, (.:))
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import Gargantext.Types as GT import Gargantext.Types as GT
...@@ -21,6 +22,7 @@ instance ntreeFunctor :: Functor NTree where ...@@ -21,6 +22,7 @@ instance ntreeFunctor :: Functor NTree where
newtype LNode = LNode { id :: ID newtype LNode = LNode { id :: ID
, name :: Name , name :: Name
, nodeType :: GT.NodeType , nodeType :: GT.NodeType
, parent_id :: Maybe ID
} }
derive instance newtypeLNode :: Newtype LNode _ derive instance newtypeLNode :: Newtype LNode _
...@@ -34,6 +36,7 @@ instance decodeJsonLNode :: DecodeJson LNode where ...@@ -34,6 +36,7 @@ instance decodeJsonLNode :: DecodeJson LNode where
pure $ LNode { id : id_ pure $ LNode { id : id_
, name , name
, nodeType , nodeType
, parent_id : Nothing
} }
instance decodeJsonFTree :: DecodeJson (NTree LNode) where instance decodeJsonFTree :: DecodeJson (NTree LNode) where
...@@ -43,5 +46,10 @@ instance decodeJsonFTree :: DecodeJson (NTree LNode) where ...@@ -43,5 +46,10 @@ instance decodeJsonFTree :: DecodeJson (NTree LNode) where
nodes <- obj .: "children" nodes <- obj .: "children"
node' <- decodeJson node node' <- decodeJson node
nodes' <- decodeJson nodes nodes' <- decodeJson nodes
pure $ NTree node' nodes' let (LNode {id}) = node'
pure $ NTree node' (map (addParent id) nodes')
addParent :: ID -> NTree LNode -> NTree LNode
addParent id (NTree (LNode p@{id:id'}) ary)=
NTree (LNode (p {parent_id=Just id}))
(map (addParent id') ary)
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