Compiles again. CurrentRR Modal is on the way.

beta
Philippe Pittoli 2024-02-05 15:29:38 +01:00
parent e343523142
commit 0838c962f0
1 changed files with 92 additions and 101 deletions

View File

@ -296,8 +296,8 @@ render state
[ case state.wsUp, state.rr_modal of
false, _ -> Bulma.p "You are disconnected."
true, RemoveRRModal rr_id -> modal_rr_delete rr_id
true, NewRRModal t -> modal_add_new_rr t
true, UpdateRRModal -> modal_add_new_rr -- render_current_rr_modal rr_id
true, NewRRModal _ -> render_current_rr_modal
true, UpdateRRModal -> render_current_rr_modal
true, NoModal -> HH.div_
[ Bulma.h1 state._domain
, Bulma.hr
@ -336,46 +336,37 @@ render state
, HH.text "."
]
-- TODO: this seems overly complicated.
-- Verification if the RR exists has been already done.
render_current_rr_modal :: forall w. RRId -> HH.HTML w Action
render_current_rr_modal rr_id = do
case first (\rr -> rr.rrid == rr_id) state._resources of
Nothing -> H.raise $ Log $ SimpleLog $ "RR not found (RR " <> show rr_id <> ")"
Just entry -> do
case string_to_acceptedtype entry.rrtype of
Nothing -> H.raise $ Log $ SimpleLog $ "RR " <> show rr_id <> ": cannot determine the type"
Just type_ -> modal_add_new_rr type_
modal_add_new_rr :: forall w. AcceptedRRTypes -> HH.HTML w Action
modal_add_new_rr t = case t of
A -> template (content_simple "A") (foot_content t)
AAAA -> template (content_simple "AAAA") (foot_content t)
TXT -> template (content_simple "TXT") (foot_content t)
CNAME -> template (content_simple "CNAME") (foot_content t)
NS -> template (content_simple "NS") (foot_content t)
MX -> template content_mx (foot_content t)
SRV -> template content_srv (foot_content t)
render_current_rr_modal :: forall w. HH.HTML w Action
render_current_rr_modal =
case state._currentRR.rrtype of
"A" -> template content_simple (foot_content A)
"AAAA" -> template content_simple (foot_content AAAA)
"TXT" -> template content_simple (foot_content TXT)
"CNAME" -> template content_simple (foot_content CNAME)
"NS" -> template content_simple (foot_content NS)
"MX" -> template content_mx (foot_content MX)
"SRV" -> template content_srv (foot_content SRV)
_ -> Bulma.p $ "Invalid type: " <> state._currentRR.rrtype
where
-- DRY
updateForm x = UpdateCurrentRR <<< x
render_errors = if A.length state._currentRR_errors > 0
then HH.div_ $ [ Bulma.h3 "Errors: " ] <> map error_to_paragraph state._currentRR_errors
else HH.div_ [ ]
content_simple :: String -> Array (HH.HTML w Action)
content_simple t_ =
content_simple :: Array (HH.HTML w Action)
content_simple =
[ render_errors
, Bulma.box_input ("domain" <> t_) "Name" "www" -- id, title, placeholder
, Bulma.box_input ("domain" <> state._currentRR.rrtype) "Name" "www" -- id, title, placeholder
(updateForm Field_Domain) -- action
state._currentRR.name -- value
state._currentRR.valid -- validity (TODO)
should_be_disabled -- condition
, Bulma.box_input ("ttl" <> t_) "TTL" "600"
, Bulma.box_input ("ttl" <> state._currentRR.rrtype) "TTL" "600"
(updateForm Field_TTL)
state._currentRR.ttl
state._currentRR.valid
should_be_disabled
, Bulma.box_input ("target" <> t_) "Target" "198.51.100.5"
, Bulma.box_input ("target" <> state._currentRR.rrtype) "Target" "198.51.100.5"
(updateForm Field_Target)
state._currentRR.target
state._currentRR.valid
@ -482,7 +473,7 @@ handleAction = case _ of
-- | Each time a "new RR" button is clicked, the form resets.
CreateNewRRModal t -> do
state <- H.get
H.modify_ _ { rr_modal = Just t }
H.modify_ _ { rr_modal = NewRRModal t }
let defaultA = { rrtype: "A", rrid: 0, modified: false, valid: true, ttl: "600", readonly: false
, name: "www"
, target: "192.0.2.1"