Settings.purs 16.1 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
                | Publish { subTreeParams :: SubTreeParams }
20 21
                | Add    (Array NodeType)
                | Merge { subTreeParams :: SubTreeParams }
22
                | Move  { subTreeParams :: SubTreeParams }
23
                | Link  { subTreeParams :: SubTreeParams }
24
                | Clone
25
                | AddingContact
26
                | CloseNodePopover
27
                | WriteNodesDocuments  -- https://gitlab.iscpif.fr/gargantext/purescript-gargantext/issues/331  
28 29

------------------------------------------------------------------------
30
instance Eq NodeAction where
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  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
  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
49

50
instance Show NodeAction where
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
  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"
  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"
68 69

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

------------------------------------------------------------------------
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
102
              , buttons : [ Add [ FolderPrivate
103 104 105
                                , FolderShared
                                , FolderPublic
                                ]
106
                          , Delete
107
                          ]
108 109 110 111 112 113 114 115 116
              }

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

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

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

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

settingsBox Folder =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation Folder
              , buttons : [ Add [ Corpus
                                , Folder
                                , Annuaire
168 169
                                , NodeFrameWrite
                                , NodeFrameCalc
170
                                ]
171
                          , Move moveParameters
172 173 174 175 176 177 178 179
                          , Delete
                          ]
              }

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

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

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

222 223 224 225 226 227 228 229 230 231
settingsBox Phylo =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation Phylo
              , buttons : [ Delete
                          ]
              }



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

241 242 243 244 245 246 247 248
settingsBox (NodePublic Dashboard) =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation Dashboard
              , buttons : [ Delete
                          ]
              }

249 250 251 252 253 254 255 256 257 258
settingsBox (NodePublic NodeFile) =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation NodeFile
              , buttons : [ Delete
                          ]
              }



259 260 261 262
settingsBox (NodePublic FolderPublic) =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation FolderPublic
263 264
              , buttons : [ Add [FolderPublic]
                          , Delete
265 266
                          ]
              }
267 268


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

settingsBox Dashboard =
  SettingsBox { show : true
              , edit : false
              , doc  : Documentation Dashboard
296
              , buttons : [ Refresh
297
                          , Publish publishParams
298 299
                          , Delete
                          ]
300 301 302 303
              }

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

314 315 316 317 318 319 320 321

settingsBox NodeFrameWrite =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation NodeFrameWrite
              , buttons : [ Add [ NodeFrameWrite
                                , NodeFrameCalc
                                ]
322
                          , Move moveFrameParameters
323
                          , Delete
324 325 326 327 328 329 330 331
                          ]
              }


settingsBox NodeFrameCalc =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation NodeFrameCalc
332 333
              , buttons : [ Upload
                          , Add [ NodeFrameCalc
334 335
                                , NodeFrameWrite
                                ]
336
                          , Move moveFrameParameters
337
                          , Delete
338 339 340
                          ]
              }

341
settingsBox NodeFrameNotebook =
342 343
  SettingsBox { show : true
              , edit : true
344
              , doc  : Documentation NodeFrameNotebook
345 346
              , buttons : [ Add [ NodeFrameCalc
                                , NodeFrameWrite
347
                                , NodeFrameNotebook
348 349 350 351 352 353 354
                                ]
                          , Move moveFrameParameters
                          , Delete
                          ]
              }


355 356 357 358 359 360 361 362 363 364 365 366 367
settingsBox NodeFrameVisio =
  SettingsBox { show : true
              , edit : true
              , doc  : Documentation NodeFrameVisio
              , buttons : [ Add [ NodeFrameVisio
                                , NodeFrameWrite
                                , NodeFrameCalc
                                ]
                          , Delete
                          ]
              }


368 369 370 371
settingsBox NodeFile =
  SettingsBox { show: true
              , edit: true
              , doc: Documentation NodeFile
372 373
              , buttons: [ Publish publishParams
                         , Delete ]
374 375 376
              }


377 378 379 380 381 382
settingsBox _ =
  SettingsBox { show : false
              , edit : false
              , doc  : Documentation NodeUser
              , buttons : []
              }
383

384 385
-- | SubTree Parameters

386 387 388 389 390 391 392 393
moveParameters = { subTreeParams : SubTreeParams 
                                 { showtypes: [ FolderPrivate
                                              , FolderShared
                                              , Team
                                              , FolderPublic
                                              , Folder
                                              ]
                                 , valitypes: [ FolderPrivate
394 395
                                              , Team
                                              -- , FolderPublic
396 397 398 399 400
                                              , Folder
                                              ]
                                 }
                  }

401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423

moveFrameParameters = { subTreeParams : SubTreeParams 
                                 { showtypes: [ FolderPrivate
                                              , FolderShared
                                              , Team
                                              , FolderPublic
                                              , Folder
                                              , Corpus
                                              , NodeFrameWrite
                                              , NodeFrameCalc
                                              ]
                                 , valitypes: [ FolderPrivate
                                              , Team
                                              -- , FolderPublic
                                              , Folder
                                              , Corpus
                                              , NodeFrameWrite
                                              , NodeFrameCalc
                                              ]
                                 }
                  }


424 425
linkParams :: NodeType -> {subTreeParams :: SubTreeParams}
linkParams nodeType =  { subTreeParams : SubTreeParams 
426 427 428 429 430
                              { showtypes: [ FolderPrivate
                                           , FolderShared
                                           , Team
                                           , FolderPublic
                                           , Folder
431
                                           , nodeType
432
                                           ]
433
                              , valitypes: [ nodeType
434 435
                                           ]
                              }
436 437
                      }

438

439 440 441 442 443 444 445 446 447 448

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