Routes.purs 7.58 KB
Newer Older
1 2 3
module Gargantext.Routes where

import Prelude
4

5
import Data.Maybe (Maybe(..))
6
import Data.UUID (UUID)
Karen Konou's avatar
Karen Konou committed
7
import Data.Map as M
8
import Gargantext.Types (ChartOpts, ChartType, CorpusMetricOpts, CTabNgramType, Id, Limit, ListId, DocId, NgramsGetOpts, NgramsGetTableAllOpts, NodeType, Offset, OrderBy, SearchOpts, SessionId, TabSubType, TabType, TermList)
9
import Gargantext.Types as GT
10 11

data AppRoute
12
  = Annuaire       SessionId Int
13
  | ContactPage    SessionId Int Int
14
  | Corpus         SessionId Int
15
  | CorpusCode     SessionId Int
16 17 18
  | CorpusDocument SessionId Int Int Int
  | Dashboard      SessionId Int
  | Document       SessionId Int Int
19 20 21 22
  | Folder         SessionId Int
  | FolderPrivate  SessionId Int
  | FolderPublic   SessionId Int
  | FolderShared   SessionId Int
23 24 25
  | Home
  | Lists          SessionId Int
  | Login
26
  | PGraphExplorer  SessionId Int
27
  | PhyloExplorer   SessionId Int
28
  | RouteFile       SessionId Int
29
  | RouteFrameCalc  SessionId Int
30
  | RouteFrameCode  SessionId Int
31
  | RouteFrameWrite SessionId Int
32
  | RouteFrameVisio SessionId Int
33
  | Team            SessionId Int
34
  | NodeTexts       SessionId Int
35
  | UserPage        SessionId Int
Karen Konou's avatar
Karen Konou committed
36
  | ForgotPassword  (M.Map String String)
37

38

39
derive instance Eq AppRoute
40

41 42 43 44
data SessionRoute
  = Tab TabType (Maybe Id)
  | Children NodeType Offset Limit (Maybe OrderBy) (Maybe Id)
  | GetNgrams NgramsGetOpts (Maybe Id)
45
  | GetNgramsTableAll NgramsGetTableAllOpts (Maybe Id)
46
  | GetNgramsTableVersion { listId :: ListId, tabType :: TabType } (Maybe Id)
Alexandre Delanoë's avatar
Alexandre Delanoë committed
47
  | PutNgrams TabType (Maybe ListId) (Maybe TermList) (Maybe Id)
48
  | PostNgramsChartsAsync (Maybe Id)
Alexandre Delanoë's avatar
Alexandre Delanoë committed
49
  -- ^ This name is not good. In particular this URL is used both in PUT and POST.
50 51 52
  | RecomputeNgrams   (TabSubType CTabNgramType) Id ListId
  | RecomputeListChart ChartType  CTabNgramType  Id ListId
  | NodeAPI       NodeType (Maybe Id) String
53
  | TreeFirstLevel (Maybe Id) String
54 55
  | GraphAPI      Id String
  | ListsRoute    ListId
56
  | ListDocument (Maybe ListId) (Maybe DocId)
57
  | Search        SearchOpts (Maybe Id)
58
  | CorpusMetrics CorpusMetricOpts  (Maybe Id)
59
  | CorpusMetricsHash { listId :: ListId, tabType :: TabType }  (Maybe Id)
60
  | Chart ChartOpts (Maybe Id)
61
  | ChartHash { chartType :: ChartType, listId :: Maybe ListId, tabType :: TabType } (Maybe Id)
62
  -- | AnnuaireContact AnnuaireId DocId
63
  | PhyloAPI Id
64

65
instance Show AppRoute where
66 67
  show Home                     = "Home"
  show Login                    = "Login"
Karen Konou's avatar
Karen Konou committed
68
  show (ForgotPassword  u)      = "ForgotPassword" <> show u
69 70 71 72 73 74
  show (Folder        s i)      = "Folder"         <> show i <> " (" <> show s <> ")"
  show (FolderPrivate s i)      = "FolderPrivate"  <> show i <> " (" <> show s <> ")"
  show (FolderPublic  s i)      = "FolderPublic"   <> show i <> " (" <> show s <> ")"
  show (FolderShared  s i)      = "FolderShared"   <> show i <> " (" <> show s <> ")"
  show (Team          s i)      = "Team"           <> show i <> " (" <> show s <> ")"
  show (Corpus        s i)      = "Corpus"         <> show i <> " (" <> show s <> ")"
75
  show (CorpusCode    s i)      = "CorpusCode"     <> show i <> " (" <> show s <> ")"
76
  show (Document    _ s i)      = "Document"       <> show i <> " (" <> show s <> ")"
77
  show (CorpusDocument s _ _ i) = "CorpusDocument" <> show i <> " (" <> show s <> ")"
78
  show (PGraphExplorer s i)     = "graphExplorer"  <> show i <> " (" <> show s <> ")"
79
  show (PhyloExplorer  s i)     = "phyloExplorer"  <> show i <> " (" <> show s <> ")"
80
  show (Dashboard      s i)     = "Dashboard"      <> show i <> " (" <> show s <> ")"
81
  show (NodeTexts      s i)     = "texts"          <> show i <> " (" <> show s <> ")"
82 83 84 85
  show (Lists          s i)     = "lists"          <> show i <> " (" <> show s <> ")"
  show (Annuaire       s i)     = "Annuaire"       <> show i <> " (" <> show s <> ")"
  show (UserPage       s i)     = "User"           <> show i <> " (" <> show s <> ")"
  show (ContactPage  s a i)     = "Contact"        <> show a <> "::" <> show i <> " (" <> show s <> ")"
86 87
  show (RouteFrameWrite s i)    = "write"          <> show i <> " (" <> show s <> ")"
  show (RouteFrameCalc  s i)    = "calc"           <> show i <> " (" <> show s <> ")"
88
  show (RouteFrameCode  s i)    = "code"           <> show i <> " (" <> show s <> ")"
89
  show (RouteFrameVisio s i)    = "visio"          <> show i <> " (" <> show s <> ")"
90
  show (RouteFile       s i)    = "file"           <> show i <> " (" <> show s <> ")"
91

92 93

appPath :: AppRoute -> String
94 95
appPath Home                     = ""
appPath Login                    = "login"
Karen Konou's avatar
Karen Konou committed
96 97 98 99 100 101
appPath (ForgotPassword u)       = "forgotPassword/" <> show u
appPath (Folder s i)             = "folder/"         <> show s <> "/" <> show i
appPath (FolderPrivate s i)      = "folderPrivate/"  <> show s <> "/" <> show i
appPath (FolderPublic s i)       = "folderPublic/"   <> show s <> "/" <> show i
appPath (FolderShared s i)       = "folderShared/"   <> show s <> "/" <> show i
appPath (Team s i)               = "team/"           <> show s <> "/" <> show i
102
appPath (CorpusDocument s c l i) = "corpus/" <> show s <> "/" <> show c <> "/list/" <> show l <> "/document/" <> show i
103
appPath (Corpus s i)             = "corpus/"     <> show s <> "/" <> show i
104
appPath (CorpusCode s i)         = "corpusCode/" <> show s <> "/" <> show i
105 106 107
appPath (Document s l i)         = "list/"       <> show s <> "/" <> show l <> "/document/" <> show i
appPath (Dashboard s i)          = "dashboard/"  <> show s <> "/" <> show i
appPath (PGraphExplorer s i)     = "graph/"      <> show s <> "/" <> show i
108
appPath (PhyloExplorer  s i)     = "phylo/"      <> show s <> "/" <> show i
109
appPath (NodeTexts s i)          = "texts/"      <> show s <> "/" <> show i
110 111 112 113 114
appPath (Lists s i)              = "lists/"      <> show s <> "/" <> show i
appPath (Annuaire s i)           = "annuaire/"   <> show s <> "/" <> show i
appPath (UserPage s i)           = "user/"       <> show s <> "/" <> show i
appPath (ContactPage s a i)      = "annuaire/"   <> show s <> "/" <> show a <> "/contact/" <> show i
appPath (RouteFrameWrite s i)    = "write/"     <> show s <> "/" <> show i
115 116 117
appPath (RouteFrameCalc  s i)     = "calc/"      <> show s <> "/" <> show i
appPath (RouteFrameCode  s i)     = "code/"      <> show s <> "/" <> show i
appPath (RouteFrameVisio s i)     = "visio/"      <> show s <> "/" <> show i
118
appPath (RouteFile s i)          = "file/"      <> show s <> "/" <> show i
119

120
nodeTypeAppRoute :: NodeType -> SessionId -> Int -> Maybe AppRoute
Karen Konou's avatar
Karen Konou committed
121 122 123 124 125 126 127 128
nodeTypeAppRoute GT.Annuaire s i       = Just $ Annuaire s i
nodeTypeAppRoute GT.Corpus s i         = Just $ Corpus s i
nodeTypeAppRoute GT.Dashboard s i      = Just $ Dashboard s i
nodeTypeAppRoute GT.Folder s i         = Just $ Folder s i
nodeTypeAppRoute GT.FolderPrivate s i  = Just $ FolderPrivate s i
nodeTypeAppRoute GT.FolderPublic s i   = Just $ FolderPublic s i
nodeTypeAppRoute GT.FolderShared s i   = Just $ FolderShared s i
nodeTypeAppRoute GT.Graph s i          = Just $ PGraphExplorer s i
129
nodeTypeAppRoute GT.Phylo s i          = Just $ PhyloExplorer  s i
Karen Konou's avatar
Karen Konou committed
130 131 132 133 134
nodeTypeAppRoute GT.NodeContact s i    = Just $ Annuaire s i
nodeTypeAppRoute GT.NodeFile s i       = Just $ RouteFile s i
nodeTypeAppRoute GT.NodeList s i       = Just $ Lists s i
nodeTypeAppRoute GT.NodeUser s i       = Just $ UserPage s i
nodeTypeAppRoute GT.Team s i           = Just $ Team s i
135
nodeTypeAppRoute GT.NodeTexts s i      = Just $ NodeTexts s i
Karen Konou's avatar
Karen Konou committed
136
nodeTypeAppRoute GT.NodeFrameWrite s i = Just $ RouteFrameWrite s i
137 138
nodeTypeAppRoute GT.NodeFrameCalc  s i = Just $ RouteFrameCalc  s i
nodeTypeAppRoute GT.NodeFrameVisio s i = Just $ RouteFrameVisio s i
Karen Konou's avatar
Karen Konou committed
139
nodeTypeAppRoute _ _ _                 = Nothing
140 141 142 143 144 145 146 147


------------------------------------------------------

type Tile =
  ( id    :: UUID
  , route :: AppRoute
  )