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

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

data AppRoute
  = Home
  | Login
10 11 12 13 14 15 16 17 18 19
  | Folder SessionId Int
  | Corpus SessionId  Int
    | 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
20
    | ContactPage    SessionId Int Int
21

22 23
derive instance eqAppRoute :: Eq AppRoute

24 25
type AnnuaireId = Int
type ContactId = Int
26 27 28 29 30 31 32

data SessionRoute
  = Tab TabType (Maybe Id)
  | Children NodeType Offset Limit (Maybe OrderBy) (Maybe Id)
  | GetNgrams NgramsGetOpts (Maybe Id)
  | PutNgrams TabType (Maybe ListId) (Maybe TermList) (Maybe Id)
  -- ^ This name is not good. In particular this URL is used both in PUT and POST.
33
  | NodeAPI NodeType (Maybe Id) String
34 35 36 37 38 39
  | ListDocument (Maybe ListId) (Maybe Id)
  | Search SearchOpts (Maybe Id)
  | CorpusMetrics CorpusMetricOpts  (Maybe Id)
  | Chart ChartOpts (Maybe Id)

instance showAppRoute :: Show AppRoute where
40 41 42 43 44 45
  show Home                     = "Home"
  show Login                    = "Login"
  show (Folder s i)             = "Folder"   <> show i <> " (" <> show s <> ")"
  show (Corpus s i)             = "Corpus"   <> show i <> " (" <> show s <> ")"
  show (Document _ s i)         = "Document" <> show i <> " (" <> show s <> ")"
  show (CorpusDocument s _ _ i) = "CorpusDocument" <> show i <> " (" <> show s <> ")"
46 47 48 49
  show (PGraphExplorer s i)     = "graphExplorer"  <> show i <> " (" <> show s <> ")"
  show (Dashboard      s i)     = "Dashboard"      <> show i <> " (" <> show s <> ")"
  show (Texts s i)              = "texts"    <> show i <> " (" <> show s <> ")"
  show (Lists s i)              = "lists"    <> show i <> " (" <> show s <> ")"
50 51
  show (Annuaire s i)           = "Annuaire" <> show i <> " (" <> show s <> ")"
  show (UserPage s i)           = "User"     <> show i <> " (" <> show s <> ")"
52
  show (ContactPage s a i)      = "Contact"  <> show a <> "::" <> show i <> " (" <> show s <> ")"
53 54

appPath :: AppRoute -> String
55 56 57
appPath Home                 = ""
appPath Login                = "login"
appPath (Folder s i)         = "folder/"     <> show s <> "/" <> show i
58
appPath (CorpusDocument s c l i) = "corpus/" <> show s <> "/" <> show c <> "/list/" <> show l <> "/document/" <> show i
59 60 61 62 63 64 65 66
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
67
appPath (ContactPage s a i)  = "annuaire/"   <> show s <> "/" <> show a <> "/contact/" <> show i