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

3
import Prelude (class Eq, class Show, show, (&&), (<>), (==))
4
import Data.Array (foldl)
5 6 7
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))

8 9
import Gargantext.Types

10 11
------------------------------------------------------------------------
------------------------------------------------------------------------
12 13 14 15 16
{-
-- | TODO
filterWithRights (show action if user can only)

-}
17 18
------------------------------------------------------------------------
------------------------------------------------------------------------
19 20 21

data Status a = IsBeta a | IsProd a

22 23
data NodeAction = Documentation NodeType
                | SearchBox
24
                | Download | Upload | Refresh | Config
25
                | Move     | Clone  | Delete
26
                | Share    | Link NodeType
27
                | Add (Array NodeType)
28
                | CopyFromCorpus
29 30 31 32 33 34 35 36 37 38 39 40


instance eqNodeAction :: Eq NodeAction where
  eq (Documentation x) (Documentation y) = true && (x == y)
  eq SearchBox SearchBox = true
  eq Download Download = true
  eq Upload Upload     = true
  eq Refresh Refresh   = true
  eq Move Move         = true
  eq Clone Clone       = true
  eq Delete Delete     = true
  eq Share Share       = true
41
  eq (Link x) (Link y) = true && (x == y)
42
  eq (Add  x) (Add  y) = true && (x == y)
43
  eq CopyFromCorpus CopyFromCorpus = true
44
  eq Config Config     = true
45 46
  eq _ _               = false

47 48 49 50 51 52 53 54 55 56
instance showNodeAction :: Show NodeAction where
  show (Documentation x) = "Documentation of " <> show x
  show SearchBox         = "SearchBox"
  show Download          = "Download"
  show Upload            = "Upload"
  show Refresh           = "Refresh"
  show Move              = "Move"
  show Clone             = "Clone"
  show Delete            = "Delete"
  show Share             = "Share"
57
  show Config            = "Config"
58 59
  show (Link x)          = "Link to " <> show x
  show (Add xs)          = foldl (\a b -> a <> show b) "Add " xs
60
  show CopyFromCorpus    = "Copy from corpus"
61 62 63 64 65 66 67 68 69 70


glyphiconNodeAction :: NodeAction -> String
glyphiconNodeAction (Documentation _) = "question-sign"
glyphiconNodeAction Delete            = "trash"
glyphiconNodeAction (Add _)           = "plus"
glyphiconNodeAction SearchBox         = "search"
glyphiconNodeAction Upload            = "upload"
glyphiconNodeAction (Link _)          = "transfer"
glyphiconNodeAction Download          = "download"
71
glyphiconNodeAction CopyFromCorpus    = "random"
72 73
glyphiconNodeAction Refresh           = "refresh"
glyphiconNodeAction Config            = "wrench"
74 75 76
glyphiconNodeAction _                 = ""


77
------------------------------------------------------------------------
78 79 80
data SettingsBox =
  SettingsBox { show    :: Boolean
              , edit    :: Boolean
81
              , doc     :: NodeAction
82 83
              , buttons :: Array NodeAction
              }
84
------------------------------------------------------------------------
85 86

settingsBox :: NodeType -> SettingsBox
87
settingsBox NodeUser = SettingsBox {
88
    show : true
89 90
  , edit : false
  , doc  : Documentation NodeUser
91
  , buttons : [ Delete ]
92 93 94
  }

settingsBox FolderPrivate = SettingsBox {
95
    show : true
96 97
  , edit : false
  , doc  : Documentation FolderPrivate
98
  , buttons : [ Add [ Corpus
99 100 101
                    , Folder
                    , Annuaire
                    ]
102
              ]
103 104 105
  }

settingsBox Team = SettingsBox {
106
    show : true
107
  , edit : true
108
  , doc  : Documentation Team
109
  , buttons : [ Add [ Corpus
110 111 112 113 114 115 116
                    , Folder
                    , Annuaire
                    ]
              , Delete]
  }

settingsBox FolderShared = SettingsBox {
117
    show : true
118 119
  , edit : true
  , doc  : Documentation FolderShared
120
  , buttons : [ Add [Team, FolderShared]
121
              -- , Delete
122 123 124 125
              ]
  }

settingsBox FolderPublic = SettingsBox {
126
    show : true
127 128
  , edit : false
  , doc  : Documentation FolderPublic
129
  , buttons : [ Add [ Corpus
130 131
                    , Folder
                    ]
132 133 134
    ]
  }

135 136 137 138 139 140 141 142 143 144 145
settingsBox Folder =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation Folder
              , buttons : [ Add [ Corpus
                                , Folder
                                , Annuaire
                                ]
                          , Delete
                          ]
              }
146

147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
settingsBox Corpus =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation Corpus
              , buttons : [ SearchBox
                          , Add [ NodeList
                                , Graph
                                , Dashboard
                                ]
                          , Upload
                          , Download
                            --, Share
                            --, Move
                            --, Clone
                          , Link Annuaire
                          , Delete
                          ]
              }
165

166 167 168 169 170 171 172 173 174 175
settingsBox Texts =
  SettingsBox { show : true
              , edit : false
              , doc  : Documentation Texts
              , buttons : [ Refresh
                          , Upload
                          , Download
                          -- , Delete
                          ]
              }
176

177 178 179 180 181 182 183 184 185 186
settingsBox Graph =
  SettingsBox { show : true
              , edit : false
              , doc  : Documentation Graph
              , buttons : [ Refresh
                          , Config
                          , Download -- TODO as GEXF or JSON
                          , Delete
                          ]
              }
187

188 189 190 191 192 193 194 195 196
settingsBox NodeList =
  SettingsBox { show : true
              , edit : false
              , doc  : Documentation NodeList
              , buttons : [ Refresh
                          , Config
                          , Download
                          , Upload
                          , CopyFromCorpus
197
                          , Delete
198 199
                          ]
              }
200

201 202 203 204 205 206
settingsBox Dashboard =
  SettingsBox { show : true
              , edit : false
              , doc  : Documentation Dashboard
              , buttons : []
              }
207

208 209 210 211 212 213 214 215
settingsBox Annuaire =
  SettingsBox { show : true
              , edit : false
              , doc  : Documentation Annuaire
              , buttons : [ Upload
                          , Delete
                          ]
              }
216

217 218 219 220 221 222
settingsBox _ =
  SettingsBox { show : false
              , edit : false
              , doc  : Documentation NodeUser
              , buttons : []
              }