WIP: (slowly) replacing fixed "new RR" forms with modal forms.

This commit is contained in:
Philippe Pittoli 2024-01-21 17:44:46 +01:00
parent c9552677ab
commit c448521df7
2 changed files with 94 additions and 17 deletions

View File

@ -98,6 +98,9 @@ data Add_RR
| Add_MXRR | Add_MXRR
| Add_SRVRR | Add_SRVRR
-- NEW
| Add_A
data Update_SRR_Form data Update_SRR_Form
= Update_SRR_Type Int = Update_SRR_Type Int
| Update_SRR_Domain RecordName | Update_SRR_Domain RecordName
@ -110,6 +113,15 @@ data Update_MX_Form
| Update_MX_Target RecordTarget | Update_MX_Target RecordTarget
| Update_MX_Priority Priority | Update_MX_Priority Priority
data Update_MODAL_Form
= Update_MODAL_Domain RecordName
| Update_MODAL_TTL TTL
| Update_MODAL_Target RecordTarget
| Update_MODAL_Priority Priority
| Update_MODAL_Protocol Protocol
| Update_MODAL_Weight Weight
| Update_MODAL_Port Port
data Update_SRV_Form data Update_SRV_Form
= Update_SRV_Domain RecordName = Update_SRV_Domain RecordName
| Update_SRV_TTL TTL | Update_SRV_TTL TTL
@ -123,6 +135,7 @@ data Update_New_Form
= Update_New_Form_SRR Update_SRR_Form = Update_New_Form_SRR Update_SRR_Form
| Update_New_Form_MXRR Update_MX_Form | Update_New_Form_MXRR Update_MX_Form
| Update_New_Form_SRVRR Update_SRV_Form | Update_New_Form_SRVRR Update_SRV_Form
| Update_New_MODAL_Form_RR Update_MODAL_Form
data Update_Local_Form data Update_Local_Form
= Update_Local_Form_SRR Update_SRR_Form = Update_Local_Form_SRR Update_SRR_Form
@ -170,6 +183,9 @@ type State =
, _srvrr :: Array (SRVRR ()) , _srvrr :: Array (SRVRR ())
, _errors :: Hash.HashMap RRId Validation.Errors , _errors :: Hash.HashMap RRId Validation.Errors
-- Unique RR form.
, _newRR :: (SRVRR ()) -- SRVRR contains all relevant information for every RR.
-- potential future entries -- potential future entries
, _newSRR :: (SimpleRR ()) , _newSRR :: (SimpleRR ())
, _newMXRR :: (MXRR ()) , _newMXRR :: (MXRR ())
@ -210,6 +226,9 @@ initialState domain =
, _srvrr: [] , _srvrr: []
, _errors: Hash.empty , _errors: Hash.empty
-- This is the state for the new RR modal.
, _newRR: defaultResourceSRV
, _newSRR: defaultResourceA , _newSRR: defaultResourceA
, _newMXRR: defaultResourceMX , _newMXRR: defaultResourceMX
, _newSRVRR: defaultResourceSRV , _newSRVRR: defaultResourceSRV
@ -263,20 +282,41 @@ render state
] ]
modal_add_new_rr :: forall w. AcceptedRRTypes -> State -> HH.HTML w Action modal_add_new_rr :: forall w. AcceptedRRTypes -> State -> HH.HTML w Action
modal_add_new_rr t state = case t of modal_add_new_rr t { _newRR: rr } = case t of
A -> template "A" [ Bulma.p "hello, new A RR!" ] A -> template "A" content_a foot_a
AAAA -> template "AAAA" [ Bulma.p "hello, new AAAA RR!" ] AAAA -> template "AAAA" [ Bulma.p "hello, new AAAA RR!" ] []
TXT -> template "TXT" [ Bulma.p "hello, new TXT RR!" ] TXT -> template "TXT" [ Bulma.p "hello, new TXT RR!" ] []
CNAME -> template "CNAME" [ Bulma.p "hello, new CNAME RR!" ] CNAME -> template "CNAME" [ Bulma.p "hello, new CNAME RR!" ] []
NS -> template "NS" [ Bulma.p "hello, new NS RR!" ] NS -> template "NS" [ Bulma.p "hello, new NS RR!" ] []
MX -> template "MX" [ Bulma.p "hello, new MX RR!" ] MX -> template "MX" [ Bulma.p "hello, new MX RR!" ] []
SRV -> template "SRV" [ Bulma.p "hello, new SRV RR!" ] SRV -> template "SRV" [ Bulma.p "hello, new SRV RR!" ] []
where where
template t content = Bulma.modal -- DRY
update x = UpdateNewForm <<< Update_New_MODAL_Form_RR <<< x
content_a =
[ Bulma.box_input "domainA" "Domain" "www" -- id, title, placeholder
(update Update_MODAL_Domain) -- action
rr.name -- value
rr.valid -- validity (TODO)
should_be_disabled -- condition
, Bulma.box_input "ttlA" "TTL" "3600"
(update Update_MODAL_TTL)
rr.ttl
rr.valid
should_be_disabled
, Bulma.box_input "targetA" "Target" "198.51.100.5"
(update Update_MODAL_Target)
rr.target
rr.valid
should_be_disabled
]
should_be_disabled = (if true then (HP.enabled true) else (HP.disabled true))
foot_a = [Bulma.btn_add (AddRR Add_A) (TellSomethingWentWrong rr.rrid "cannot add") rr.valid]
template t content foot = Bulma.modal
[ Bulma.modal_background [ Bulma.modal_background
, Bulma.modal_card [Bulma.modal_header $ "New " <> t <> " resource record" , Bulma.modal_card [Bulma.modal_header $ "New " <> t <> " resource record"
, Bulma.modal_body content ] , Bulma.modal_body content ]
, Bulma.modal_foot [Bulma.modal_cancel_button CancelModal] , Bulma.modal_foot (foot <> [Bulma.modal_cancel_button CancelModal])
] ]
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
@ -298,6 +338,38 @@ handleAction = case _ of
H.raise $ MessageToSend message H.raise $ MessageToSend message
UpdateNewForm form -> case form of UpdateNewForm form -> case form of
-- Update for the new RR form in the new RR modal.
Update_New_MODAL_Form_RR rr_update -> case rr_update of
Update_MODAL_Domain val -> do
-- H.raise $ Log $ SimpleLog ("Update new SRV entry name: " <> val)
state <- H.get
H.modify_ _ { _newRR = state._newRR { name = val } }
Update_MODAL_Target val -> do
-- H.raise $ Log $ SimpleLog ("Update new SRV entry target: " <> val)
state <- H.get
H.modify_ _ { _newRR = state._newRR { target = val } }
-- TODO: FIXME: test all inputs
Update_MODAL_TTL val -> do
-- H.raise $ Log $ SimpleLog ("Update new SRV entry ttl: " <> val)
state <- H.get
H.modify_ _ { _newRR = state._newRR {ttl = val, valid = isInteger val}}
Update_MODAL_Priority val -> do
-- H.raise $ Log $ SimpleLog ("Update new SRV entry priority: " <> val)
state <- H.get
H.modify_ _ { _newRR = state._newRR { priority = val } }
Update_MODAL_Protocol val -> do
-- H.raise $ Log $ SimpleLog ("Update new SRV entry protocol: " <> val)
state <- H.get
H.modify_ _ { _newRR = state._newRR { protocol = val } }
Update_MODAL_Weight val -> do
-- H.raise $ Log $ SimpleLog ("Update new SRV entry weight: " <> val)
state <- H.get
H.modify_ _ { _newRR = state._newRR { weight = val } }
Update_MODAL_Port val -> do
-- H.raise $ Log $ SimpleLog ("Update new SRV entry port: " <> val)
state <- H.get
H.modify_ _ { _newRR = state._newRR { port = val } }
Update_New_Form_SRR rr_update -> case rr_update of Update_New_Form_SRR rr_update -> case rr_update of
Update_SRR_Type val -> do Update_SRR_Type val -> do
-- let new_type = fromMaybe "unknown" (baseRecords A.!! val) -- let new_type = fromMaybe "unknown" (baseRecords A.!! val)
@ -368,6 +440,12 @@ handleAction = case _ of
-- This action only is possible if inputs are correct. -- This action only is possible if inputs are correct.
AddRR form -> case form of AddRR form -> case form of
Add_A -> do
H.raise $ Log $ SimpleLog "TODO: trying to add a A RR blah blah blah"
---- TODO
--state <- H.get
--try_add_new_entry state._domain (Validation.validateA state._newRR) "simple"
Add_SRR -> do Add_SRR -> do
state <- H.get state <- H.get
try_add_new_entry state._domain (Validation.validateSRR state._newSRR) "simple" try_add_new_entry state._domain (Validation.validateSRR state._newSRR) "simple"
@ -814,7 +892,7 @@ render_new_record_column_simple rr _
] ]
where where
should_be_disabled = (if true then (HP.enabled true) else (HP.disabled true)) should_be_disabled = (if true then (HP.enabled true) else (HP.disabled true))
-- type_selection :: forall w i. HH.HTML w i type_selection :: HH.HTML w Action
type_selection = HH.div [HP.classes $ C.select <> C.is_normal] type_selection = HH.div [HP.classes $ C.select <> C.is_normal]
[ HH.select [ HH.select
[ HE.onSelectedIndexChange (UpdateNewForm <<< Update_New_Form_SRR <<< Update_SRR_Type) ] [ HE.onSelectedIndexChange (UpdateNewForm <<< Update_New_Form_SRR <<< Update_SRR_Type) ]

View File

@ -1,6 +1,5 @@
-- | The `Bulma` module is a wrapper around the BULMA css framework.
module Bulma where module Bulma where
{- This file is a wrapper around the BULMA css framework. -}
import Prelude import Prelude
import Halogen.HTML as HH import Halogen.HTML as HH