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 16
import Gargantext.Types

------------------------------------------------------------------------
------------------------------------------------------------------------
{-
-- | RIGHT Management
if user has access to node then he can do all his related actions
-}
------------------------------------------------------------------------
data NodeAction = Documentation NodeType
                | SearchBox
                | Download | Upload | Refresh | Config
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 46 47 48 49 50
  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
  eq (Publish x) (Publish y)                 = x == y
  eq AddingContact AddingContact             = true
  eq CloseNodePopover CloseNodePopover       = true
  eq WriteNodesDocuments WriteNodesDocuments = true
  eq _ _                                     = false
51

52
instance Show NodeAction where
53 54 55 56 57 58 59 60 61
  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"
62
  show ManageTeam          = "Team"
63 64 65 66 67 68 69 70
  show Config              = "Config"
  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"
71 72

glyphiconNodeAction :: NodeAction -> String
73 74 75 76 77 78 79 80 81 82 83
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"
glyphiconNodeAction Share               = "user-plus"
84
glyphiconNodeAction ManageTeam          = "users"
85 86 87 88 89 90
glyphiconNodeAction AddingContact       = "user-plus"
glyphiconNodeAction (Move _)            = "share-square-o"
glyphiconNodeAction (Publish _)         = fldr FolderPublic true
glyphiconNodeAction CloseNodePopover    = "close"
glyphiconNodeAction WriteNodesDocuments = "bars"
glyphiconNodeAction _                   = ""
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

------------------------------------------------------------------------
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
106
              , buttons : [ Delete
107
                          ]
108 109 110 111 112 113
              }

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

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

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

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

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

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

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

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

225 226 227 228
settingsBox Phylo =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation Phylo
229 230
              , buttons : [ Refresh
                          , Delete
231 232 233 234 235
                          ]
              }



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

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

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



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


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

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

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

318

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


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

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


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


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


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

390 391
-- | SubTree Parameters

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

411

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


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

448

449 450 451 452 453 454 455 456

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