Commit c99eb587 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[CLEAN/ERGO] Login form

parent 8d391cd0
...@@ -24,12 +24,11 @@ import Gargantext.Sessions (OpenNodes, Session, mkNodeId) ...@@ -24,12 +24,11 @@ import Gargantext.Sessions (OpenNodes, Session, mkNodeId)
import Gargantext.Types as GT import Gargantext.Types as GT
type CommonProps = type CommonProps =
( ( frontends :: Frontends
frontends :: Frontends , mCurrentRoute :: Maybe AppRoute
, mCurrentRoute :: Maybe AppRoute , openNodes :: R.State OpenNodes
, openNodes :: R.State OpenNodes , reload :: R.State Reload
, reload :: R.State Reload , session :: Session
, session :: Session
) )
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -93,16 +92,16 @@ toHtml p@{ frontends ...@@ -93,16 +92,16 @@ toHtml p@{ frontends
, tasks: tasks@(asyncTasks /\ setAsyncTasks) , tasks: tasks@(asyncTasks /\ setAsyncTasks)
, tree: tree@(NTree (LNode {id, name, nodeType}) ary) } = R.createElement el {} [] , tree: tree@(NTree (LNode {id, name, nodeType}) ary) } = R.createElement el {} []
where where
el = R.hooksComponent "NodeView" cpt el = R.hooksComponent "NodeView" cpt
commonProps = RecordE.pick p :: Record CommonProps commonProps = RecordE.pick p :: Record CommonProps
pAction = performAction (RecordE.pick p :: Record PerformActionProps) pAction = performAction (RecordE.pick p :: Record PerformActionProps)
cpt _ _ = do cpt _ _ = do
let nodeId = mkNodeId session id let nodeId = mkNodeId session id
let folderIsOpen = Set.member nodeId (fst openNodes) let folderIsOpen = Set.member nodeId (fst openNodes)
let setFn = if folderIsOpen then Set.delete else Set.insert let setFn = if folderIsOpen then Set.delete else Set.insert
let toggleFolderIsOpen _ = (snd openNodes) (setFn nodeId) let toggleFolderIsOpen _ = (snd openNodes) (setFn nodeId)
let folderOpen = Tuple folderIsOpen toggleFolderIsOpen let folderOpen = Tuple folderIsOpen toggleFolderIsOpen
let withId (NTree (LNode {id: id'}) _) = id' let withId (NTree (LNode {id: id'}) _) = id'
...@@ -154,15 +153,14 @@ childNodes props@{ children } = ...@@ -154,15 +153,14 @@ childNodes props@{ children } =
el = R.hooksComponent "ChildNodeView" cpt el = R.hooksComponent "ChildNodeView" cpt
cpt {tree, asyncTasks} _ = do cpt {tree, asyncTasks} _ = do
tasks <- R.useState' asyncTasks tasks <- R.useState' asyncTasks
pure $ toHtml (Record.merge commonProps pure $ toHtml (Record.merge commonProps { tasks, tree })
{ tasks, tree })
type PerformActionProps = type PerformActionProps =
( openNodes :: R.State OpenNodes ( openNodes :: R.State OpenNodes
, reload :: R.State Reload , reload :: R.State Reload
, session :: Session , session :: Session
, tasks :: R.State (Array GT.AsyncTaskWithType) , tasks :: R.State (Array GT.AsyncTaskWithType)
, tree :: FTree , tree :: FTree
) )
performAction :: Record PerformActionProps performAction :: Record PerformActionProps
......
...@@ -3,11 +3,12 @@ ...@@ -3,11 +3,12 @@
-- 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, show, ($), (<>), (*>), (<$>), (>), map) import Prelude (Unit, bind, const, discard, pure, show, ($), (<>), (*>), (<$>), (>), map, (==), (/=), not, (&&))
import Data.Array (head) import Data.Array (head)
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Maybe (Maybe(..), fromMaybe) import Data.Maybe (Maybe(..), fromMaybe)
import Data.Tuple (fst, snd) import Data.Tuple (fst, snd)
import Data.Tuple.Nested ((/\))
import Data.String as DST import Data.String as DST
import DOM.Simple.Console (log) import DOM.Simple.Console (log)
import Data.Sequence as DS import Data.Sequence as DS
...@@ -32,7 +33,8 @@ import Gargantext.Utils.Reactix as R2 ...@@ -32,7 +33,8 @@ 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
, visible :: R.State Boolean ) , visible :: R.State Boolean
)
type ModalProps = ( visible :: R.State Boolean ) type ModalProps = ( visible :: R.State Boolean )
...@@ -147,7 +149,8 @@ renderBackend state backend@(Backend {name}) = ...@@ -147,7 +149,8 @@ renderBackend state backend@(Backend {name}) =
type FormProps = type FormProps =
( backend :: Backend ( backend :: Backend
, sessions :: R2.Reductor Sessions Sessions.Action , sessions :: R2.Reductor Sessions Sessions.Action
, visible :: R.State 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 []
...@@ -156,9 +159,10 @@ formCpt :: R.Component FormProps ...@@ -156,9 +159,10 @@ 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, visible} _ = 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' ""
setBox@(checkBox /\ setCheckBox) <- R.useState' false
pure $ R2.row pure $ R2.row
[ cardGroup [ cardGroup
[ card [ card
...@@ -175,9 +179,18 @@ formCpt = R.hooksComponent "G.C.Login.form" cpt where ...@@ -175,9 +179,18 @@ formCpt = R.hooksComponent "G.C.Login.form" cpt where
, center , center
[ H.label {} [ H.label {}
[ H.div {className: "checkbox"} [ H.div {className: "checkbox"}
[ termsCheckbox {}, H.text "I accept the terms of use ", termsLink {} ] ] [ termsCheckbox setBox , H.text "I accept the terms of use ", termsLink {} ] ]
, loginSubmit $ ]
onClick props error username password ] ] ] ] ] ] ]
, if checkBox == true
&& fst username /= ""
&& fst password /= ""
then H.div {} [center [loginSubmit $ onClick props error username password]]
else H.div {} []
]
]
]
]
onClick {backend, sessions, visible} 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}
...@@ -194,13 +207,18 @@ csrfTokenInput _ = ...@@ -194,13 +207,18 @@ csrfTokenInput _ =
H.input { type: "hidden", name: "csrfmiddlewaretoken" H.input { type: "hidden", name: "csrfmiddlewaretoken"
, value: csrfMiddlewareToken }-- TODO hard-coded CSRF token , value: csrfMiddlewareToken }-- TODO hard-coded CSRF token
termsCheckbox :: {} -> R.Element termsCheckbox :: R.State Boolean -> R.Element
termsCheckbox _ = termsCheckbox setCheckBox =
H.input { id: "terms-accept", type: "checkbox", value: "", className: "checkbox" } H.input { id: "terms-accept"
, type: "checkbox"
, value: fst setCheckBox
, className: "checkbox"
, on: { click: \_ -> (snd setCheckBox) $ const $ not (fst setCheckBox)}
}
termsLink :: {} -> R.Element termsLink :: {} -> R.Element
termsLink _ = termsLink _ =
H.a { target: "_blank", href: termsUrl } [ H.text " [ Read the terms of use ] " ] H.a { target: "_blank", href: termsUrl } [ H.text " [Read the terms of use]" ]
where termsUrl = "http://gitlab.iscpif.fr/humanities/tofu/tree/master" where termsUrl = "http://gitlab.iscpif.fr/humanities/tofu/tree/master"
requestAccessLink :: {} -> R.Element requestAccessLink :: {} -> R.Element
......
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