From c448521df786ebd37c0429a7b165081027bef3f0 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sun, 21 Jan 2024 17:44:46 +0100 Subject: [PATCH] WIP: (slowly) replacing fixed "new RR" forms with modal forms. --- src/App/ZoneInterface.purs | 108 +++++++++++++++++++++++++++++++------ src/Bulma.purs | 3 +- 2 files changed, 94 insertions(+), 17 deletions(-) diff --git a/src/App/ZoneInterface.purs b/src/App/ZoneInterface.purs index 1161bb8..387d5f1 100644 --- a/src/App/ZoneInterface.purs +++ b/src/App/ZoneInterface.purs @@ -98,6 +98,9 @@ data Add_RR | Add_MXRR | Add_SRVRR + -- NEW + | Add_A + data Update_SRR_Form = Update_SRR_Type Int | Update_SRR_Domain RecordName @@ -110,19 +113,29 @@ data Update_MX_Form | Update_MX_Target RecordTarget | 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 = Update_SRV_Domain RecordName | Update_SRV_TTL TTL - | Update_SRV_Target RecordTarget + | Update_SRV_Target RecordTarget | Update_SRV_Priority Priority | Update_SRV_Protocol Protocol | Update_SRV_Weight Weight | Update_SRV_Port Port data Update_New_Form - = Update_New_Form_SRR Update_SRR_Form - | Update_New_Form_MXRR Update_MX_Form - | Update_New_Form_SRVRR Update_SRV_Form + = Update_New_Form_SRR Update_SRR_Form + | Update_New_Form_MXRR Update_MX_Form + | Update_New_Form_SRVRR Update_SRV_Form + | Update_New_MODAL_Form_RR Update_MODAL_Form data Update_Local_Form = Update_Local_Form_SRR Update_SRR_Form @@ -170,6 +183,9 @@ type State = , _srvrr :: Array (SRVRR ()) , _errors :: Hash.HashMap RRId Validation.Errors + -- Unique RR form. + , _newRR :: (SRVRR ()) -- SRVRR contains all relevant information for every RR. + -- potential future entries , _newSRR :: (SimpleRR ()) , _newMXRR :: (MXRR ()) @@ -210,6 +226,9 @@ initialState domain = , _srvrr: [] , _errors: Hash.empty + -- This is the state for the new RR modal. + , _newRR: defaultResourceSRV + , _newSRR: defaultResourceA , _newMXRR: defaultResourceMX , _newSRVRR: defaultResourceSRV @@ -263,20 +282,41 @@ render state ] modal_add_new_rr :: forall w. AcceptedRRTypes -> State -> HH.HTML w Action - modal_add_new_rr t state = case t of - A -> template "A" [ Bulma.p "hello, new A RR!" ] - 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!" ] + 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!" ] [] 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_card [Bulma.modal_header $ "New " <> t <> " resource record" , 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 @@ -298,6 +338,38 @@ handleAction = case _ of H.raise $ MessageToSend message 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_SRR_Type val -> do -- let new_type = fromMaybe "unknown" (baseRecords A.!! val) @@ -368,6 +440,12 @@ handleAction = case _ of -- This action only is possible if inputs are correct. 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 state <- H.get try_add_new_entry state._domain (Validation.validateSRR state._newSRR) "simple" @@ -814,7 +892,7 @@ render_new_record_column_simple rr _ ] where 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] [ HH.select [ HE.onSelectedIndexChange (UpdateNewForm <<< Update_New_Form_SRR <<< Update_SRR_Type) ] diff --git a/src/Bulma.purs b/src/Bulma.purs index 4eb2f68..86c156e 100644 --- a/src/Bulma.purs +++ b/src/Bulma.purs @@ -1,6 +1,5 @@ +-- | The `Bulma` module is a wrapper around the BULMA css framework. module Bulma where -{- This file is a wrapper around the BULMA css framework. -} - import Prelude import Halogen.HTML as HH