From 0838c962f07b9bfac7d4e1c348da5abe025c3cb7 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Mon, 5 Feb 2024 15:29:38 +0100 Subject: [PATCH] Compiles again. CurrentRR Modal is on the way. --- src/App/ZoneInterface.purs | 193 ++++++++++++++++++------------------- 1 file changed, 92 insertions(+), 101 deletions(-) diff --git a/src/App/ZoneInterface.purs b/src/App/ZoneInterface.purs index 1369793..d15e1c8 100644 --- a/src/App/ZoneInterface.purs +++ b/src/App/ZoneInterface.purs @@ -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,114 +336,105 @@ 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_ = - [ render_errors - , Bulma.box_input ("domain" <> t_) "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" - (updateForm Field_TTL) - state._currentRR.ttl - state._currentRR.valid - should_be_disabled - , Bulma.box_input ("target" <> t_) "Target" "198.51.100.5" - (updateForm Field_Target) - state._currentRR.target - state._currentRR.valid - should_be_disabled - ] + content_simple :: Array (HH.HTML w Action) + content_simple = + [ render_errors + , 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" <> state._currentRR.rrtype) "TTL" "600" + (updateForm Field_TTL) + state._currentRR.ttl + state._currentRR.valid + should_be_disabled + , Bulma.box_input ("target" <> state._currentRR.rrtype) "Target" "198.51.100.5" + (updateForm Field_Target) + state._currentRR.target + state._currentRR.valid + should_be_disabled + ] content_mx :: Array (HH.HTML w Action) content_mx = - [ render_errors - , Bulma.box_input ("domainMX") "Name" "mail" -- id, title, placeholder - (updateForm Field_Domain) -- action - state._currentRR.name -- value - state._currentRR.valid -- validity (TODO) - should_be_disabled -- condition - , Bulma.box_input ("ttlMX") "TTL" "600" - (updateForm Field_TTL) - state._currentRR.ttl - state._currentRR.valid - should_be_disabled - , Bulma.box_input ("targetMX") "Target" "www" - (updateForm Field_Target) - state._currentRR.target - state._currentRR.valid - should_be_disabled - , Bulma.box_input ("priorityMX") "Priority" "10" - (updateForm Field_Priority) - state._currentRR.priority - state._currentRR.valid - should_be_disabled - ] + [ render_errors + , Bulma.box_input ("domainMX") "Name" "mail" -- id, title, placeholder + (updateForm Field_Domain) -- action + state._currentRR.name -- value + state._currentRR.valid -- validity (TODO) + should_be_disabled -- condition + , Bulma.box_input ("ttlMX") "TTL" "600" + (updateForm Field_TTL) + state._currentRR.ttl + state._currentRR.valid + should_be_disabled + , Bulma.box_input ("targetMX") "Target" "www" + (updateForm Field_Target) + state._currentRR.target + state._currentRR.valid + should_be_disabled + , Bulma.box_input ("priorityMX") "Priority" "10" + (updateForm Field_Priority) + state._currentRR.priority + state._currentRR.valid + should_be_disabled + ] content_srv :: Array (HH.HTML w Action) content_srv = - [ render_errors - , Bulma.box_input ("domainSRV") "Name" "_sip._tcp" -- id, title, placeholder - (updateForm Field_Domain) -- action - state._currentRR.name -- value - state._currentRR.valid -- validity (TODO) - should_be_disabled -- condition - , Bulma.box_input ("ttlSRV") "TTL" "600" - (updateForm Field_TTL) - state._currentRR.ttl - state._currentRR.valid - should_be_disabled - , Bulma.box_input ("targetSRV") "Target" "www" - (updateForm Field_Target) - state._currentRR.target - state._currentRR.valid - should_be_disabled - , Bulma.box_input ("prioritySRV") "Priority" "10" - (updateForm Field_Priority) - state._currentRR.priority - state._currentRR.valid - should_be_disabled - , Bulma.box_input ("portSRV") "Port" "5061" - (updateForm Field_Port) - state._currentRR.port - state._currentRR.valid - should_be_disabled - , Bulma.box_input ("weightSRV") "Weight" "100" - (updateForm Field_Weight) - state._currentRR.weight - state._currentRR.valid - should_be_disabled - , Bulma.box_input ("protocolSRV") "Protocol" "tcp" - (updateForm Field_Protocol) - state._currentRR.protocol - state._currentRR.valid - should_be_disabled - ] + [ render_errors + , Bulma.box_input ("domainSRV") "Name" "_sip._tcp" -- id, title, placeholder + (updateForm Field_Domain) -- action + state._currentRR.name -- value + state._currentRR.valid -- validity (TODO) + should_be_disabled -- condition + , Bulma.box_input ("ttlSRV") "TTL" "600" + (updateForm Field_TTL) + state._currentRR.ttl + state._currentRR.valid + should_be_disabled + , Bulma.box_input ("targetSRV") "Target" "www" + (updateForm Field_Target) + state._currentRR.target + state._currentRR.valid + should_be_disabled + , Bulma.box_input ("prioritySRV") "Priority" "10" + (updateForm Field_Priority) + state._currentRR.priority + state._currentRR.valid + should_be_disabled + , Bulma.box_input ("portSRV") "Port" "5061" + (updateForm Field_Port) + state._currentRR.port + state._currentRR.valid + should_be_disabled + , Bulma.box_input ("weightSRV") "Weight" "100" + (updateForm Field_Weight) + state._currentRR.weight + state._currentRR.valid + should_be_disabled + , Bulma.box_input ("protocolSRV") "Protocol" "tcp" + (updateForm Field_Protocol) + state._currentRR.protocol + state._currentRR.valid + should_be_disabled + ] should_be_disabled = (if true then (HP.enabled true) else (HP.disabled true)) 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. 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"