Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
a7f06511
Commit
a7f06511
authored
Sep 30, 2019
by
James Laver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enable login, up to cors problem
parent
8e5fcc57
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
58 deletions
+70
-58
App.purs
src/Gargantext/Components/App.purs
+24
-22
Forest.purs
src/Gargantext/Components/Forest.purs
+6
-4
Login.purs
src/Gargantext/Components/Login.purs
+40
-32
No files found.
src/Gargantext/Components/App.purs
View file @
a7f06511
...
...
@@ -47,14 +47,16 @@ appCpt = R.hooksComponent "G.C.App.app" cpt where
showCorpus <- R.useState' false
let tree = forestLayout frontends (fst sessions) (fst route) (snd showLogin)
let mCurrentRoute = Just $ fst route
let setVisible = snd showLogin
let backends = fromFoldable defaultBackends
pure $ case unSessions (fst sessions) of
pure $ case fst showLogin of
true -> tree $ login { sessions, backends, visible: showLogin }
false ->
case unSessions (fst sessions) of
Nothing -> tree $ homeLayout EN
Just session ->
case (fst route) of
Home -> tree $ homeLayout EN
Login -> login { sessions, backends, setVisible
}
Login -> login { sessions, backends, visible: showLogin
}
Folder _ -> tree $ folder {}
Corpus nodeId -> tree $ corpusLayout { nodeId }
Texts nodeId -> tree $ textsLayout { nodeId, session }
...
...
src/Gargantext/Components/Forest.purs
View file @
a7f06511
module Gargantext.Components.Forest where
import Prelude (const, show)
import Prelude (const, show
, discard
)
import Data.Maybe (Maybe(..))
import DOM.Simple.Console (log)
import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Ends (Frontends)
...
...
@@ -33,6 +34,7 @@ forestCpt = R.staticComponent "G.C.Forest.forest" cpt where
, treeView { root: treeId, mCurrentRoute: Just route, session: s } ]
plus :: R2.Setter Boolean -> R.Element
plus showLogin =
H.button {on: {click: \_ -> showLogin (const true)}}
[ H.text "+" ]
plus showLogin = H.button {on: {click}} [ H.text "+" ]
where
click _ = do
showLogin (const true)
src/Gargantext/Components/Login.purs
View file @
a7f06511
...
...
@@ -3,7 +3,7 @@
-- Select a backend and log into it
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.Maybe (Maybe(..))
import Data.Tuple (fst, snd)
...
...
@@ -16,7 +16,7 @@ import Reactix.DOM.HTML as H
------------------------------------------------------------------------
import Gargantext.Components.Forms (clearfix, card, cardBlock, cardGroup, center, formGroup)
import Gargantext.Components.Login.Types (AuthRequest(..))
import Gargantext.Ends (Backend)
import Gargantext.Ends (Backend
(..)
)
import Gargantext.Sessions (Session, Sessions, postAuthRequest, unSessions)
import Gargantext.Sessions as Sessions
import Gargantext.Utils (csrfMiddlewareToken)
...
...
@@ -28,25 +28,28 @@ import Gargantext.Utils.Reactix as R2
type Props =
( backends :: Array Backend
, sessions :: R2.Reductor Sessions Sessions.Action
,
setVisible :: R2.Setter
Boolean )
,
visible :: R.State
Boolean )
type ModalProps = ( visible :: Boolean )
modal :: Record ModalProps ->
Array
R.Element -> R.Element
modal
= R.createElement modalCpt
modal :: Record ModalProps -> R.Element -> R.Element
modal
props child = R.createElement modalCpt props [ child ]
modalCpt :: R.Component ModalProps
modalCpt = R.staticComponent "Modal" cpt where
cpt {visible} children =
H.div { id: "loginModal", className: modalClass visible
, role: "dialog", "data": {show: true}}
modalCpt = R.hooksComponent "Modal" cpt where
cpt {visible} children = do
R.createPortal elems <$> R2.getPortalHost
where
elems =
[ H.div { id: "loginModal", className: modalClass visible
, role: "dialog", "data": {show: true}, style: {display: "block"}}
[ H.div { className: "modal-dialog", role: "document"}
[ H.div { className: "modal-content" }
[ H.div { className: "modal-header" }
[ H.h5 { className: "modal-title" } []
, H.button { "type": "button", className: "close"
, "data": { dismiss: "modal" } }
[ H.span { aria: { hidden: true } } [ H.text "X"
] ]
[ H.span { aria: { hidden: true } } [ H.text "X" ]
] ]
, H.div { className: "modal-body" } children ] ] ] ]
modalClass s = "modal myModal" <> if s then "" else " fade"
...
...
@@ -56,11 +59,13 @@ login props = R.createElement loginCpt props []
loginCpt :: R.Component Props
loginCpt = R.hooksComponent "G.C.Login.login" cpt
where
cpt props@{backends, sessions,
setV
isible} _ = do
cpt props@{backends, sessions,
v
isible} _ = do
backend <- R.useState' Nothing
pure $ case (fst backend) of
Nothing -> chooser { backends, backend, sessions, setVisible }
Just b -> form { sessions, setVisible, backend: b }
pure $
modal {visible: fst visible} $
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 )
...
...
@@ -70,28 +75,31 @@ chooser props = R.createElement chooserCpt props []
chooserCpt :: R.Component ChooserProps
chooserCpt = R.staticComponent "G.C.Login.chooser" cpt where
cpt :: Record ChooserProps -> Array R.Element -> R.Element
cpt {backend, backends, sessions
, setVisible
} _ =
R.fragment
cpt {backend, backends, sessions} _ =
H.ul {}
[ renderSessions sessions, renderBackends backends backend ]
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 (Just s) = renderSession s
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 backends state = R.fragment
[]
renderBackends backends state = R.fragment
$ (flip renderBackend $ state) <$> backends
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 =
( backend :: Backend
, sessions :: R2.Reductor Sessions Sessions.Action
,
setVisible :: R2.Setter
Boolean )
,
visible :: R.State
Boolean )
form :: Record FormProps -> R.Element
form props = R.createElement formCpt props []
...
...
@@ -99,7 +107,7 @@ form props = R.createElement formCpt props []
formCpt :: R.Component FormProps
formCpt = R.hooksComponent "G.C.Login.form" cpt where
cpt :: Record FormProps -> Array R.Element -> R.Hooks R.Element
cpt props@{backend, sessions,
setV
isible} _ = do
cpt props@{backend, sessions,
v
isible} _ = do
error <- R.useState' ""
username <- R.useState' ""
password <- R.useState' ""
...
...
@@ -123,7 +131,7 @@ formCpt = R.hooksComponent "G.C.Login.form" cpt where
[ termsCheckbox {}, H.text "I accept the terms of use ", termsLink {} ] ]
, loginSubmit $
onClick props error username password ] ] ] ] ] ]
onClick {backend, sessions,
setV
isible} error username password e =
onClick {backend, sessions,
v
isible} error username password e =
launchAff_ $ do
let req = AuthRequest {username: fst username, password: fst password}
res <- postAuthRequest backend req
...
...
@@ -132,7 +140,7 @@ formCpt = R.hooksComponent "G.C.Login.form" cpt where
Right sess -> liftEffect $ do
(snd sessions) (Sessions.Login sess)
(snd error) (const "")
setVisible
(const false)
(snd visible)
(const false)
logo =
H.div {className: "col-md-10 col-md-push-1"}
[ H.h2 {className: "text-primary center m-a-2"}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment