Commit a7f06511 authored by James Laver's avatar James Laver

enable login, up to cors problem

parent 8e5fcc57
...@@ -47,29 +47,31 @@ appCpt = R.hooksComponent "G.C.App.app" cpt where ...@@ -47,29 +47,31 @@ appCpt = R.hooksComponent "G.C.App.app" cpt where
showCorpus <- R.useState' false showCorpus <- R.useState' false
let tree = forestLayout frontends (fst sessions) (fst route) (snd showLogin) let tree = forestLayout frontends (fst sessions) (fst route) (snd showLogin)
let mCurrentRoute = Just $ fst route let mCurrentRoute = Just $ fst route
let setVisible = snd showLogin
let backends = fromFoldable defaultBackends let backends = fromFoldable defaultBackends
pure $ case unSessions (fst sessions) of pure $ case fst showLogin of
Nothing -> tree $ homeLayout EN true -> tree $ login { sessions, backends, visible: showLogin }
Just session -> false ->
case (fst route) of case unSessions (fst sessions) of
Home -> tree $ homeLayout EN Nothing -> tree $ homeLayout EN
Login -> login { sessions, backends, setVisible } Just session ->
Folder _ -> tree $ folder {} case (fst route) of
Corpus nodeId -> tree $ corpusLayout { nodeId } Home -> tree $ homeLayout EN
Texts nodeId -> tree $ textsLayout { nodeId, session } Login -> login { sessions, backends, visible: showLogin }
Lists nodeId -> tree $ listsLayout { nodeId, session } Folder _ -> tree $ folder {}
Dashboard -> tree $ dashboardLayout {} Corpus nodeId -> tree $ corpusLayout { nodeId }
Annuaire annuaireId -> tree $ annuaireLayout { annuaireId, session } Texts nodeId -> tree $ textsLayout { nodeId, session }
UserPage nodeId -> tree $ userLayout { nodeId, session } Lists nodeId -> tree $ listsLayout { nodeId, session }
ContactPage nodeId -> tree $ userLayout { nodeId, session } Dashboard -> tree $ dashboardLayout {}
CorpusDocument corpusId listId nodeId -> Annuaire annuaireId -> tree $ annuaireLayout { annuaireId, session }
tree $ documentLayout { nodeId, listId, session, corpusId: Just corpusId } UserPage nodeId -> tree $ userLayout { nodeId, session }
Document listId nodeId -> ContactPage nodeId -> tree $ userLayout { nodeId, session }
tree $ documentLayout { nodeId, listId, session, corpusId: Nothing } CorpusDocument corpusId listId nodeId ->
PGraphExplorer graphId -> tree $ documentLayout { nodeId, listId, session, corpusId: Just corpusId }
simpleLayout (fst sessions) $ Document listId nodeId ->
explorerLayout { graphId, mCurrentRoute, session, treeId: Nothing } tree $ documentLayout { nodeId, listId, session, corpusId: Nothing }
PGraphExplorer graphId ->
simpleLayout (fst sessions) $
explorerLayout { graphId, mCurrentRoute, session, treeId: Nothing }
forestLayout :: Frontends -> Sessions -> AppRoute -> R2.Setter Boolean -> R.Element -> R.Element forestLayout :: Frontends -> Sessions -> AppRoute -> R2.Setter Boolean -> R.Element -> R.Element
forestLayout frontends sessions route showLogin child = forestLayout frontends sessions route showLogin child =
......
module Gargantext.Components.Forest where module Gargantext.Components.Forest where
import Prelude (const, show) import Prelude (const, show, discard)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import DOM.Simple.Console (log)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Gargantext.Ends (Frontends) import Gargantext.Ends (Frontends)
...@@ -33,6 +34,7 @@ forestCpt = R.staticComponent "G.C.Forest.forest" cpt where ...@@ -33,6 +34,7 @@ forestCpt = R.staticComponent "G.C.Forest.forest" cpt where
, treeView { root: treeId, mCurrentRoute: Just route, session: s } ] , treeView { root: treeId, mCurrentRoute: Just route, session: s } ]
plus :: R2.Setter Boolean -> R.Element plus :: R2.Setter Boolean -> R.Element
plus showLogin = plus showLogin = H.button {on: {click}} [ H.text "+" ]
H.button {on: {click: \_ -> showLogin (const true)}} where
[ H.text "+" ] click _ = do
showLogin (const true)
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
-- Select a backend and log into it -- Select a backend and log into it
module Gargantext.Components.Login where module Gargantext.Components.Login where
import Prelude (Unit, bind, const, discard, pure, ($), (<>)) import Prelude (Unit, bind, const, discard, pure, flip, show, ($), (<>), (<$>))
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Tuple (fst, snd) import Data.Tuple (fst, snd)
...@@ -16,7 +16,7 @@ import Reactix.DOM.HTML as H ...@@ -16,7 +16,7 @@ import Reactix.DOM.HTML as H
------------------------------------------------------------------------ ------------------------------------------------------------------------
import Gargantext.Components.Forms (clearfix, card, cardBlock, cardGroup, center, formGroup) import Gargantext.Components.Forms (clearfix, card, cardBlock, cardGroup, center, formGroup)
import Gargantext.Components.Login.Types (AuthRequest(..)) import Gargantext.Components.Login.Types (AuthRequest(..))
import Gargantext.Ends (Backend) import Gargantext.Ends (Backend(..))
import Gargantext.Sessions (Session, Sessions, postAuthRequest, unSessions) import Gargantext.Sessions (Session, Sessions, postAuthRequest, unSessions)
import Gargantext.Sessions as Sessions import Gargantext.Sessions as Sessions
import Gargantext.Utils (csrfMiddlewareToken) import Gargantext.Utils (csrfMiddlewareToken)
...@@ -28,27 +28,30 @@ import Gargantext.Utils.Reactix as R2 ...@@ -28,27 +28,30 @@ import Gargantext.Utils.Reactix as R2
type Props = type Props =
( backends :: Array Backend ( backends :: Array Backend
, sessions :: R2.Reductor Sessions Sessions.Action , sessions :: R2.Reductor Sessions Sessions.Action
, setVisible :: R2.Setter Boolean ) , visible :: R.State Boolean )
type ModalProps = ( visible :: Boolean ) type ModalProps = ( visible :: Boolean )
modal :: Record ModalProps -> Array R.Element -> R.Element modal :: Record ModalProps -> R.Element -> R.Element
modal = R.createElement modalCpt modal props child = R.createElement modalCpt props [ child ]
modalCpt :: R.Component ModalProps modalCpt :: R.Component ModalProps
modalCpt = R.staticComponent "Modal" cpt where modalCpt = R.hooksComponent "Modal" cpt where
cpt {visible} children = cpt {visible} children = do
H.div { id: "loginModal", className: modalClass visible R.createPortal elems <$> R2.getPortalHost
, role: "dialog", "data": {show: true}} where
[ H.div { className: "modal-dialog", role: "document"} elems =
[ H.div { className: "modal-content" } [ H.div { id: "loginModal", className: modalClass visible
[ H.div { className: "modal-header" } , role: "dialog", "data": {show: true}, style: {display: "block"}}
[ H.h5 { className: "modal-title" } [] [ H.div { className: "modal-dialog", role: "document"}
, H.button { "type": "button", className: "close" [ H.div { className: "modal-content" }
, "data": { dismiss: "modal" } } [ H.div { className: "modal-header" }
[ H.span { aria: { hidden: true } } [ H.text "X" ] ] [ H.h5 { className: "modal-title" } []
, H.div { className: "modal-body" } children ] ] ] ] , H.button { "type": "button", className: "close"
modalClass s = "modal myModal" <> if s then "" else " fade" , "data": { dismiss: "modal" } }
[ H.span { aria: { hidden: true } } [ H.text "X" ] ] ]
, H.div { className: "modal-body" } children ] ] ] ]
modalClass s = "modal myModal" <> if s then "" else " fade"
login :: Record Props -> R.Element login :: Record Props -> R.Element
login props = R.createElement loginCpt props [] login props = R.createElement loginCpt props []
...@@ -56,11 +59,13 @@ login props = R.createElement loginCpt props [] ...@@ -56,11 +59,13 @@ login props = R.createElement loginCpt props []
loginCpt :: R.Component Props loginCpt :: R.Component Props
loginCpt = R.hooksComponent "G.C.Login.login" cpt loginCpt = R.hooksComponent "G.C.Login.login" cpt
where where
cpt props@{backends, sessions, setVisible} _ = do cpt props@{backends, sessions, visible} _ = do
backend <- R.useState' Nothing backend <- R.useState' Nothing
pure $ case (fst backend) of pure $
Nothing -> chooser { backends, backend, sessions, setVisible } modal {visible: fst visible} $
Just b -> form { sessions, setVisible, backend: b } case fst backend of
Nothing -> chooser { backends, backend, sessions, visible }
Just b -> form { sessions, visible, backend: b }
type ChooserProps = ( backend :: R.State (Maybe Backend) | Props ) type ChooserProps = ( backend :: R.State (Maybe Backend) | Props )
...@@ -70,28 +75,31 @@ chooser props = R.createElement chooserCpt props [] ...@@ -70,28 +75,31 @@ chooser props = R.createElement chooserCpt props []
chooserCpt :: R.Component ChooserProps chooserCpt :: R.Component ChooserProps
chooserCpt = R.staticComponent "G.C.Login.chooser" cpt where chooserCpt = R.staticComponent "G.C.Login.chooser" cpt where
cpt :: Record ChooserProps -> Array R.Element -> R.Element cpt :: Record ChooserProps -> Array R.Element -> R.Element
cpt {backend, backends, sessions, setVisible} _ = cpt {backend, backends, sessions} _ =
R.fragment H.ul {}
[ renderSessions sessions, renderBackends backends backend ] [ renderSessions sessions, renderBackends backends backend ]
renderSessions :: R2.Reductor Sessions Sessions.Action -> R.Element renderSessions :: R2.Reductor Sessions Sessions.Action -> R.Element
renderSessions sessions = render (unSessions $ fst sessions) where renderSessions sessions =
render (unSessions $ fst sessions) where
render Nothing = R.fragment [] render Nothing = R.fragment []
render (Just s) = renderSession s render (Just s) = renderSession s
renderSession :: Session -> R.Element renderSession :: Session -> R.Element
renderSession session = R.fragment [] renderSession session = H.li {} [ H.text $ "Active session: " <> show session ]
renderBackends :: Array Backend -> R.State (Maybe Backend) -> R.Element renderBackends :: Array Backend -> R.State (Maybe Backend) -> R.Element
renderBackends backends state = R.fragment [] renderBackends backends state = R.fragment $ (flip renderBackend $ state) <$> backends
renderBackend :: Backend -> R.State (Maybe Backend) -> R.Element renderBackend :: Backend -> R.State (Maybe Backend) -> R.Element
renderBackend backend state = R.fragment [] renderBackend backend@(Backend {name}) state =
H.li {} [ H.a {on: {click}} [ H.text $ "Connect to " <> name ] ] where
click _ = (snd state) (const $ Just backend)
type FormProps = type FormProps =
( backend :: Backend ( backend :: Backend
, sessions :: R2.Reductor Sessions Sessions.Action , sessions :: R2.Reductor Sessions Sessions.Action
, setVisible :: R2.Setter Boolean ) , visible :: R.State Boolean )
form :: Record FormProps -> R.Element form :: Record FormProps -> R.Element
form props = R.createElement formCpt props [] form props = R.createElement formCpt props []
...@@ -99,7 +107,7 @@ form props = R.createElement formCpt props [] ...@@ -99,7 +107,7 @@ form props = R.createElement formCpt props []
formCpt :: R.Component FormProps formCpt :: R.Component FormProps
formCpt = R.hooksComponent "G.C.Login.form" cpt where formCpt = R.hooksComponent "G.C.Login.form" cpt where
cpt :: Record FormProps -> Array R.Element -> R.Hooks R.Element cpt :: Record FormProps -> Array R.Element -> R.Hooks R.Element
cpt props@{backend, sessions, setVisible} _ = do cpt props@{backend, sessions, visible} _ = do
error <- R.useState' "" error <- R.useState' ""
username <- R.useState' "" username <- R.useState' ""
password <- R.useState' "" password <- R.useState' ""
...@@ -123,7 +131,7 @@ formCpt = R.hooksComponent "G.C.Login.form" cpt where ...@@ -123,7 +131,7 @@ formCpt = R.hooksComponent "G.C.Login.form" cpt where
[ termsCheckbox {}, H.text "I accept the terms of use ", termsLink {} ] ] [ termsCheckbox {}, H.text "I accept the terms of use ", termsLink {} ] ]
, loginSubmit $ , loginSubmit $
onClick props error username password ] ] ] ] ] ] onClick props error username password ] ] ] ] ] ]
onClick {backend, sessions, setVisible} error username password e = onClick {backend, sessions, visible} error username password e =
launchAff_ $ do launchAff_ $ do
let req = AuthRequest {username: fst username, password: fst password} let req = AuthRequest {username: fst username, password: fst password}
res <- postAuthRequest backend req res <- postAuthRequest backend req
...@@ -132,7 +140,7 @@ formCpt = R.hooksComponent "G.C.Login.form" cpt where ...@@ -132,7 +140,7 @@ formCpt = R.hooksComponent "G.C.Login.form" cpt where
Right sess -> liftEffect $ do Right sess -> liftEffect $ do
(snd sessions) (Sessions.Login sess) (snd sessions) (Sessions.Login sess)
(snd error) (const "") (snd error) (const "")
setVisible (const false) (snd visible) (const false)
logo = logo =
H.div {className: "col-md-10 col-md-push-1"} H.div {className: "col-md-10 col-md-push-1"}
[ H.h2 {className: "text-primary center m-a-2"} [ H.h2 {className: "text-primary center m-a-2"}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment