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

Alexandre Delanoë's avatar
Alexandre Delanoë committed
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
import Gargantext.Components.Forest.Tree.Node.Settings (NodeAction(..), glyphiconNodeAction)
9
import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileType, UploadFileContents)
10
import Gargantext.Components.Forest.Tree.Node.Action.Update.Types (UpdateNodeParams)
11

12 13 14 15 16 17 18
{-
type UpdateNodeProps =
  ( id       :: GT.ID
  , dispatch :: Action -> Aff Unit
  , name     :: GT.Name
  , nodeType :: NodeType
  , params   :: UpdateNodeParams
Alexandre Delanoë's avatar
Alexandre Delanoë committed
19
  )
20 21
  -}

Alexandre Delanoë's avatar
Alexandre Delanoë committed
22

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

33

34
instance showShow :: Show Action where
35
  show (AddNode     _ _    )= "AddNode"
Alexandre Delanoë's avatar
Alexandre Delanoë committed
36 37
  show  DeleteNode          = "DeleteNode"
  show (RenameNode  _      )= "RenameNode"
38 39
  show (UpdateNode  _      )= "UpdateNode"
  show (ShareNode   _      )= "ShareNode"
Alexandre Delanoë's avatar
Alexandre Delanoë committed
40
  show (DoSearch    _      )= "SearchQuery"
41
  show (UploadFile  _ _ _ _)= "UploadFile"
42
  show  RefreshTree         = "RefreshTree"
43
  show  DownloadNode        = "Download"
44

45 46 47 48 49 50
type Props =
  ( dispatch :: Action -> Aff Unit
  , id       :: Int
  , nodeType :: GT.NodeType
  , session  :: Session
  )
51
-----------------------------------------------------------------------
52
icon :: Action -> String
53
icon (AddNode    _ _)     = glyphiconNodeAction (Add [])
54
icon  DeleteNode          = glyphiconNodeAction Delete
55
icon (RenameNode _)       = glyphiconNodeAction Config
56
icon (UpdateNode _)       = glyphiconNodeAction Refresh
57
icon (ShareNode  _)       = glyphiconNodeAction Share
58 59
icon (DoSearch   _)       = glyphiconNodeAction SearchBox
icon (UploadFile _ _ _ _) = glyphiconNodeAction Upload
60
icon  RefreshTree         = glyphiconNodeAction Refresh
61
icon  DownloadNode        = glyphiconNodeAction Download
62 63
-- icon _             = "hand-o-right"

64
text :: Action -> String
65
text (AddNode     _ _    )= "Add !"
66
text  DeleteNode          = "Delete !"
67
text (RenameNode  _      )= "Rename !"
68
text (UpdateNode  _      )= "Update !"
69
text (ShareNode   _      )= "Share !"
70
text (DoSearch    _      )= "Launch search !"
71
text (UploadFile  _ _ _ _)= "Upload File !"
72
text  RefreshTree         = "Refresh Tree !"
73
text DownloadNode         = "Download !"
74
-----------------------------------------------------------------------