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 [ case state.wsUp, state.rr_modal of
false, _ -> Bulma.p "You are disconnected." false, _ -> Bulma.p "You are disconnected."
true, RemoveRRModal rr_id -> modal_rr_delete rr_id true, RemoveRRModal rr_id -> modal_rr_delete rr_id
true, NewRRModal t -> modal_add_new_rr t true, NewRRModal _ -> render_current_rr_modal
true, UpdateRRModal -> modal_add_new_rr -- render_current_rr_modal rr_id true, UpdateRRModal -> render_current_rr_modal
true, NoModal -> HH.div_ true, NoModal -> HH.div_
[ Bulma.h1 state._domain [ Bulma.h1 state._domain
, Bulma.hr , Bulma.hr
@ -336,114 +336,105 @@ render state
, HH.text "." , HH.text "."
] ]
-- TODO: this seems overly complicated. render_current_rr_modal :: forall w. HH.HTML w Action
-- Verification if the RR exists has been already done. render_current_rr_modal =
render_current_rr_modal :: forall w. RRId -> HH.HTML w Action case state._currentRR.rrtype of
render_current_rr_modal rr_id = do "A" -> template content_simple (foot_content A)
case first (\rr -> rr.rrid == rr_id) state._resources of "AAAA" -> template content_simple (foot_content AAAA)
Nothing -> H.raise $ Log $ SimpleLog $ "RR not found (RR " <> show rr_id <> ")" "TXT" -> template content_simple (foot_content TXT)
Just entry -> do "CNAME" -> template content_simple (foot_content CNAME)
case string_to_acceptedtype entry.rrtype of "NS" -> template content_simple (foot_content NS)
Nothing -> H.raise $ Log $ SimpleLog $ "RR " <> show rr_id <> ": cannot determine the type" "MX" -> template content_mx (foot_content MX)
Just type_ -> modal_add_new_rr type_ "SRV" -> template content_srv (foot_content SRV)
_ -> Bulma.p $ "Invalid type: " <> state._currentRR.rrtype
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)
where where
-- DRY -- DRY
updateForm x = UpdateCurrentRR <<< x updateForm x = UpdateCurrentRR <<< x
render_errors = if A.length state._currentRR_errors > 0 render_errors = if A.length state._currentRR_errors > 0
then HH.div_ $ [ Bulma.h3 "Errors: " ] <> map error_to_paragraph state._currentRR_errors then HH.div_ $ [ Bulma.h3 "Errors: " ] <> map error_to_paragraph state._currentRR_errors
else HH.div_ [ ] else HH.div_ [ ]
content_simple :: String -> Array (HH.HTML w Action) content_simple :: Array (HH.HTML w Action)
content_simple t_ = content_simple =
[ render_errors [ 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 (updateForm Field_Domain) -- action
state._currentRR.name -- value state._currentRR.name -- value
state._currentRR.valid -- validity (TODO) state._currentRR.valid -- validity (TODO)
should_be_disabled -- condition should_be_disabled -- condition
, Bulma.box_input ("ttl" <> t_) "TTL" "600" , Bulma.box_input ("ttl" <> state._currentRR.rrtype) "TTL" "600"
(updateForm Field_TTL) (updateForm Field_TTL)
state._currentRR.ttl state._currentRR.ttl
state._currentRR.valid state._currentRR.valid
should_be_disabled 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) (updateForm Field_Target)
state._currentRR.target state._currentRR.target
state._currentRR.valid state._currentRR.valid
should_be_disabled should_be_disabled
] ]
content_mx :: Array (HH.HTML w Action) content_mx :: Array (HH.HTML w Action)
content_mx = content_mx =
[ render_errors [ render_errors
, Bulma.box_input ("domainMX") "Name" "mail" -- id, title, placeholder , Bulma.box_input ("domainMX") "Name" "mail" -- id, title, placeholder
(updateForm Field_Domain) -- action (updateForm Field_Domain) -- action
state._currentRR.name -- value state._currentRR.name -- value
state._currentRR.valid -- validity (TODO) state._currentRR.valid -- validity (TODO)
should_be_disabled -- condition should_be_disabled -- condition
, Bulma.box_input ("ttlMX") "TTL" "600" , Bulma.box_input ("ttlMX") "TTL" "600"
(updateForm Field_TTL) (updateForm Field_TTL)
state._currentRR.ttl state._currentRR.ttl
state._currentRR.valid state._currentRR.valid
should_be_disabled should_be_disabled
, Bulma.box_input ("targetMX") "Target" "www" , Bulma.box_input ("targetMX") "Target" "www"
(updateForm Field_Target) (updateForm Field_Target)
state._currentRR.target state._currentRR.target
state._currentRR.valid state._currentRR.valid
should_be_disabled should_be_disabled
, Bulma.box_input ("priorityMX") "Priority" "10" , Bulma.box_input ("priorityMX") "Priority" "10"
(updateForm Field_Priority) (updateForm Field_Priority)
state._currentRR.priority state._currentRR.priority
state._currentRR.valid state._currentRR.valid
should_be_disabled should_be_disabled
] ]
content_srv :: Array (HH.HTML w Action) content_srv :: Array (HH.HTML w Action)
content_srv = content_srv =
[ render_errors [ render_errors
, Bulma.box_input ("domainSRV") "Name" "_sip._tcp" -- id, title, placeholder , Bulma.box_input ("domainSRV") "Name" "_sip._tcp" -- id, title, placeholder
(updateForm Field_Domain) -- action (updateForm Field_Domain) -- action
state._currentRR.name -- value state._currentRR.name -- value
state._currentRR.valid -- validity (TODO) state._currentRR.valid -- validity (TODO)
should_be_disabled -- condition should_be_disabled -- condition
, Bulma.box_input ("ttlSRV") "TTL" "600" , Bulma.box_input ("ttlSRV") "TTL" "600"
(updateForm Field_TTL) (updateForm Field_TTL)
state._currentRR.ttl state._currentRR.ttl
state._currentRR.valid state._currentRR.valid
should_be_disabled should_be_disabled
, Bulma.box_input ("targetSRV") "Target" "www" , Bulma.box_input ("targetSRV") "Target" "www"
(updateForm Field_Target) (updateForm Field_Target)
state._currentRR.target state._currentRR.target
state._currentRR.valid state._currentRR.valid
should_be_disabled should_be_disabled
, Bulma.box_input ("prioritySRV") "Priority" "10" , Bulma.box_input ("prioritySRV") "Priority" "10"
(updateForm Field_Priority) (updateForm Field_Priority)
state._currentRR.priority state._currentRR.priority
state._currentRR.valid state._currentRR.valid
should_be_disabled should_be_disabled
, Bulma.box_input ("portSRV") "Port" "5061" , Bulma.box_input ("portSRV") "Port" "5061"
(updateForm Field_Port) (updateForm Field_Port)
state._currentRR.port state._currentRR.port
state._currentRR.valid state._currentRR.valid
should_be_disabled should_be_disabled
, Bulma.box_input ("weightSRV") "Weight" "100" , Bulma.box_input ("weightSRV") "Weight" "100"
(updateForm Field_Weight) (updateForm Field_Weight)
state._currentRR.weight state._currentRR.weight
state._currentRR.valid state._currentRR.valid
should_be_disabled should_be_disabled
, Bulma.box_input ("protocolSRV") "Protocol" "tcp" , Bulma.box_input ("protocolSRV") "Protocol" "tcp"
(updateForm Field_Protocol) (updateForm Field_Protocol)
state._currentRR.protocol state._currentRR.protocol
state._currentRR.valid state._currentRR.valid
should_be_disabled should_be_disabled
] ]
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))
foot_content x = [ Bulma.btn_add (ValidateRR x) foot_content x = [ Bulma.btn_add (ValidateRR x)
@ -482,7 +473,7 @@ handleAction = case _ of
-- | Each time a "new RR" button is clicked, the form resets. -- | Each time a "new RR" button is clicked, the form resets.
CreateNewRRModal t -> do CreateNewRRModal t -> do
state <- H.get 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 let defaultA = { rrtype: "A", rrid: 0, modified: false, valid: true, ttl: "600", readonly: false
, name: "www" , name: "www"
, target: "192.0.2.1" , target: "192.0.2.1"