From 7fcb9d73a90595119834e998e5cc15735ac9052f Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Mon, 22 Jan 2024 23:43:51 +0100 Subject: [PATCH] Remove a lot of obsolete code. --- src/App/ZoneInterface.purs | 203 +++---------------------------------- 1 file changed, 14 insertions(+), 189 deletions(-) diff --git a/src/App/ZoneInterface.purs b/src/App/ZoneInterface.purs index 36326a4..5272449 100644 --- a/src/App/ZoneInterface.purs +++ b/src/App/ZoneInterface.purs @@ -35,13 +35,10 @@ import Data.String.Regex as Regex import Data.String.Regex.Flags as RegexFlags import Data.String.Regex.Unsafe as RegexUnsafe import Effect.Aff.Class (class MonadAff) --- import Effect (foreachE) import Halogen as H import Halogen.HTML as HH import Halogen.HTML.Events as HE import Halogen.HTML.Properties as HP ---import Web.Event.Event as Event ---import Web.Event.Event (Event) import Bulma as Bulma import CSSClasses as C @@ -107,21 +104,18 @@ data Update_MODAL_Form | Update_MODAL_Weight Weight | Update_MODAL_Port Port --- TODO: remove this. data Update_SRR_Form = Update_SRR_Type Int | Update_SRR_Domain RecordName | Update_SRR_TTL TTL | Update_SRR_Target RecordTarget --- TODO: remove this. data Update_MX_Form = Update_MX_Domain RecordName | Update_MX_TTL TTL - | Update_MX_Target RecordTarget + | Update_MX_Target RecordTarget | Update_MX_Priority Priority --- TODO: remove this. data Update_SRV_Form = Update_SRV_Domain RecordName | Update_SRV_TTL TTL @@ -131,12 +125,6 @@ data Update_SRV_Form | Update_SRV_Weight Weight | Update_SRV_Port Port --- TODO: remove this. -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 - data Update_Local_Form = Update_Local_Form_SRR Update_SRR_Form | Update_Local_Form_MXRR Update_MX_Form @@ -152,9 +140,6 @@ data Action -- Add new entries. | AddRR AcceptedRRTypes - -- Update new entry forms. - | UpdateNewForm Update_New_Form - -- Update new entry form (in the `active_new_rr_modal` modal). | UpdateNewRRForm Update_MODAL_Form @@ -478,114 +463,38 @@ handleAction = case _ of state <- H.get H.modify_ _ { _newRR = state._newRR { port = val } } - UpdateNewForm form -> case form of - Update_New_Form_SRR rr_update -> case rr_update of - Update_SRR_Type val -> do - -- let new_type = fromMaybe "unknown" (baseRecords A.!! val) - -- H.raise $ Log $ SimpleLog ("Update new entry type: " <> new_type) - state <- H.get - H.modify_ _ { _newSRR = changeType state._newSRR (baseRecords A.!! val) } - Update_SRR_Domain val -> do - -- H.raise $ Log $ SimpleLog ("Update new entry name: " <> val) - H.modify_ _ { _newSRR { name = val } } - Update_SRR_TTL val -> do - -- H.raise $ Log $ SimpleLog ("Update new entry ttl: " <> val) - H.modify_ _ { _newSRR { ttl = val, valid = isInteger val } } - Update_SRR_Target val -> do - -- H.raise $ Log $ SimpleLog ("Update new entry target: " <> val) - H.modify_ _ { _newSRR { target = val } } - - Update_New_Form_MXRR rr_update -> case rr_update of - -- TODO: FIXME: test all inputs - Update_MX_Domain val -> do - -- H.raise $ Log $ SimpleLog ("Update new MX entry name: " <> val) - state <- H.get - H.modify_ _ { _newMXRR = state._newMXRR { name = val } } - -- TODO: FIXME: test all inputs - Update_MX_TTL val -> do - -- H.raise $ Log $ SimpleLog ("Update new MX entry ttl: " <> val) - state <- H.get - H.modify_ _ { _newMXRR = state._newMXRR {ttl = val, valid = isInteger val} } - -- TODO: FIXME: test all inputs - Update_MX_Target val -> do - -- H.raise $ Log $ SimpleLog ("Update new MX entry target: " <> val) - state <- H.get - H.modify_ _ { _newMXRR = state._newMXRR { target = val } } - Update_MX_Priority val -> do - -- H.raise $ Log $ SimpleLog ("Update new MX entry priority: " <> val) - state <- H.get - H.modify_ _ { _newMXRR = state._newMXRR { priority = val } } - - Update_New_Form_SRVRR rr_update -> case rr_update of - Update_SRV_Domain val -> do - -- H.raise $ Log $ SimpleLog ("Update new SRV entry name: " <> val) - state <- H.get - H.modify_ _ { _newSRVRR = state._newSRVRR { name = val } } - Update_SRV_Target val -> do - -- H.raise $ Log $ SimpleLog ("Update new SRV entry target: " <> val) - state <- H.get - H.modify_ _ { _newSRVRR = state._newSRVRR { target = val } } - -- TODO: FIXME: test all inputs - Update_SRV_TTL val -> do - -- H.raise $ Log $ SimpleLog ("Update new SRV entry ttl: " <> val) - state <- H.get - H.modify_ _ { _newSRVRR = state._newSRVRR {ttl = val, valid = isInteger val}} - Update_SRV_Priority val -> do - -- H.raise $ Log $ SimpleLog ("Update new SRV entry priority: " <> val) - state <- H.get - H.modify_ _ { _newSRVRR = state._newSRVRR { priority = val } } - Update_SRV_Protocol val -> do - -- H.raise $ Log $ SimpleLog ("Update new SRV entry protocol: " <> val) - state <- H.get - H.modify_ _ { _newSRVRR = state._newSRVRR { protocol = val } } - Update_SRV_Weight val -> do - -- H.raise $ Log $ SimpleLog ("Update new SRV entry weight: " <> val) - state <- H.get - H.modify_ _ { _newSRVRR = state._newSRVRR { weight = val } } - Update_SRV_Port val -> do - -- H.raise $ Log $ SimpleLog ("Update new SRV entry port: " <> val) - state <- H.get - H.modify_ _ { _newSRVRR = state._newSRVRR { port = val } } - - -- This action only is possible if inputs are correct. + -- | Try to add a resource record to the zone. + -- | Can fail if the content of the form isn't valid. + -- | + -- | TODO: perform verifications BEFORE this action can even be performed. AddRR form -> case form of A -> do - H.raise $ Log $ SimpleLog "TODO: trying to add a A RR!" state <- H.get - try_add_new_entry state._domain (Validation.validateSRR state._newRR) "simple" + try_add_new_entry state._domain (Validation.validateSRR state._newRR) "A" AAAA -> do - H.raise $ Log $ SimpleLog "TODO: trying to add a AAAA RR blah blah blah" state <- H.get - try_add_new_entry state._domain (Validation.validateSRR state._newRR) "simple" + try_add_new_entry state._domain (Validation.validateSRR state._newRR) "AAAA" TXT -> do - H.raise $ Log $ SimpleLog "TODO: trying to add a TXT RR blah blah blah" state <- H.get - try_add_new_entry state._domain (Validation.validateSRR state._newRR) "simple" + try_add_new_entry state._domain (Validation.validateSRR state._newRR) "TXT" CNAME -> do - H.raise $ Log $ SimpleLog "TODO: trying to add a CNAME RR blah blah blah" state <- H.get - try_add_new_entry state._domain (Validation.validateSRR state._newRR) "simple" + try_add_new_entry state._domain (Validation.validateSRR state._newRR) "CNAME" NS -> do - H.raise $ Log $ SimpleLog "TODO: trying to add a NS RR blah blah blah" state <- H.get - try_add_new_entry state._domain (Validation.validateSRR state._newRR) "simple" + try_add_new_entry state._domain (Validation.validateSRR state._newRR) "NS" MX -> do - H.raise $ Log $ SimpleLog "TODO: trying to add a MX RR blah blah blah" - 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" state <- H.get - try_add_new_entry state._domain (Validation.validateSRVRR state._newSRVRR) "SRV" + try_add_new_entry state._domain (Validation.validateMXRR state._newRR) "MX" + SRV -> do + state <- H.get + try_add_new_entry state._domain (Validation.validateSRVRR state._newRR) "SRV" UpdateLocalForm rr_id form -> case form of Update_Local_Form_SRR rr_update -> case rr_update of Update_SRR_Type val -> do let new_type = fromMaybe "unknown" (baseRecords A.!! val) H.raise $ Log $ SimpleLog ("TODO: Update local RR " <> show rr_id <> " type: " <> new_type) - -- state <- H.get - -- H.modify_ _ { _srr = changeType state._newSRR (baseRecords A.!! val) } Update_SRR_Domain val -> do -- H.raise $ Log $ SimpleLog ("Update local RR " <> show rr_id <> " name: " <> val) state <- H.get @@ -991,88 +900,8 @@ render_new_records state , Bulma.btn_add_new_rr (NewRRModal MX) "MX" , Bulma.btn_add_new_rr (NewRRModal SRV) "SRV" ] [] --- , Bulma.columns [] --- [ render_new_record_column_simple state._newSRR state._errors --- , render_new_record_colunm_mx state._newMXRR state._errors --- , render_new_record_colunm_srv state._newSRVRR state._errors --- -- , render_current_target state._newSRR --- -- , render_mx_current_target state._newMXRR --- -- , render_srv_current_target state._newSRVRR --- ] ] -{- -render_new_record_column_simple :: forall (w :: Type) - . (SimpleRR ()) -> Hash.HashMap RRId Validation.Errors -> HH.HTML w Action -render_new_record_column_simple rr _ - = Bulma.column_ $ [ Bulma.zone_rr_title $ S.joinWith ", " baseRecords - , type_selection - , Bulma.hr - , Bulma.box_input "domainSRR" "Domain" "www" -- id, title, placeholder - (UpdateNewForm <<< Update_New_Form_SRR <<< Update_SRR_Domain) -- action - rr.name -- value - rr.valid -- validity (TODO) - should_be_disabled -- condition - , Bulma.box_input "ttlSRR" "TTL" "3600" - (UpdateNewForm <<< Update_New_Form_SRR <<< Update_SRR_TTL) - rr.ttl - rr.valid - should_be_disabled - , Bulma.box_input "targetSRR" "Target" "198.51.100.5" - (UpdateNewForm <<< Update_New_Form_SRR <<< Update_SRR_Target) - rr.target - rr.valid - should_be_disabled - , Bulma.btn_add (AddRR Add_SRR) (TellSomethingWentWrong rr.rrid "cannot add") rr.valid - ] - where - should_be_disabled = (if true then (HP.enabled true) else (HP.disabled true)) - 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) ] - $ map type_option baseRecords - ] - type_option n - = HH.option - [ HP.value n - , HP.selected (n == rr.rrtype) - ] [ HH.text n ] - -render_new_record_colunm_mx :: forall (w :: Type) - . (MXRR ()) -> Hash.HashMap RRId Validation.Errors -> HH.HTML w Action -render_new_record_colunm_mx rr _ - = Bulma.column_ - [ Bulma.zone_rr_title "MX" - , Bulma.hr - , Bulma.box_input "domainMX" "Domain" "mail" (UpdateNewForm <<< Update_New_Form_MXRR <<< Update_MX_Domain) rr.name rr.valid should_be_disabled - , Bulma.box_input "ttlMX" "TTL" "3600" (UpdateNewForm <<< Update_New_Form_MXRR <<< Update_MX_TTL) rr.ttl rr.valid should_be_disabled - , Bulma.box_input "priorityMX" "Priority" "10" (UpdateNewForm <<< Update_New_Form_MXRR <<< Update_MX_Priority) rr.priority rr.valid should_be_disabled - , Bulma.box_input "targetMX" "Target" "www" (UpdateNewForm <<< Update_New_Form_MXRR <<< Update_MX_Target) rr.target rr.valid should_be_disabled - , Bulma.btn_add (AddRR Add_MXRR) (TellSomethingWentWrong rr.rrid "cannot add") rr.valid - ] - where - should_be_disabled = (if true then (HP.enabled true) else (HP.disabled true)) - -render_new_record_colunm_srv :: forall (w :: Type) - . (SRVRR ()) -> Hash.HashMap RRId Validation.Errors -> HH.HTML w Action -render_new_record_colunm_srv rr _ - = Bulma.column_ - [ Bulma.zone_rr_title "SRV" - , Bulma.hr - , Bulma.box_input "nameSRV" "Name" "_sip._tcp" (UpdateNewForm <<< Update_New_Form_SRVRR <<< Update_SRV_Domain) rr.name rr.valid should_be_disabled - , Bulma.box_input "ttlSRV" "TTL" "3600" (UpdateNewForm <<< Update_New_Form_SRVRR <<< Update_SRV_TTL) rr.ttl rr.valid should_be_disabled - , Bulma.box_input "prioritySRV" "Priority" "10" (UpdateNewForm <<< Update_New_Form_SRVRR <<< Update_SRV_Priority) rr.priority rr.valid should_be_disabled - , Bulma.box_input "protocolSRV" "Protocol" "tcp" (UpdateNewForm <<< Update_New_Form_SRVRR <<< Update_SRV_Protocol) rr.protocol rr.valid should_be_disabled - , Bulma.box_input "weightSRV" "Weight" "10" (UpdateNewForm <<< Update_New_Form_SRVRR <<< Update_SRV_Weight) rr.weight rr.valid should_be_disabled - , Bulma.box_input "portSRV" "Port" "80" (UpdateNewForm <<< Update_New_Form_SRVRR <<< Update_SRV_Port) rr.port rr.valid should_be_disabled - , Bulma.box_input "targetSRV" "Target" "example.com." (UpdateNewForm <<< Update_New_Form_SRVRR <<< Update_SRV_Target) rr.target rr.valid should_be_disabled - , Bulma.btn_add (AddRR Add_SRVRR) (TellSomethingWentWrong rr.rrid "cannot add") rr.valid - ] - where - should_be_disabled = (if true then (HP.enabled true) else (HP.disabled true)) --} - -- ACTIONS -- add a new record and get a new placeholter @@ -1098,10 +927,6 @@ new_soa state = case _ of Nothing -> state Just rr -> state { _soa = Just rr } -changeType :: forall (l :: Row Type). (SimpleRR l) -> Maybe String -> (SimpleRR l) -changeType rr Nothing = rr -changeType rr (Just s) = rr { rrtype = s } - update_domain :: forall (l :: Row Type). Int -> String -> Array (SimpleRR l) -> Array (SimpleRR l) update_domain rr_id val = update (\rr -> rr { modified = true, name = val }) rr_id