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

3 4
import Gargantext.Prelude

5
import Data.Maybe (Maybe(..))
6
import Effect.Aff (Aff)
7
import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(..))
8
import Gargantext.Components.Forest.Tree.Node.Settings (NodeAction(..), glyphiconNodeAction)
9
import Gargantext.Components.Forest.Tree.Node.Tools.FTree (ID)
10
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree.Types (SubTreeOut, SubTreeParams(..))
11
import Gargantext.Sessions (Session)
12
import Gargantext.Types as GT
13 14 15

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

21
subTreeOut :: Action -> Maybe SubTreeOut
22 23 24 25
subTreeOut (MoveNode    {params}) = params
subTreeOut (MergeNode   {params}) = params
subTreeOut (LinkNode    {params}) = params
subTreeOut (SharePublic {params}) = params
26 27 28
subTreeOut _                    = Nothing

setTreeOut ::  Action -> Maybe SubTreeOut -> Action
Alexandre Delanoë's avatar
Alexandre Delanoë committed
29
setTreeOut (MoveNode  {params:_}) p = MoveNode  {params: p}
Alexandre Delanoë's avatar
Alexandre Delanoë committed
30
setTreeOut (MergeNode {params:_}) p = MergeNode {params: p}
31
setTreeOut (LinkNode  {nodeType, params:_}) p = LinkNode  {nodeType, params: p}
32
setTreeOut (SharePublic {params:_}) p = SharePublic  {params: p}
33 34
setTreeOut a   _             = a

35
-----------------------------------------------------------------------
36
icon :: Action -> String
37 38 39 40 41 42 43 44
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
45
icon (UploadFile _ _ _ _ _ _ _)     = glyphiconNodeAction Upload
46 47 48
icon (UploadArbitraryFile _ _ _ _ ) = glyphiconNodeAction Upload
icon UploadFrameCalc                = glyphiconNodeAction Upload
icon  RefreshTree                   = glyphiconNodeAction Refresh
49
icon  CloseBox                      = glyphiconNodeAction CloseNodePopover
50 51 52 53 54
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:[] }})
icon (DocumentsFromWriteNodes _)    = glyphiconNodeAction (WriteNodesDocuments)
55

56
icon NoAction                       = "hand-o-right"
57

58 59
-- icon _             = "hand-o-right"

60
text :: Action -> String
61 62 63 64 65 66 67 68
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 !"
69
text (UploadFile _ _ _ _ _ _ _)     = "Upload File !"
70 71 72
text (UploadArbitraryFile _ _  _ _) = "Upload arbitrary file !"
text UploadFrameCalc                = "Upload frame calc"
text  RefreshTree                   = "Refresh Tree !"
73
text  CloseBox                      = "Close Box !"
74 75 76 77 78 79
text DownloadNode                   = "Download !"
text (MoveNode  _ )                 = "Move !"
text (MergeNode _ )                 = "Merge !"
text (LinkNode  _ )                 = "Link !"
text (DocumentsFromWriteNodes _ )   = "Documents from Write Nodes !"
text NoAction                       = "No Action"
80
-----------------------------------------------------------------------