WIP: Authd Admin: Search User Interface.
parent
ef22dd22c3
commit
b60913ef02
|
@ -7,7 +7,7 @@
|
|||
-}
|
||||
module App.AuthenticationDaemonAdminInterface where
|
||||
|
||||
import Prelude (Unit, bind, discard, not, pure, show, ($), (<<<), (<>))
|
||||
import Prelude (Unit, bind, discard, not, pure, show, ($), (<<<), (<>), (=<<))
|
||||
|
||||
import Bulma as Bulma
|
||||
|
||||
|
@ -21,6 +21,10 @@ import Halogen.HTML.Properties as HP
|
|||
import Web.Event.Event (Event)
|
||||
import Web.Event.Event as Event
|
||||
|
||||
import Web.HTML (window) as HTML
|
||||
import Web.HTML.Window (sessionStorage) as Window
|
||||
import Web.Storage.Storage as Storage
|
||||
|
||||
import Data.ArrayBuffer.Types (ArrayBuffer)
|
||||
|
||||
import App.LogMessage
|
||||
|
@ -62,12 +66,15 @@ data Action
|
|||
| SearchUserAttempt
|
||||
| PreventSubmit Event
|
||||
|
||||
-- | Change the displayed page.
|
||||
| Routing Page
|
||||
|
||||
| Initialize
|
||||
| Finalize
|
||||
|
||||
-- | There are different `sub-pages` in the authentication daemon admin page.
|
||||
-- | For example, users can be searched and a list is provided.
|
||||
data Page = Home | SearchUser | AddUser
|
||||
data Page = Home | Search | Add
|
||||
|
||||
type StateAddUserForm = { login :: String, admin :: Boolean, email :: String, pass :: String }
|
||||
type StateSearchUserForm = { login :: String, admin :: Boolean, email :: String, domain :: String }
|
||||
|
@ -103,9 +110,9 @@ render :: forall m. State -> H.ComponentHTML Action () m
|
|||
render { addUserForm, searchUserForm, page, wsUp }
|
||||
= case page of
|
||||
Home -> HH.div_ [ Bulma.columns_ [ Bulma.column_ [ Bulma.h3 "Add a new user", render_adduser_form ] ] ]
|
||||
SearchUser -> HH.div_ [ Bulma.columns_ [ Bulma.column_ [ Bulma.h3 "Search users", render_searchuser_form ] ]
|
||||
Search -> HH.div_ [ Bulma.columns_ [ Bulma.column_ [ Bulma.h3 "Search users", render_searchuser_form ] ]
|
||||
, Bulma.column_ [ Bulma.h3 "Result", Bulma.subtitle "TODO" ] ]
|
||||
AddUser -> HH.div_ [ Bulma.columns_ [ Bulma.column_ [ Bulma.h3 "Add a new user", render_adduser_form ] ] ]
|
||||
Add -> HH.div_ [ Bulma.columns_ [ Bulma.column_ [ Bulma.h3 "Add a new user", render_adduser_form ] ] ]
|
||||
where
|
||||
|
||||
active = (if wsUp then (HP.enabled true) else (HP.disabled true))
|
||||
|
@ -116,13 +123,7 @@ render { addUserForm, searchUserForm, page, wsUp }
|
|||
, Bulma.btn (show addUserForm.admin) (HandleAddUserInput ADDUSER_toggle_admin)
|
||||
, Bulma.box_input "email" "User email" "email" (up ADDUSER_INP_email) addUserForm.email active
|
||||
, Bulma.box_password "password" "User password" "password" (up ADDUSER_INP_pass) addUserForm.pass active
|
||||
, HH.button
|
||||
[ HP.style "padding: 0.5rem 1.25rem;"
|
||||
, HP.type_ HP.ButtonSubmit
|
||||
, HE.onClick \ _ -> AddUserAttempt
|
||||
, (if wsUp then (HP.enabled true) else (HP.disabled true))
|
||||
]
|
||||
[ HH.text "Send Message to Server" ]
|
||||
, generic_button AddUserAttempt wsUp
|
||||
]
|
||||
up x = HandleAddUserInput <<< x
|
||||
|
||||
|
@ -133,14 +134,18 @@ render { addUserForm, searchUserForm, page, wsUp }
|
|||
, Bulma.box_input "email" "User email" "email" (up SEARCHUSER_INP_email) searchUserForm.email active
|
||||
--, Bulma.box_input "domain" "Domain owned" "blah.netlib.re."
|
||||
-- (up SEARCHUSER_INP_domain) searchUserForm.email active
|
||||
, HH.button
|
||||
, generic_button SearchUserAttempt wsUp
|
||||
]
|
||||
|
||||
generic_button :: forall w. Action -> Boolean -> HH.HTML w Action
|
||||
generic_button action active =
|
||||
HH.button
|
||||
[ HP.style "padding: 0.5rem 1.25rem;"
|
||||
, HP.type_ HP.ButtonSubmit
|
||||
, HE.onClick \_ -> SearchUserAttempt
|
||||
, (if wsUp then (HP.enabled true) else (HP.disabled true))
|
||||
, (if active then (HP.enabled true) else (HP.disabled true))
|
||||
]
|
||||
[ HH.text "Send Message to Server" ]
|
||||
]
|
||||
|
||||
handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit
|
||||
handleAction = case _ of
|
||||
|
@ -189,6 +194,15 @@ handleAction = case _ of
|
|||
H.raise $ MessageToSend ab
|
||||
H.raise $ Log $ SimpleLog "[😇] Trying to add a user"
|
||||
|
||||
Routing page -> do
|
||||
-- Store the current page we are on and restore it when we reload.
|
||||
sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window
|
||||
_ <- case page of
|
||||
Home -> H.liftEffect $ Storage.setItem "current-ada-page" "Home" sessionstorage
|
||||
Search -> H.liftEffect $ Storage.setItem "current-ada-page" "Search" sessionstorage
|
||||
Add -> H.liftEffect $ Storage.setItem "current-ada-page" "Add" sessionstorage
|
||||
H.modify_ _ { page = page }
|
||||
|
||||
SearchUserAttempt -> do
|
||||
{ searchUserForm } <- H.get
|
||||
let login = searchUserForm.login
|
||||
|
@ -204,8 +218,6 @@ handleAction = case _ of
|
|||
--H.raise $ MessageToSend ab
|
||||
H.raise $ Log $ SimpleLog "[😇] TODO: Trying to add a user"
|
||||
|
||||
|
||||
|
||||
handleQuery :: forall a m. MonadAff m => Query a -> H.HalogenM State Action () Output m (Maybe a)
|
||||
handleQuery = case _ of
|
||||
|
||||
|
|
Loading…
Reference in New Issue