App.purs 9.5 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
import Data.Tuple (fst, snd)
9 10 11 12
import Reactix as R
import Reactix.DOM.HTML as H

import Gargantext.Components.Data.Lang (LandingLang(..))
13
import Gargantext.Components.Folder (folder)
14
import Gargantext.Components.Forest (forest)
15
import Gargantext.Components.GraphExplorer (explorerLayout)
16
import Gargantext.Components.Login (login)
17
import Gargantext.Components.Nodes.Annuaire (annuaireLayout)
18
import Gargantext.Components.Nodes.Annuaire.User.Contacts (annuaireUserLayout, userLayout)
19 20
import Gargantext.Components.Nodes.Corpus (corpusLayout)
import Gargantext.Components.Nodes.Corpus.Dashboard (dashboardLayout)
21 22
import Gargantext.Components.Nodes.Corpus.Document (documentLayout)
import Gargantext.Components.Nodes.Home (homeLayout)
23 24
import Gargantext.Components.Nodes.Lists (listsLayout)
import Gargantext.Components.Nodes.Texts (textsLayout)
25
import Gargantext.Config (defaultFrontends, defaultBackends)
26
import Gargantext.Ends (Frontends)
27
import Gargantext.Hooks.Router (useHashRouter)
28 29
import Gargantext.Router (router)
import Gargantext.Routes (AppRoute(..))
30
import Gargantext.Sessions (Sessions, useSessions)
31 32
import Gargantext.Sessions as Sessions
import Gargantext.Utils.Reactix as R2
James Laver's avatar
James Laver committed
33

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

37 38 39 40 41 42 43
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
44 45
    sessions   <- useSessions
    route      <- useHashRouter router Home
46

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

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

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

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

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

102 103
topBar :: {} -> R.Element
topBar _ =
James Laver's avatar
James Laver committed
104 105 106 107 108 109
  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" }
110 111
        [ divDropdownLeft ] ] ] ]
      -- SB.searchBar {session, databases: allDatabases}
James Laver's avatar
James Laver committed
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 221

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 []

222
footerCpt :: R.Component ()
James Laver's avatar
James Laver committed
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 249
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 "."
          ]]
        ]