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

import Prelude
4

5
import Data.Maybe (Maybe)
6
import Gargantext.Types (ChartOpts, CorpusMetricOpts, CTabNgramType, Id, Limit, ListId, NgramsGetOpts, NodeType, Offset, OrderBy, SearchOpts, SessionId, TabSubType, TabType, TermList, NgramsGetTableAllOpts)
7 8 9 10

data AppRoute
  = Home
  | Login
11
  | Folder SessionId Int
12 13 14
  | FolderPrivate SessionId Int
  | FolderPublic SessionId Int
  | FolderShared SessionId Int
15 16
    | Team SessionId Int
  | Corpus SessionId Int
17 18 19 20 21 22 23 24
    | Document       SessionId Int Int
    | CorpusDocument SessionId Int Int Int
    | PGraphExplorer SessionId Int
    | Dashboard      SessionId Int
    | Texts          SessionId Int
    | Lists          SessionId Int
  | Annuaire SessionId Int
    | UserPage       SessionId Int
25
    | ContactPage    SessionId Int Int
26

27 28
derive instance eqAppRoute :: Eq AppRoute

29 30
type AnnuaireId = Int
type ContactId = Int
31 32 33 34 35

data SessionRoute
  = Tab TabType (Maybe Id)
  | Children NodeType Offset Limit (Maybe OrderBy) (Maybe Id)
  | GetNgrams NgramsGetOpts (Maybe Id)
36
  | GetNgramsTableAll NgramsGetTableAllOpts (Maybe Id)
Alexandre Delanoë's avatar
Alexandre Delanoë committed
37 38
  | PutNgrams TabType (Maybe ListId) (Maybe TermList) (Maybe Id)
  -- ^ This name is not good. In particular this URL is used both in PUT and POST.
39
  | RecomputeNgrams (TabSubType CTabNgramType) Id ListId
40
  | NodeAPI NodeType (Maybe Id) String
41
  | GraphAPI Id String
42
  | ListsRoute ListId
43 44 45 46 47 48
  | ListDocument (Maybe ListId) (Maybe Id)
  | Search SearchOpts (Maybe Id)
  | CorpusMetrics CorpusMetricOpts  (Maybe Id)
  | Chart ChartOpts (Maybe Id)

instance showAppRoute :: Show AppRoute where
49 50
  show Home                     = "Home"
  show Login                    = "Login"
51 52 53 54 55 56 57
  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 <> ")"
  show (Document    _ s i)      = "Document"       <> show i <> " (" <> show s <> ")"
58
  show (CorpusDocument s _ _ i) = "CorpusDocument" <> show i <> " (" <> show s <> ")"
59 60
  show (PGraphExplorer s i)     = "graphExplorer"  <> show i <> " (" <> show s <> ")"
  show (Dashboard      s i)     = "Dashboard"      <> show i <> " (" <> show s <> ")"
61 62 63 64 65
  show (Texts          s i)     = "texts"          <> show i <> " (" <> show s <> ")"
  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 <> ")"
66 67

appPath :: AppRoute -> String
68 69
appPath Home                 = ""
appPath Login                = "login"
70 71 72 73 74
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
75
appPath (CorpusDocument s c l i) = "corpus/" <> show s <> "/" <> show c <> "/list/" <> show l <> "/document/" <> show i
76 77 78 79 80 81 82 83
appPath (Corpus s i)         = "corpus/"     <> show s <> "/" <> show i
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
appPath (Texts s i)          = "texts/"      <> show s <> "/" <> show i
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
84
appPath (ContactPage s a i)  = "annuaire/"   <> show s <> "/" <> show a <> "/contact/" <> show i