Router.purs 1.92 KB
Newer Older
1
module Gargantext.Router where
2

3
import Gargantext.Prelude
Abinaya Sudhir's avatar
Abinaya Sudhir committed
4

5
import Data.Foldable (oneOf)
6
import Data.Int (floor)
Sudhir Kumar's avatar
Sudhir Kumar committed
7
import Routing.Match (Match, lit, num)
8 9 10 11

data Routes
  = Home
  | Login
12 13
  | Folder             Int
    | Corpus           Int
14
      | Document       Int Int
15
      | CorpusDocument Int Int Int
16
      | PGraphExplorer Int
17
      | Dashboard
18 19
      | Texts          Int
      | Lists          Int
20 21
    | Annuaire         Int
      | UserPage       Int
22
      | ContactPage       Int
23

24
routing :: Match Routes
25 26 27
routing = oneOf
  [ Login            <$   route "login"
  , Folder           <$> (route "folder"     *> int)
28
  , CorpusDocument   <$> (route "corpus" *> int) <*> (lit "list" *> int) <*> (lit "document" *> int)
29 30 31 32
  , Corpus           <$> (route "corpus"     *> int)
     , Document       <$> (route "list" *> int) <*> (lit "document" *> int)
     , Dashboard      <$   route "dashboard"
     , PGraphExplorer <$> (route "graph"      *> int)
33 34
     , Texts          <$> (route "texts" *> int)
     , Lists          <$> (route "lists" *> int)
35 36 37 38 39
  , Annuaire         <$> (route "annuaire"   *> int)
    , UserPage          <$> (route "user"    *> int)
    , ContactPage       <$> (route "contact" *> int)
  , Home             <$   lit ""
  ]
40

41 42
 where
    route str      = lit "" *> lit str
43

44 45
    int :: Match Int
    int = floor <$> num
46

47
instance showRoutes :: Show Routes where
Alexandre Delanoë's avatar
Alexandre Delanoë committed
48
  show Login            = "Login"
49 50
  show (UserPage i)     = "User"     <> show i
  show (ContactPage i)  = "Contact"  <> show i
51
  show (CorpusDocument _ _ i)     = "Document" <> show i
52
  show (Document _ i)     = "Document" <> show i
53
  show (Corpus i)       = "Corpus"   <> show i
54 55
  show (Annuaire i)     = "Annuaire" <> show i
  show (Folder   i)     = "Folder"   <> show i
56
  show Dashboard        = "Dashboard"
57
  show (PGraphExplorer i) = "graphExplorer" <> show i
58 59
  show (Texts i)          = "texts" <> show i
  show (Lists i)          = "lists" <> show i
Alexandre Delanoë's avatar
Alexandre Delanoë committed
60
  show Home             = "Home"