WIP: Authd Admin: Search User Interface.

beta
Philippe Pittoli 2024-02-17 02:52:46 +01:00
parent ef22dd22c3
commit b60913ef02
1 changed files with 34 additions and 22 deletions

View File

@ -7,7 +7,7 @@
-} -}
module App.AuthenticationDaemonAdminInterface where module App.AuthenticationDaemonAdminInterface where
import Prelude (Unit, bind, discard, not, pure, show, ($), (<<<), (<>)) import Prelude (Unit, bind, discard, not, pure, show, ($), (<<<), (<>), (=<<))
import Bulma as Bulma import Bulma as Bulma
@ -21,6 +21,10 @@ import Halogen.HTML.Properties as HP
import Web.Event.Event (Event) import Web.Event.Event (Event)
import Web.Event.Event as 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 Data.ArrayBuffer.Types (ArrayBuffer)
import App.LogMessage import App.LogMessage
@ -62,12 +66,15 @@ data Action
| SearchUserAttempt | SearchUserAttempt
| PreventSubmit Event | PreventSubmit Event
-- | Change the displayed page.
| Routing Page
| Initialize | Initialize
| Finalize | Finalize
-- | There are different `sub-pages` in the authentication daemon admin page. -- | There are different `sub-pages` in the authentication daemon admin page.
-- | For example, users can be searched and a list is provided. -- | 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 StateAddUserForm = { login :: String, admin :: Boolean, email :: String, pass :: String }
type StateSearchUserForm = { login :: String, admin :: Boolean, email :: String, domain :: String } type StateSearchUserForm = { login :: String, admin :: Boolean, email :: String, domain :: String }
@ -102,10 +109,10 @@ initialState _ = { addUserForm: { login: "", admin: false, email: "", pass: "
render :: forall m. State -> H.ComponentHTML Action () m render :: forall m. State -> H.ComponentHTML Action () m
render { addUserForm, searchUserForm, page, wsUp } render { addUserForm, searchUserForm, page, wsUp }
= case page of = case page of
Home -> HH.div_ [ Bulma.columns_ [ Bulma.column_ [ Bulma.h3 "Add a new user", render_adduser_form ] ] ] 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" ] ] , 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 where
active = (if wsUp then (HP.enabled true) else (HP.disabled true)) 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.btn (show addUserForm.admin) (HandleAddUserInput ADDUSER_toggle_admin)
, Bulma.box_input "email" "User email" "email" (up ADDUSER_INP_email) addUserForm.email active , 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 , Bulma.box_password "password" "User password" "password" (up ADDUSER_INP_pass) addUserForm.pass active
, HH.button , generic_button AddUserAttempt wsUp
[ 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" ]
] ]
up x = HandleAddUserInput <<< x up x = HandleAddUserInput <<< x
@ -133,15 +134,19 @@ render { addUserForm, searchUserForm, page, wsUp }
, Bulma.box_input "email" "User email" "email" (up SEARCHUSER_INP_email) searchUserForm.email active , Bulma.box_input "email" "User email" "email" (up SEARCHUSER_INP_email) searchUserForm.email active
--, Bulma.box_input "domain" "Domain owned" "blah.netlib.re." --, Bulma.box_input "domain" "Domain owned" "blah.netlib.re."
-- (up SEARCHUSER_INP_domain) searchUserForm.email active -- (up SEARCHUSER_INP_domain) searchUserForm.email active
, HH.button , generic_button SearchUserAttempt wsUp
[ HP.style "padding: 0.5rem 1.25rem;"
, HP.type_ HP.ButtonSubmit
, HE.onClick \ _ -> SearchUserAttempt
, (if wsUp then (HP.enabled true) else (HP.disabled true))
]
[ HH.text "Send Message to Server" ]
] ]
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 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 :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit
handleAction = case _ of handleAction = case _ of
Initialize -> do Initialize -> do
@ -189,6 +194,15 @@ handleAction = case _ of
H.raise $ MessageToSend ab H.raise $ MessageToSend ab
H.raise $ Log $ SimpleLog "[😇] Trying to add a user" 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 SearchUserAttempt -> do
{ searchUserForm } <- H.get { searchUserForm } <- H.get
let login = searchUserForm.login let login = searchUserForm.login
@ -204,8 +218,6 @@ handleAction = case _ of
--H.raise $ MessageToSend ab --H.raise $ MessageToSend ab
H.raise $ Log $ SimpleLog "[😇] TODO: Trying to add a user" 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 :: forall a m. MonadAff m => Query a -> H.HalogenM State Action () Output m (Maybe a)
handleQuery = case _ of handleQuery = case _ of