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

3
import Data.Generic.Rep (class Generic)
4
import Data.Maybe (Maybe(..))
5
import Effect.Aff (Aff)
6

7 8
import Gargantext.Prelude

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
import Gargantext.Sessions (Session)
import Gargantext.Types  as GT
16 17 18 19 20 21

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

24

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

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

43
            | NoAction
44

45

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

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

60
derive instance Generic Action _
61

62
instance Eq Action where
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
  eq (AddNode s1 nt1) (AddNode s2 nt2) = (eq s1 s2) && (eq nt1 nt2)
  eq (DeleteNode nt1) (DeleteNode nt2) = eq nt1 nt2
  eq (RenameNode s1) (RenameNode s2) = eq s1 s2
  eq (UpdateNode un1) (UpdateNode un2) = eq un1 un2
  eq (DoSearch at1) (DoSearch at2) = eq at1 at2
  eq (UploadFile nt1 ft1 s1 _) (UploadFile nt2 ft2 s2 _) = (eq nt1 nt2) && (eq ft1 ft2) && (eq s1 s2)
  eq (UploadArbitraryFile s1 _) (UploadArbitraryFile s2 _) = eq s1 s2
  eq DownloadNode DownloadNode = true
  eq RefreshTree RefreshTree = true
  eq ClosePopover ClosePopover = true
  eq (ShareTeam s1) (ShareTeam s2) = eq s1 s2
  eq (AddContact ac1) (AddContact ac2) = eq ac1 ac2
  eq (SharePublic p1) (SharePublic p2) = eq p1 p2
  eq (MoveNode p1) (MoveNode p2) = eq p1 p2
  eq (MergeNode p1) (MergeNode p2) = eq p1 p2
  eq (LinkNode l1) (LinkNode l2) = eq l1 l2
  eq NoAction NoAction = true
  eq _ _ = false

82
instance Show Action where
83 84 85 86 87 88 89 90 91
  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"
92
  show (UploadArbitraryFile  _ _) = "UploadArbitraryFile"
93 94 95 96 97 98 99
  show  RefreshTree               = "RefreshTree"
  show  ClosePopover              = "ClosePopover"
  show  DownloadNode              = "Download"
  show (MoveNode  _ )             = "MoveNode"
  show (MergeNode _ )             = "MergeNode"
  show (LinkNode  _ )             = "LinkNode"
  show NoAction                   = "NoAction"
100

101
-----------------------------------------------------------------------
102
icon :: Action -> String
103 104 105 106 107 108 109 110 111
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
112
icon (UploadArbitraryFile _ _ ) = glyphiconNodeAction Upload
113
icon  RefreshTree                 = glyphiconNodeAction Refresh
114
icon  ClosePopover                = glyphiconNodeAction CloseNodePopover
115 116 117 118
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:[] }})
119

120
icon NoAction                     = "hand-o-right"
121

122 123
-- icon _             = "hand-o-right"

124
text :: Action -> String
125 126 127 128 129 130 131 132 133
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 !"
134
text (UploadArbitraryFile  _ _) = "Upload arbitrary file !"
135 136 137 138 139 140 141
text  RefreshTree               = "Refresh Tree !"
text  ClosePopover              = "Close Popover !"
text DownloadNode               = "Download !"
text (MoveNode  _ )             = "Move !"
text (MergeNode _ )             = "Merge !"
text (LinkNode  _ )             = "Link !"
text NoAction                   = "No Action"
142
-----------------------------------------------------------------------