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

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

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

22

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

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

41
            | NoAction
42

43

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

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


59
instance showShow :: Show Action where
60 61 62 63 64 65 66 67 68
  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"
69
  show (UploadArbitraryFile  _ _) = "UploadArbitraryFile"
70 71 72 73 74 75 76
  show  RefreshTree               = "RefreshTree"
  show  ClosePopover              = "ClosePopover"
  show  DownloadNode              = "Download"
  show (MoveNode  _ )             = "MoveNode"
  show (MergeNode _ )             = "MergeNode"
  show (LinkNode  _ )             = "LinkNode"
  show NoAction                   = "NoAction"
77

78
-----------------------------------------------------------------------
79
icon :: Action -> String
80 81 82 83 84 85 86 87 88
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
89
icon (UploadArbitraryFile _ _ ) = glyphiconNodeAction Upload
90
icon  RefreshTree                 = glyphiconNodeAction Refresh
91
icon  ClosePopover                = glyphiconNodeAction CloseNodePopover
92 93 94 95
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:[] }})
96

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

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

101
text :: Action -> String
102 103 104 105 106 107 108 109 110
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 !"
111
text (UploadArbitraryFile  _ _) = "Upload arbitrary file !"
112 113 114 115 116 117 118
text  RefreshTree               = "Refresh Tree !"
text  ClosePopover              = "Close Popover !"
text DownloadNode               = "Download !"
text (MoveNode  _ )             = "Move !"
text (MergeNode _ )             = "Merge !"
text (LinkNode  _ )             = "Link !"
text NoAction                   = "No Action"
119
-----------------------------------------------------------------------