Action.purs 5.21 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 28
            | UploadFile  GT.NodeType FileType (Maybe String) UploadFileBlob
            | UploadArbitraryFile  GT.NodeType (Maybe String) UploadFileBlob
29
            | DownloadNode
30
            | RefreshTree
31

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

39
            | NoAction
40

41

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

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


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

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

93
icon NoAction                     = "hand-o-right"
94

95 96
-- icon _             = "hand-o-right"

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