App.purs 9.47 KB
Newer Older
1
module Gargantext.Components.App where
James Laver's avatar
James Laver committed
2

3
import Prelude
4

5
import Data.Array (fromFoldable)
6
import Data.Foldable (intercalate)
7
import Data.Maybe (Maybe(..), maybe')
James Laver's avatar
James Laver committed
8 9
import Data.Tuple (fst, snd)
import Gargantext.Components.Data.Lang (Lang(..))
10
import Gargantext.Components.Folder (folder)
11
import Gargantext.Components.Forest (forest)
12
import Gargantext.Components.GraphExplorer (explorerLayout)
13
import Gargantext.Components.Login (login)
14
import Gargantext.Components.Nodes.Annuaire (annuaireLayout)
15
import Gargantext.Components.Nodes.Annuaire.User.Contacts (annuaireUserLayout, userLayout)
16 17
import Gargantext.Components.Nodes.Corpus (corpusLayout)
import Gargantext.Components.Nodes.Corpus.Dashboard (dashboardLayout)
18 19
import Gargantext.Components.Nodes.Corpus.Document (documentLayout)
import Gargantext.Components.Nodes.Home (homeLayout)
20 21
import Gargantext.Components.Nodes.Lists (listsLayout)
import Gargantext.Components.Nodes.Texts (textsLayout)
22
import Gargantext.Config (defaultFrontends, defaultBackends)
23
import Gargantext.Ends (Frontends)
24
import Gargantext.Hooks.Router (useHashRouter)
25 26
import Gargantext.Router (router)
import Gargantext.Routes (AppRoute(..))
27
import Gargantext.Sessions (Sessions, useSessions)
28 29 30 31
import Gargantext.Sessions as Sessions
import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix.DOM.HTML as H
James Laver's avatar
James Laver committed
32

33
-- TODO (what does this mean?)
James Laver's avatar
James Laver committed
34 35
-- tree changes endConfig state => trigger endConfig change in outerLayout, layoutFooter etc

36 37 38 39 40 41 42
app :: {} -> R.Element
app props = R.createElement appCpt props []

appCpt :: R.Component ()
appCpt = R.hooksComponent "G.C.App.app" cpt where
  frontends = defaultFrontends
  cpt _ _ = do
43 44
    sessions   <- useSessions
    route      <- useHashRouter router Home
45

46
    showLogin  <- R.useState' false
47
    showCorpus <- R.useState' false
48

49
    let forested      = forestLayout frontends (fst sessions) (fst route) (snd showLogin)
50 51
    let mCurrentRoute = fst route
    let backends      = fromFoldable defaultBackends
52
    let withSession = \sid f -> maybe' (\_ -> forested $ homeLayout EN) f $ Sessions.lookup sid (fst sessions)
53
    pure $ case fst showLogin of
54
      true -> forested $ login { sessions, backends, visible: showLogin }
55
      false ->
56 57 58
        case fst route of
          Home  -> forested $ homeLayout EN
          Login -> login { sessions, backends, visible: showLogin }
59
          Folder sid _      -> withSession sid $ \_ -> forested (folder {})
60
          Corpus sid nodeId -> withSession sid $ \session -> forested $ corpusLayout { nodeId, session }
61 62 63
          Texts sid nodeId  -> withSession sid $ \session -> forested $ textsLayout { nodeId, session, frontends }
          Lists sid nodeId  -> withSession sid $ \session -> forested $ listsLayout { nodeId, session }
          Dashboard sid _nodeId  -> withSession sid $ \session -> forested $ dashboardLayout {}
64
          Annuaire sid nodeId    -> withSession sid $ \session -> forested $ annuaireLayout { frontends, nodeId, session }
65
          UserPage sid nodeId    -> withSession sid $ \session -> forested $ userLayout { frontends, nodeId, session }
66
          ContactPage sid aId nodeId -> withSession sid $ \session -> forested $ annuaireUserLayout { annuaireId: aId, frontends, nodeId, session }
67 68 69 70 71 72 73 74 75 76
          CorpusDocument sid corpusId listId nodeId ->
            withSession sid $ \session -> forested $ documentLayout { nodeId, listId, session, corpusId: Just corpusId }
          Document sid listId nodeId ->
            withSession sid $
              \session -> forested $ documentLayout { nodeId, listId, session, corpusId: Nothing }
          PGraphExplorer sid graphId ->
            withSession sid $
              \session ->
                simpleLayout $
                  explorerLayout { graphId, mCurrentRoute, session
77
                                 , sessions: (fst sessions), frontends
78
                                 , showLogin }
79 80

forestLayout :: Frontends -> Sessions -> AppRoute -> R2.Setter Boolean -> R.Element -> R.Element
81
forestLayout frontends sessions route showLogin child = do
82
  R.fragment [ topBar {}, R2.row [main], footer {} ]
James Laver's avatar
James Laver committed
83
  where
84
    main =
James Laver's avatar
James Laver committed
85 86
      R.fragment
      [ H.div {className: "col-md-2", style: {paddingTop: "60px"}}
87
              [ forest {sessions, route, frontends, showLogin } ]
88 89
      , mainPage child
      ]
James Laver's avatar
James Laver committed
90 91

-- Simple layout does not accommodate the tree
92 93
simpleLayout :: R.Element -> R.Element
simpleLayout child = R.fragment [ topBar {}, child, footer {}]
James Laver's avatar
James Laver committed
94

95 96 97
mainPage :: R.Element -> R.Element
mainPage child =
  H.div {className: "col-md-10"}
James Laver's avatar
James Laver committed
98 99 100
  [ H.div {id: "page-wrapper"}
    [ H.div {className: "container-fluid"} [ child ] ] ]

101 102
topBar :: {} -> R.Element
topBar _ =
James Laver's avatar
James Laver committed
103 104 105 106 107 108
  H.div { id: "dafixedtop", role: "navigation"
        , className: "navbar navbar-inverse navbar-fixed-top" }
  [ H.div { className: "container-fluid" }
    [ H.div { className: "navbar-inner" }
      [ logo
      , H.div { className: "collapse navbar-collapse" }
109 110
        [ divDropdownLeft ] ] ] ]
      -- SB.searchBar {session, databases: allDatabases}
James Laver's avatar
James Laver committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220

logo :: R.Element
logo =
  H.a { className, href: "#/" }
  [ H.img { src, title, width: "30", height: "28" } ]
  where
    className = "navbar-brand logoSmall"
    src = "images/logoSmall.png"
    title = "Back to home."

divDropdownLeft :: R.Element
divDropdownLeft =
  divDropdownLeft' $
    LiNav { title : "About Gargantext"
          , href  : "#"
          , icon  : "glyphicon glyphicon-info-sign"
          , text  : "Info" }

divDropdownLeft' :: LiNav -> R.Element
divDropdownLeft' mb =
  H.ul {className: "nav navbar-nav"}
  [ H.ul {className: "nav navbar-nav pull-left"}
    [ H.li {className: "dropdown"} [ menuButton mb, menuElements' ] ] ]

menuButton :: LiNav -> R.Element
menuButton (LiNav { title, href, icon, text } ) =
  H.a { className: "dropdown-toggle navbar-text"
      , data: {toggle: "dropdown"}
      , href, title
      , role: "button" }
  [ H.span { aria: {hidden : true}, className: icon } []
  , H.text (" " <> text) ]

menuElements' :: R.Element
menuElements' = menuElements-- title, icon, text
  [ -- ===========================================================
    [ LiNav { title : "Quick start, tutorials and methodology"
            , href  : "https://iscpif.fr/gargantext/your-first-map/"
            , icon  : "glyphicon glyphicon-book"
            , text  : "Documentation"
            }
    , LiNav { title : "Report bug here"
            , href  : "https://www.iscpif.fr/gargantext/feedback-and-bug-reports/"
            , icon  : "glyphicon glyphicon-bullhorn"
            , text  : "Feedback"
            }
    ]
    , -----------------------------------------------------------
    [ LiNav { title : "Interactive chat"
            , href  : "https://chat.iscpif.fr/channel/gargantext"
            , icon  : "fab fa-rocketchat"
            , text  : "Chat"
            }
    , LiNav { title : "Asynchronous discussions"
            , href  : "https://discourse.iscpif.fr/c/gargantext"
            , icon  : "fab fa-discourse"
            , text  : "Forum"
            }
    ]
    ,------------------------------------------------------------
    [ LiNav { title : "More about us (you)"
            , href  : "https://iscpif.fr"
            , icon  : "glyphicon glyphicon-question-sign"
            , text  : "About"
            }
    ]
  ] -- ===========================================================

-- | Menu in the sidebar, syntactic sugar
menuElements :: Array (Array LiNav) -> R.Element
menuElements ns = dropDown $ intercalate divider $ map (map liNav) ns
  where
    dropDown :: Array R.Element -> R.Element
    dropDown = H.ul {className: "dropdown-menu"}

    divider :: Array R.Element
    divider = [H.li {className: "divider"} []]

-- | surgar for target : "blank"
--data LiNav_ = LiNav_ { title  :: String
--                     , href   :: String
--                     , icon   :: String
--                     , text   :: String
--                     , target :: String
--                     }

data LiNav = LiNav { title :: String
                   , href  :: String
                   , icon  :: String
                   , text  :: String
                   }

liNav :: LiNav -> R.Element
liNav (LiNav { title : title'
             , href  : href'
             , icon  : icon'
             , text  : text'
             }
      ) = H.li {} [ H.a { tabIndex: (-1)
                        , target: "blank"
                        , title: title'
                        , href: href'
                        } [ H.span { className: icon' } []
                          , H.text $ " " <> text'
                          ]
                  ]

footer :: {} -> R.Element
footer props = R.createElement footerCpt props []

221
footerCpt :: R.Component ()
James Laver's avatar
James Laver committed
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
footerCpt = R.staticComponent "G.C.Layout.footer" cpt
  where
    cpt _ _ =
      H.div { className: "container" }
      [ H.hr {}
      , H.footer {}
        [ H.p {}
          [ H.text "Gargantext "
          , H.span {className: "glyphicon glyphicon-registration-mark"} []
          , H.text ", version 4.0"
          , H.a { href: "http://www.cnrs.fr"
                , target: "blank"
                , title: "Project hosted by CNRS."
                }
            [ H.text ", Copyrights "
            , H.span { className: "glyphicon glyphicon-copyright-mark" } []
            , H.text " CNRS 2017-Present"
            ]
          , H.a { href: "http://gitlab.iscpif.fr/humanities/gargantext/blob/stable/LICENSE"
                , target: "blank"
                , title: "Legal instructions of the project."
                }
            [ H.text ", Licences aGPLV3 and CECILL variant Affero compliant" ]
          , H.text "."
          ]]
        ]