WIP: modal forms.

beta
Philippe Pittoli 2024-01-22 05:44:29 +01:00
parent c448521df7
commit 272237a5a1
1 changed files with 138 additions and 19 deletions

View File

@ -100,6 +100,13 @@ data Add_RR
-- NEW
| Add_A
| Add_AAAA
| Add_TXT
| Add_CNAME
| Add_NS
| Add_MX
| Add_SRV
data Update_SRR_Form
= Update_SRR_Type Int
@ -283,35 +290,98 @@ render state
modal_add_new_rr :: forall w. AcceptedRRTypes -> State -> HH.HTML w Action
modal_add_new_rr t { _newRR: rr } = case t of
A -> template "A" content_a foot_a
AAAA -> template "AAAA" [ Bulma.p "hello, new AAAA RR!" ] []
TXT -> template "TXT" [ Bulma.p "hello, new TXT RR!" ] []
CNAME -> template "CNAME" [ Bulma.p "hello, new CNAME RR!" ] []
NS -> template "NS" [ Bulma.p "hello, new NS RR!" ] []
MX -> template "MX" [ Bulma.p "hello, new MX RR!" ] []
SRV -> template "SRV" [ Bulma.p "hello, new SRV RR!" ] []
A -> template "A" (content_simple "A") (foot_content Add_A)
AAAA -> template "AAAA" (content_simple "AAAA") (foot_content Add_AAAA)
TXT -> template "TXT" (content_simple "TXT") (foot_content Add_TXT)
CNAME -> template "CNAME" (content_simple "CNAME") (foot_content Add_CNAME)
NS -> template "NS" (content_simple "NS") (foot_content Add_NS)
MX -> template "MX" content_mx (foot_content Add_MX)
SRV -> template "SRV" content_srv (foot_content Add_SRV)
where
-- 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)
updateForm x = UpdateNewForm <<< Update_New_MODAL_Form_RR <<< x
content_simple :: String -> Array (HH.HTML w Action)
content_simple t =
[ Bulma.box_input ("domain" <> t) "Name" "www" -- id, title, placeholder
(updateForm Update_MODAL_Domain) -- action
rr.name -- value
rr.valid -- validity (TODO)
should_be_disabled -- condition
, Bulma.box_input ("ttl" <> t) "TTL" "600"
(updateForm Update_MODAL_TTL)
rr.ttl
rr.valid
should_be_disabled
, Bulma.box_input "targetA" "Target" "198.51.100.5"
(update Update_MODAL_Target)
, Bulma.box_input ("target" <> t) "Target" "198.51.100.5"
(updateForm Update_MODAL_Target)
rr.target
rr.valid
should_be_disabled
]
content_mx :: Array (HH.HTML w Action)
content_mx =
[ Bulma.box_input ("domainMX") "Name" "mail" -- id, title, placeholder
(updateForm Update_MODAL_Domain) -- action
rr.name -- value
rr.valid -- validity (TODO)
should_be_disabled -- condition
, Bulma.box_input ("ttlMX") "TTL" "600"
(updateForm Update_MODAL_TTL)
rr.ttl
rr.valid
should_be_disabled
, Bulma.box_input ("targetMX") "Target" "www"
(updateForm Update_MODAL_Target)
rr.target
rr.valid
should_be_disabled
, Bulma.box_input ("priorityMX") "Priority" "10"
(updateForm Update_MODAL_Priority)
rr.priority
rr.valid
should_be_disabled
]
content_srv :: Array (HH.HTML w Action)
content_srv =
[ Bulma.box_input ("domainSRV") "Name" "_sip._tcp" -- id, title, placeholder
(updateForm Update_MODAL_Domain) -- action
rr.name -- value
rr.valid -- validity (TODO)
should_be_disabled -- condition
, Bulma.box_input ("ttlSRV") "TTL" "600"
(updateForm Update_MODAL_TTL)
rr.ttl
rr.valid
should_be_disabled
, Bulma.box_input ("targetSRV") "Target" "www"
(updateForm Update_MODAL_Target)
rr.target
rr.valid
should_be_disabled
, Bulma.box_input ("prioritySRV") "Priority" "10"
(updateForm Update_MODAL_Priority)
rr.priority
rr.valid
should_be_disabled
, Bulma.box_input ("portSRV") "Port" "5061"
(updateForm Update_MODAL_Port)
rr.port
rr.valid
should_be_disabled
, Bulma.box_input ("weightSRV") "Weight" "100"
(updateForm Update_MODAL_Weight)
rr.weight
rr.valid
should_be_disabled
, Bulma.box_input ("protocolSRV") "Protocol" "tcp"
(updateForm Update_MODAL_Protocol)
rr.protocol
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]
foot_content x = [Bulma.btn_add (AddRR x) (TellSomethingWentWrong rr.rrid "cannot add") rr.valid]
template t content foot = Bulma.modal
[ Bulma.modal_background
, Bulma.modal_card [Bulma.modal_header $ "New " <> t <> " resource record"
@ -329,7 +399,44 @@ handleAction = case _ of
H.modify_ _ { active_modal = Just rr_id }
NewRRModal t -> do
state <- H.get
H.modify_ _ { active_new_rr_modal = Just t }
let defaultA = { rrtype: "A", rrid: 0, modified: false, valid: true, ttl: "600", readonly: false
, name: "www"
, target: "192.0.2.1"
, port: "", weight: "", priority: "", protocol: ""}
defaultAAAA = { rrtype: "AAAA", rrid: 0, modified: false, valid: true, ttl: "600", readonly: false
, name: "www"
, target: "2001:db8::1"
, port: "", weight: "", priority: "", protocol: ""}
defaultTXT = { rrtype: "TXT", rrid: 0, modified: false, valid: true, ttl: "600", readonly: false
, name: "txt"
, target: "some text"
, port: "", weight: "", priority: "", protocol: ""}
defaultCNAME = { rrtype: "CNAME", rrid: 0, modified: false, valid: true, ttl: "600", readonly: false
, name: "blog"
, target: "www"
, port: "", weight: "", priority: "", protocol: ""}
defaultNS = { rrtype: "NS", rrid: 0, modified: false, valid: true, ttl: "600", readonly: false
, name: (state._domain <> ".")
, target: "ns0.example.com."
, port: "", weight: "", priority: "", protocol: ""}
defaultMX = { rrtype: "MX", rrid: 0, modified: false, valid: true, ttl: "600", readonly: false
, name: "mail"
, target: "www"
, port: "", weight: "", priority: "10", protocol: ""}
defaultSRV = { rrtype: "SRV", rrid: 0, modified: false, valid: true, ttl: "600", readonly: false
, name: "_sip._tcp"
, target: "www"
, port: "5061", weight: "100", priority: "10", protocol: "tcp"}
case t of
A -> H.modify_ _ { _newRR = defaultA }
AAAA -> H.modify_ _ { _newRR = defaultAAAA }
TXT -> H.modify_ _ { _newRR = defaultTXT }
CNAME -> H.modify_ _ { _newRR = defaultCNAME }
NS -> H.modify_ _ { _newRR = defaultNS }
MX -> H.modify_ _ { _newRR = defaultMX }
SRV -> H.modify_ _ { _newRR = defaultSRV }
Initialize -> do
{ _domain } <- H.get
@ -442,6 +549,18 @@ handleAction = case _ of
AddRR form -> case form of
Add_A -> do
H.raise $ Log $ SimpleLog "TODO: trying to add a A RR blah blah blah"
Add_AAAA -> do
H.raise $ Log $ SimpleLog "TODO: trying to add a AAAA RR blah blah blah"
Add_TXT -> do
H.raise $ Log $ SimpleLog "TODO: trying to add a TXT RR blah blah blah"
Add_CNAME -> do
H.raise $ Log $ SimpleLog "TODO: trying to add a CNAME RR blah blah blah"
Add_NS -> do
H.raise $ Log $ SimpleLog "TODO: trying to add a NS RR blah blah blah"
Add_MX -> do
H.raise $ Log $ SimpleLog "TODO: trying to add a MX RR blah blah blah"
Add_SRV -> do
H.raise $ Log $ SimpleLog "TODO: trying to add a SRV RR blah blah blah"
---- TODO
--state <- H.get
--try_add_new_entry state._domain (Validation.validateA state._newRR) "simple"