Node.purs 5.48 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 22
------------------------------------------------------------------------
------------------------------------------------------------------------
data NodeAction = Documentation NodeType
                | SearchBox
                | Download | Upload | Refresh
                | Move     | Clone  | Delete
23
                | Share    | Link NodeType
24 25 26 27 28 29 30 31 32 33 34 35 36
                | Add (Array NodeType)


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
37
  eq (Link x) (Link y) = true && (x == y)
38 39 40
  eq (Add x) (Add y)   = true && (x == y)
  eq _ _               = false

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
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"
  show (Link x)          = "Link to " <> show x
  show (Add xs)          = foldl (\a b -> a <> show b) "Add " xs


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"
glyphiconNodeAction _                 = ""


66 67
------------------------------------------------------------------------
------------------------------------------------------------------------
68 69 70
data SettingsBox =
  SettingsBox { show    :: Boolean
              , edit    :: Boolean
71
              , doc     :: NodeAction
72 73
              , buttons :: Array NodeAction
              }
74
------------------------------------------------------------------------
75 76

settingsBox :: NodeType -> SettingsBox
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
settingsBox NodeUser = SettingsBox {
    show: true
  , edit : false
  , doc  : Documentation NodeUser
  , buttons : [ SearchBox
              , Delete
              ]
  }

settingsBox FolderPrivate = SettingsBox {
    show: true
  , edit : false
  , doc  : Documentation FolderPrivate
  , buttons : [ SearchBox
              , Add [ Corpus
                    , Folder
                    , Annuaire
                    ]
95
              ]
96 97 98 99
  }

settingsBox Team = SettingsBox {
    show: true
100
  , edit : true
101 102 103 104 105 106 107 108 109 110 111 112 113
  , doc  : Documentation Team
  , buttons : [ SearchBox
              , Add [ Corpus
                    , Folder
                    , Annuaire
                    ]
              , Delete]
  }

settingsBox FolderShared = SettingsBox {
    show: true
  , edit : true
  , doc  : Documentation FolderShared
114
  , buttons : [ Add [Team, Folder]
115 116 117 118 119 120 121 122
              ]
  }

settingsBox FolderPublic = SettingsBox {
    show: true
  , edit : false
  , doc  : Documentation FolderPublic
  , buttons : [{-, SearchBox
123 124
                                                    , Add [ Corpus
                                                          , Folder
125
                                                          ]-}
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
    ]
  }

settingsBox Folder = SettingsBox {
    show: true
  , edit : true
  , doc  : Documentation Folder
  , buttons : [ SearchBox
              , Add [ Corpus
                    , Folder
                    , Annuaire
                    ]
              , Delete
              ]
  }

settingsBox Corpus = SettingsBox {
    show: true
  , edit : true
  , doc  : Documentation Corpus
  , buttons : [ SearchBox
              , Add [ NodeList
                    , Graph
                    , Dashboard
                    ]
              , Upload
              , Download
                --, Share
                --, Move
                --, Clone
              , Link Annuaire
              , Delete
              ]
  }

settingsBox Texts = SettingsBox {
    show: true
  , edit : false
  , doc  : Documentation Texts
  , buttons : [ Upload
              , Download
              , Delete
              ]
  }

settingsBox Graph = SettingsBox {
    show: true
  , edit : false
  , doc  : Documentation Graph
  , buttons : [ Documentation Graph
              , Download
              , Delete
              ]
  }

settingsBox NodeList = SettingsBox {
    show: true
  , edit : false
  , doc  : Documentation NodeList
  , buttons : [ Upload
              , Download
              , Delete
              ]
  }

settingsBox Dashboard = SettingsBox {
    show: true
  , edit : false
  , doc  : Documentation Dashboard
  , buttons : [Delete]
  }

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

settingsBox _ = SettingsBox {
    show: false
  , edit : false
  , doc  : Documentation NodeUser
  , buttons : []
  }