Add some documentation for DomainListInterface.

This commit is contained in:
Philippe Pittoli 2023-07-08 23:44:01 +02:00
parent 572dfc88a4
commit 507330120e
2 changed files with 48 additions and 18 deletions

View File

@ -26,7 +26,7 @@ data Page = Home | LoginRegister | DomainList | Zone | AuthAdmin
data Action data Action
= AuthenticationComponentEvent AF.Output = AuthenticationComponentEvent AF.Output
| AuthenticationDaemonAdminComponentEvent AAI.Output -- Admin interface for authd. | AuthenticationDaemonAdminComponentEvent AAI.Output -- Admin interface for authd.
| DomainListComponentEvent DomainListInterface.Output | DomainListComponentEvent DomainListInterface.Output
| AuthenticationDaemonEvent WS.Output | AuthenticationDaemonEvent WS.Output
| DNSManagerDaemonEvent WS.Output | DNSManagerDaemonEvent WS.Output
| AuthenticateToDNSManager | AuthenticateToDNSManager
@ -35,6 +35,7 @@ data Action
type State = { token :: Maybe String type State = { token :: Maybe String
, uid :: Maybe Int , uid :: Maybe Int
, current_page :: Page , current_page :: Page
, store_DomainListInterface_state :: Maybe DomainListInterface.State
} }
type ChildSlots = type ChildSlots =
@ -65,6 +66,7 @@ initialState :: forall i. i -> State
initialState _ = { token: Nothing initialState _ = { token: Nothing
, uid: Nothing , uid: Nothing
, current_page: Home , current_page: Home
, store_DomainListInterface_state: Nothing
} }
render :: forall m. MonadAff m => State -> H.ComponentHTML Action ChildSlots m render :: forall m. MonadAff m => State -> H.ComponentHTML Action ChildSlots m
@ -128,8 +130,8 @@ render state
render_newdomain_interface :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad render_newdomain_interface :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad
render_newdomain_interface = case state.token of render_newdomain_interface = case state.token of
Just token -> Bulma.box $ Just _ -> Bulma.box $
[ HH.slot _dli unit DomainListInterface.component token DomainListComponentEvent [ HH.slot _dli unit DomainListInterface.component unit DomainListComponentEvent
] ]
Nothing -> render_nothing Nothing -> render_nothing

View File

@ -1,16 +1,15 @@
module App.DomainListInterface where module App.DomainListInterface where
{- Simple component with the list of own domains and a form to add a new domain. -- | `App.DomainListInterface` is a simple component with the list of own domains
This interface allows to: -- | and a form to add a new domain.
- display the list of own domains -- |
- show and select accepted domains (TLDs) -- | This interface allows to:
- create new domains -- | - display the list of own domains
- delete a domain -- | - show and select accepted domains (TLDs)
- TODO: ask for confirmation -- | - create new domains
- TODO: show and modify the content of a Zone -- | - delete a domain
-- | - TODO: ask for confirmation
Authentication is automatic with the token. -- | - TODO: switch to the interface to show and modify the content of a Zone
-}
import Prelude (Unit, bind, discard, map, otherwise, pure, ($), (/=), (<<<), (<>)) import Prelude (Unit, bind, discard, map, otherwise, pure, ($), (/=), (<<<), (<>))
@ -33,11 +32,21 @@ import Bulma as Bulma
import App.LogMessage import App.LogMessage
import App.Messages.DNSManagerDaemon as DNSManager import App.Messages.DNSManagerDaemon as DNSManager
-- | `App.DomainListInterface` can send messages through websocket interface
-- | connected to dnsmanagerd. See `App.WS`.
-- |
-- | Also, this component can log messages and ask its parent (`App.Container`) to
-- | reconnect the websocket to `dnsmanagerd`.
data Output data Output
= MessageToSend ArrayBuffer = MessageToSend ArrayBuffer
| Log LogMessage | Log LogMessage
| DNSManagerReconnect | DNSManagerReconnect
-- | `App.DomainListInterface` can receive messages from `dnsmanagerd`.
-- |
-- | The component is also informed when the connection is lost or up again.
data Query a data Query a
= MessageReceived ArrayBuffer a = MessageReceived ArrayBuffer a
| ConnectionIsDown a | ConnectionIsDown a
@ -45,12 +54,25 @@ data Query a
type Slot = H.Slot Query Output type Slot = H.Slot Query Output
type Input = String -- | `App.DomainListInterface` has no input.
type Input = Unit
-- | `App.DomainListInterface` has a single form to add a new domain.
-- | Only two possible inputs: the (sub)domain name and the selection of the TLD.
data NewDomainFormAction data NewDomainFormAction
= INP_newdomain String = INP_newdomain String
| UpdateSelectedDomain String | UpdateSelectedDomain String
-- | Possible component's actions are:
-- | - update the accepted domains (examples: netlib.re, codelib.re and example.com)
-- | - update the list of own domains
-- | - handle user inputs
-- | - add a new domain
-- | - remove a domain
-- | - TODO: show the zone content (in another component)
data Action data Action
= UpdateAcceptedDomains (Array String) = UpdateAcceptedDomains (Array String)
| UpdateMyDomains (Array String) | UpdateMyDomains (Array String)
@ -61,18 +83,23 @@ data Action
| RemoveDomain String | RemoveDomain String
| EnterDomain String | EnterDomain String
-- | The form only has two elements:
-- | the subdomain name input and the selected TLD.
type NewDomainFormState type NewDomainFormState
= { new_domain :: String = { new_domain :: String
, selected_domain :: String , selected_domain :: String
} }
-- | The entire component's state contains the form, accepted domains,
-- | the list of own domains and a boolean to know if the connection is up.
type State = type State =
{ newDomainForm :: NewDomainFormState { newDomainForm :: NewDomainFormState
, accepted_domains :: Array String , accepted_domains :: Array String
, my_domains :: Array String , my_domains :: Array String
, wsUp :: Boolean , wsUp :: Boolean
, token :: String
} }
component :: forall m. MonadAff m => H.Component Query Input Output m component :: forall m. MonadAff m => H.Component Query Input Output m
@ -86,18 +113,19 @@ component =
} }
} }
-- | Default available domain: netlib.re.
default_domain :: String default_domain :: String
default_domain = "netlib.re" default_domain = "netlib.re"
initialState :: Input -> State initialState :: Input -> State
initialState token = initialState _ =
{ newDomainForm: { new_domain: "" { newDomainForm: { new_domain: ""
, selected_domain: default_domain , selected_domain: default_domain
} }
, accepted_domains: [ default_domain ] , accepted_domains: [ default_domain ]
, my_domains: [ ] , my_domains: [ ]
, wsUp: true , wsUp: true
, token: token
} }
render :: forall m. State -> H.ComponentHTML Action () m render :: forall m. State -> H.ComponentHTML Action () m