Action.purs 5.33 KB
Newer Older
1
module Gargantext.Components.Forest.Tree.Node.Action where
2

3
import Data.Maybe (Maybe(..))
4
import Effect.Aff (Aff)
5
import Gargantext.Prelude (class Show, Unit)
Alexandre Delanoë's avatar
Alexandre Delanoë committed
6
import Gargantext.Sessions (Session)
7
import Gargantext.Types  as GT
8 9
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree.Types (SubTreeOut, SubTreeParams(..))
import Gargantext.Components.Forest.Tree.Node.Settings (NodeAction(..), glyphiconNodeAction)
10
import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileType, UploadFileBlob)
11
import Gargantext.Components.Forest.Tree.Node.Action.Update.Types (UpdateNodeParams)
12
import Gargantext.Components.Forest.Tree.Node.Action.Contact.Types (AddContactParams)
13 14 15 16 17 18

type Props =
  ( dispatch :: Action -> Aff Unit
  , id       :: Int
  , nodeType :: GT.NodeType
  , session  :: Session
Alexandre Delanoë's avatar
Alexandre Delanoë committed
19
  )
20

21

22
data Action = AddNode     String GT.NodeType
23
            | DeleteNode  GT.NodeType
24
            | RenameNode  String
25
            | UpdateNode  UpdateNodeParams
26
            | DoSearch    GT.AsyncTaskWithType
27
            | UploadFile  GT.NodeType FileType (Maybe String) UploadFileBlob
28
            | UploadArbitraryFile  (Maybe String) UploadFileBlob
29
            | DownloadNode
30
            | RefreshTree
31
            | ClosePopover
32

33
            | ShareTeam   String
34
            | AddContact  AddContactParams
35 36 37
            | SharePublic {params :: Maybe SubTreeOut}
            | MoveNode    {params :: Maybe SubTreeOut}
            | MergeNode   {params :: Maybe SubTreeOut}
38
            | LinkNode    {nodeType :: Maybe GT.NodeType, params :: Maybe SubTreeOut}
39

40
            | NoAction
41

42

43
subTreeOut :: Action -> Maybe SubTreeOut
44 45 46 47
subTreeOut (MoveNode    {params}) = params
subTreeOut (MergeNode   {params}) = params
subTreeOut (LinkNode    {params}) = params
subTreeOut (SharePublic {params}) = params
48 49 50
subTreeOut _                    = Nothing

setTreeOut ::  Action -> Maybe SubTreeOut -> Action
Alexandre Delanoë's avatar
Alexandre Delanoë committed
51
setTreeOut (MoveNode  {params:_}) p = MoveNode  {params: p}
Alexandre Delanoë's avatar
Alexandre Delanoë committed
52
setTreeOut (MergeNode {params:_}) p = MergeNode {params: p}
53
setTreeOut (LinkNode  {nodeType, params:_}) p = LinkNode  {nodeType, params: p}
54
setTreeOut (SharePublic {params:_}) p = SharePublic  {params: p}
55 56 57
setTreeOut a   _             = a


58
instance showShow :: Show Action where
59 60 61 62 63 64 65 66 67
  show (AddNode     _ _    )      = "AddNode"
  show (DeleteNode  _      )      = "DeleteNode"
  show (RenameNode  _      )      = "RenameNode"
  show (UpdateNode  _      )      = "UpdateNode"
  show (ShareTeam   _      )      = "ShareTeam"
  show (AddContact  _      )      = "AddContact"
  show (SharePublic _      )      = "SharePublic"
  show (DoSearch    _      )      = "SearchQuery"
  show (UploadFile  _ _ _ _)      = "UploadFile"
68
  show (UploadArbitraryFile  _ _) = "UploadArbitraryFile"
69 70 71 72 73 74 75
  show  RefreshTree               = "RefreshTree"
  show  ClosePopover              = "ClosePopover"
  show  DownloadNode              = "Download"
  show (MoveNode  _ )             = "MoveNode"
  show (MergeNode _ )             = "MergeNode"
  show (LinkNode  _ )             = "LinkNode"
  show NoAction                   = "NoAction"
76

77
-----------------------------------------------------------------------
78
icon :: Action -> String
79 80 81 82 83 84 85 86 87
icon (AddNode    _ _)             = glyphiconNodeAction (Add [])
icon (DeleteNode _)               = glyphiconNodeAction Delete
icon (RenameNode _)               = glyphiconNodeAction Config
icon (UpdateNode _)               = glyphiconNodeAction Refresh
icon (ShareTeam   _)              = glyphiconNodeAction Share
icon (AddContact  _)              = glyphiconNodeAction Share
icon (SharePublic _ )             = glyphiconNodeAction (Publish { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (DoSearch   _)               = glyphiconNodeAction SearchBox
icon (UploadFile _ _ _ _)         = glyphiconNodeAction Upload
88
icon (UploadArbitraryFile _ _ ) = glyphiconNodeAction Upload
89
icon  RefreshTree                 = glyphiconNodeAction Refresh
90
icon  ClosePopover                = glyphiconNodeAction CloseNodePopover
91 92 93 94
icon  DownloadNode                = glyphiconNodeAction Download
icon (MoveNode _ )                = glyphiconNodeAction (Move  { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (MergeNode _ )               = glyphiconNodeAction (Merge { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (LinkNode _  )               = glyphiconNodeAction (Link  { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
95

96
icon NoAction                     = "hand-o-right"
97

98 99
-- icon _             = "hand-o-right"

100
text :: Action -> String
101 102 103 104 105 106 107 108 109
text (AddNode     _ _    )      = "Add !"
text (DeleteNode _       )      = "Delete !"
text (RenameNode  _      )      = "Rename !"
text (UpdateNode  _      )      = "Update !"
text (ShareTeam   _      )      = "Share with team !"
text (AddContact  _      )      = "Add contact !"
text (SharePublic _      )      = "Publish !"
text (DoSearch    _      )      = "Launch search !"
text (UploadFile  _ _ _ _)      = "Upload File !"
110
text (UploadArbitraryFile  _ _) = "Upload arbitrary file !"
111 112 113 114 115 116 117
text  RefreshTree               = "Refresh Tree !"
text  ClosePopover              = "Close Popover !"
text DownloadNode               = "Download !"
text (MoveNode  _ )             = "Move !"
text (MergeNode _ )             = "Merge !"
text (LinkNode  _ )             = "Link !"
text NoAction                   = "No Action"
118
-----------------------------------------------------------------------