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

3
import Gargantext.Prelude (class Eq, class Show, show, (&&), (<>), (==))
4
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree.Types (SubTreeParams(..))
5 6 7 8 9 10 11 12 13 14 15
import Gargantext.Types

------------------------------------------------------------------------
------------------------------------------------------------------------
{-
-- | RIGHT Management
if user has access to node then he can do all his related actions
-}
------------------------------------------------------------------------
data NodeAction = Documentation NodeType
                | SearchBox
Fabien Manière's avatar
Fabien Manière committed
16
                | Download | Upload | Refresh | Config | Reconstruct
17 18
                | Delete
                | Share
19
                | ManageTeam
20
                | Publish { subTreeParams :: SubTreeParams }
21 22
                | Add    (Array NodeType)
                | Merge { subTreeParams :: SubTreeParams }
23
                | Move  { subTreeParams :: SubTreeParams }
24
                | Link  { subTreeParams :: SubTreeParams }
25
                | Clone
26
                | AddingContact
27
                | CloseNodePopover
28
                | WriteNodesDocuments  -- https://gitlab.iscpif.fr/gargantext/purescript-gargantext/issues/331
29 30

------------------------------------------------------------------------
31
instance Eq NodeAction where
32 33 34 35 36 37 38 39 40
  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 x) (Move y)                       = x == y
  eq Clone Clone                             = true
  eq Delete Delete                           = true
  eq Share Share                             = true
41
  eq ManageTeam ManageTeam                   = true
42 43 44 45
  eq (Link x) (Link y)                       = x == y
  eq (Add  x) (Add  y)                       = x == y
  eq (Merge x) (Merge y)                     = x == y
  eq Config Config                           = true
Fabien Manière's avatar
Fabien Manière committed
46
  eq Reconstruct Reconstruct                 = true
47 48 49 50 51
  eq (Publish x) (Publish y)                 = x == y
  eq AddingContact AddingContact             = true
  eq CloseNodePopover CloseNodePopover       = true
  eq WriteNodesDocuments WriteNodesDocuments = true
  eq _ _                                     = false
52

53
instance Show NodeAction where
54 55 56 57 58 59 60 61 62
  show (Documentation x)   = "Documentation of " <> show x
  show SearchBox           = "SearchBox"
  show Download            = "Download"
  show Upload              = "Upload"
  show Refresh             = "Refresh"
  show (Move _)            = "Move with subtree params" -- <> show t
  show Clone               = "Clone"
  show Delete              = "Delete"
  show Share               = "Share"
63
  show ManageTeam          = "Team"
64
  show Config              = "Config"
Fabien Manière's avatar
Fabien Manière committed
65
  show Reconstruct         = "Reconstruct"
66 67 68 69 70 71 72
  show (Link _)            = "Link to " -- <> show x
  show (Add _)             = "Add Child" -- foldl (\a b -> a <> show b) "Add " xs
  show (Merge _)           = "Merge with subtree" -- <> show t
  show (Publish _)         = "Publish" -- <> show x
  show AddingContact       = "AddingContact"
  show CloseNodePopover    = "CloseNodePopover"
  show WriteNodesDocuments = "WriteNodesDocuments"
73 74

glyphiconNodeAction :: NodeAction -> String
75 76 77 78 79 80 81 82 83 84
glyphiconNodeAction (Documentation _)   = "question-circle"
glyphiconNodeAction Delete              = "trash"
glyphiconNodeAction (Add _)             = "plus"
glyphiconNodeAction SearchBox           = "search"
glyphiconNodeAction Upload              = "upload"
glyphiconNodeAction (Link _)            = "arrows-h"
glyphiconNodeAction Download            = "download"
glyphiconNodeAction (Merge _)           = "random"
glyphiconNodeAction Refresh             = "refresh"
glyphiconNodeAction Config              = "wrench"
Fabien Manière's avatar
Fabien Manière committed
85
glyphiconNodeAction Reconstruct         = "cogs"
86
glyphiconNodeAction Share               = "user-plus"
87
glyphiconNodeAction ManageTeam          = "users"
88 89 90 91 92 93
glyphiconNodeAction AddingContact       = "user-plus"
glyphiconNodeAction (Move _)            = "share-square-o"
glyphiconNodeAction (Publish _)         = fldr FolderPublic true
glyphiconNodeAction CloseNodePopover    = "close"
glyphiconNodeAction WriteNodesDocuments = "bars"
glyphiconNodeAction _                   = ""
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

------------------------------------------------------------------------
data SettingsBox =
  SettingsBox { show    :: Boolean
              , edit    :: Boolean
              , doc     :: NodeAction
              , buttons :: Array NodeAction
              }
------------------------------------------------------------------------

settingsBox :: NodeType -> SettingsBox
settingsBox NodeUser =
  SettingsBox { show : true
              , edit : false
              , doc  : Documentation NodeUser
109
              , buttons : [ Delete
110
                          ]
111 112 113 114 115 116
              }

settingsBox FolderPrivate =
  SettingsBox { show : true
              , edit : false
              , doc  : Documentation FolderPrivate
117
              , buttons : [ Add [ Notes
118
                                , Corpus
119
                                , Calc
120 121
                                , Folder
                                , Annuaire
122
                                -- , NodeFrameNotebook
123 124 125 126 127 128 129 130
                                ]
                          ]
              }

settingsBox Team =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation Team
131
              , buttons : [ Add [ Notes
132
                                , Corpus
133
                                , Calc
134
                                , Folder
135
                                , Team
136
                                , Annuaire
137
                                -- , NodeFrameNotebook
Alexandre Delanoë's avatar
Alexandre Delanoë committed
138
                                , FolderShared
139
                                , NodeFrameVisio
140 141
                                ]
                          , Share
142
                          , ManageTeam
143 144
                          , Delete
                          ]
145 146 147 148 149 150
              }

settingsBox FolderShared =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation FolderShared
151
              , buttons : [ Add [Team, FolderShared]
152 153 154 155 156
                          ]
              }

settingsBox FolderPublic =
  SettingsBox { show : true
157
              , edit : true
158
              , doc  : Documentation FolderPublic
159
              , buttons : [ Add [ FolderPublic ]
160
                          ]
161 162 163 164 165 166
              }

settingsBox Folder =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation Folder
167
              , buttons : [ Add [ Notes
168
                                , Corpus
169
                                , Calc
170 171
                                , Folder
                                , Annuaire
172
                                -- , NodeFrameNotebook
173
                                ]
174
                          , Move moveParameters
175 176 177 178 179 180 181 182
                          , Delete
                          ]
              }

settingsBox Corpus =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation Corpus
183
              , buttons : [ Add [ Graph
184
                                , Notes
185
                                , Calc
186
                                , NodeTexts
187
                                , NodeList
188 189
                                , Graph
                                , Dashboard
190
                                , Phylo
191
                                -- , NodeFrameNotebook
192
                                ]
193
                          , Move moveParameters
194 195
                          , Upload
                          , SearchBox
196
                          , WriteNodesDocuments
197
                          -- , Download
198
                          , Link (linkParams Annuaire)
199 200 201 202
                          , Delete
                          ]
              }

203
settingsBox NodeTexts =
204
  SettingsBox { show : true
205
              , edit : true
206
              , doc  : Documentation NodeTexts
207 208 209
              , buttons : [ Refresh
                          , Upload
                          , Download
210
                          , Delete
211 212 213 214 215
                          ]
              }

settingsBox Graph =
  SettingsBox { show : true
216
              , edit : true
217 218 219 220
              , doc  : Documentation Graph
              , buttons : [ Refresh
                          , Config
                          , Download -- TODO as GEXF or JSON
221
                          -- , Publish publishParams
222 223 224 225
                          , Delete
                          ]
              }

226 227 228 229
settingsBox Phylo =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation Phylo
Fabien Manière's avatar
Fabien Manière committed
230
              , buttons : [ Reconstruct
231
                          , Delete
232 233 234 235 236
                          ]
              }



237 238 239 240 241 242 243 244 245
settingsBox (NodePublic Graph) =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation Graph
              , buttons : [ Download -- TODO as GEXF or JSON
                          , Delete
                          ]
              }

246 247 248 249 250 251 252 253
settingsBox (NodePublic Dashboard) =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation Dashboard
              , buttons : [ Delete
                          ]
              }

254 255 256 257 258 259 260 261 262 263
settingsBox (NodePublic NodeFile) =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation NodeFile
              , buttons : [ Delete
                          ]
              }



264 265 266 267
settingsBox (NodePublic FolderPublic) =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation FolderPublic
268 269
              , buttons : [ Add [FolderPublic]
                          , Delete
270 271
                          ]
              }
272 273


274 275
settingsBox NodeList =
  SettingsBox { show : true
276
              , edit : true
277 278 279 280 281
              , doc  : Documentation NodeList
              , buttons : [ Refresh
                          , Config
                          , Download
                          , Upload
282 283 284 285 286 287 288 289 290 291 292
                          , Merge {subTreeParams : SubTreeParams { showtypes: [ FolderPrivate
                                                                , FolderShared
                                                                , Team
                                                                , FolderPublic
                                                                , Folder
                                                                , Corpus
                                                                , NodeList
                                                                ]
                                                    , valitypes: [ NodeList ]
                                                    }
                                   }
293 294 295 296 297 298 299 300
                          , Delete
                          ]
              }

settingsBox Dashboard =
  SettingsBox { show : true
              , edit : false
              , doc  : Documentation Dashboard
301
              , buttons : [ Refresh
302
                          , Publish publishParams
303 304
                          , Delete
                          ]
305 306 307 308
              }

settingsBox Annuaire =
  SettingsBox { show : true
309
              , edit : true
310 311
              , doc  : Documentation Annuaire
              , buttons : [ Upload
312
                          , AddingContact
313
                          , Move moveParameters
314
                          , Link (linkParams Corpus)
315 316 317 318
                          , Delete
                          ]
              }

319

320
settingsBox Notes =
321 322
  SettingsBox { show : true
              , edit : true
323 324
              , doc  : Documentation Notes
              , buttons : [ Add [ Notes
325
                                , Calc
326 327
                                , Folder
                                , Corpus
328
                                ]
329
                          , Move moveFrameParameters
330
                          , Delete
331 332 333 334
                          ]
              }


335
settingsBox Calc =
336 337
  SettingsBox { show : true
              , edit : true
338
              , doc  : Documentation Calc
339
              , buttons : [ Upload
340
                          , Add [ Calc
341
                                , Notes
342
                                ]
343
                          , Move moveFrameParameters
344
                          , Delete
345 346 347
                          ]
              }

348
settingsBox NodeFrameNotebook =
349 350
  SettingsBox { show : true
              , edit : true
351
              , doc  : Documentation NodeFrameNotebook
352
              , buttons : [ Add [ Calc
353
                                , Notes
354
                                -- , NodeFrameNotebook
355 356 357 358 359 360 361
                                ]
                          , Move moveFrameParameters
                          , Delete
                          ]
              }


362 363 364 365 366
settingsBox NodeFrameVisio =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation NodeFrameVisio
              , buttons : [ Add [ NodeFrameVisio
367
                                , Notes
368
                                , Calc
369 370 371 372 373 374
                                ]
                          , Delete
                          ]
              }


375 376 377 378
settingsBox NodeFile =
  SettingsBox { show: true
              , edit: true
              , doc: Documentation NodeFile
379 380
              , buttons: [ Publish publishParams
                         , Delete ]
381 382 383
              }


384 385 386 387 388 389
settingsBox _ =
  SettingsBox { show : false
              , edit : false
              , doc  : Documentation NodeUser
              , buttons : []
              }
390

391 392
-- | SubTree Parameters

393
moveParameters = { subTreeParams : SubTreeParams
394 395 396 397 398
                                 { showtypes: [ FolderPrivate
                                              , FolderShared
                                              , Team
                                              , FolderPublic
                                              , Folder
399
                                              , Notes
400
                                              , Corpus
401 402
                                              ]
                                 , valitypes: [ FolderPrivate
403 404
                                              , Team
                                              -- , FolderPublic
405
                                              , Folder
406
                                              , Notes
407
                                              , Corpus
408 409 410 411
                                              ]
                                 }
                  }

412

413
moveFrameParameters = { subTreeParams : SubTreeParams
414 415 416 417 418 419
                                 { showtypes: [ FolderPrivate
                                              , FolderShared
                                              , Team
                                              , FolderPublic
                                              , Folder
                                              , Corpus
420
                                              , Notes
421
                                              , Calc
422 423 424 425 426 427
                                              ]
                                 , valitypes: [ FolderPrivate
                                              , Team
                                              -- , FolderPublic
                                              , Folder
                                              , Corpus
428
                                              , Notes
429
                                              , Calc
430 431 432 433 434
                                              ]
                                 }
                  }


435
linkParams :: NodeType -> {subTreeParams :: SubTreeParams}
436
linkParams nodeType =  { subTreeParams : SubTreeParams
437 438 439 440 441
                              { showtypes: [ FolderPrivate
                                           , FolderShared
                                           , Team
                                           , FolderPublic
                                           , Folder
442
                                           , nodeType
443
                                           ]
444
                              , valitypes: [ nodeType
445 446
                                           ]
                              }
447 448
                      }

449

450 451 452 453 454 455 456 457

publishParams =  { subTreeParams : SubTreeParams
                              { showtypes: [ FolderPublic
                                           ]
                              , valitypes: [ FolderPublic
                                           ]
                              }
               }