UpdateLocalForm: simpler code, could replace dozens and dozens of lines.
This commit is contained in:
parent
08dcd6d875
commit
2904a0e089
@ -131,24 +131,38 @@ data Update_Local_Form
|
||||
| Update_Local_Form_SRVRR Update_SRV_Form
|
||||
|
||||
data Action
|
||||
-- | Create a modal to ask confirmation before deleting a resource record.
|
||||
= DeleteRRModal RRId
|
||||
|
||||
-- | Cancel the current displayed modal.
|
||||
| CancelModal
|
||||
|
||||
-- | Create a new resource record modal (a form) for a certain type of component.
|
||||
| NewRRModal AcceptedRRTypes
|
||||
|
||||
-- | Initiate the component. This means asking the content of the zone to `dnsmanagerd`.
|
||||
| Initialize
|
||||
|
||||
-- Add new entries.
|
||||
-- | Add a new resource record to the zone.
|
||||
| AddRR AcceptedRRTypes ResourceRecord
|
||||
-- Validate a new resource record before adding it.
|
||||
|
||||
-- | Validate a new resource record before adding it.
|
||||
| ValidateRR AcceptedRRTypes
|
||||
|
||||
-- | Validate the entries in an already existing resource record.
|
||||
| ValidateLocal RRId AcceptedRRTypes
|
||||
|
||||
-- | Save the changes done in an already existing resource record.
|
||||
| SaveLocal ResourceRecord
|
||||
|
||||
-- Update new entry form (in the `active_new_rr_modal` modal).
|
||||
-- | Update new entry form (in the `active_new_rr_modal` modal).
|
||||
| UpdateNewRRForm Update_MODAL_Form
|
||||
|
||||
-- Update an already active entry.
|
||||
| UpdateLocalForm RRId Update_Local_Form
|
||||
-- TODO: Update an already existing resource record.
|
||||
| UpdateLocalForm (SRVRR ())
|
||||
|
||||
-- | Update an already active entry.
|
||||
| UpdateLocalRR RRId Update_Local_Form
|
||||
|
||||
| SaveSRR RRId
|
||||
| SaveMXRR RRId
|
||||
@ -511,7 +525,14 @@ handleAction = case _ of
|
||||
$ DNSManager.MkAddRR { domain: state._domain, rr: newrr }
|
||||
H.raise $ MessageToSend message
|
||||
|
||||
UpdateLocalForm rr_id form -> case form of
|
||||
UpdateLocalForm entry -> do
|
||||
state <- H.get
|
||||
H.raise $ Log $ SimpleLog $ "Let's try to update entry number " <> show entry.rrid
|
||||
let replaceRR rr1 rr2 | rr1.rrid == rr2.rrid = rr1
|
||||
| otherwise = rr2
|
||||
H.modify_ _ { _resources = (map (replaceRR entry) state._resources) }
|
||||
|
||||
UpdateLocalRR rr_id form -> case form of
|
||||
Update_Local_Form_SRR rr_update -> case rr_update of
|
||||
Update_SRR_Domain val -> do
|
||||
-- H.raise $ Log $ SimpleLog ("Update local RR " <> show rr_id <> " name: " <> val)
|
||||
@ -578,7 +599,7 @@ handleAction = case _ of
|
||||
state <- H.get
|
||||
H.modify_ _ { _srvrr = (update_port rr_id val state._srvrr) }
|
||||
|
||||
-- TODO: validate any local RR with the new _resources and _local_errors.
|
||||
-- | validate any local RR with the new _resources and _local_errors.
|
||||
ValidateLocal local_rr_id t -> do
|
||||
state <- H.get
|
||||
case first (\rr -> rr.rrid == local_rr_id) state._resources of
|
||||
@ -594,10 +615,6 @@ handleAction = case _ of
|
||||
let new_error_hash = Hash.delete local_rr.rrid state._local_errors
|
||||
H.modify_ _ { _local_errors = new_error_hash }
|
||||
handleAction $ SaveLocal rr
|
||||
message <- H.liftEffect
|
||||
$ DNSManager.serialize
|
||||
$ DNSManager.MkUpdateRR { domain: state._domain, rr: rr }
|
||||
H.raise $ MessageToSend message
|
||||
|
||||
SaveLocal rr -> do
|
||||
state <- H.get
|
||||
@ -809,7 +826,7 @@ render_resources errors records
|
||||
-- , HH.td_ [ Bulma.btn_delete (\_ -> DeleteRRModal rr.rrid) ]
|
||||
-- ]
|
||||
-- ] <> error_row rr
|
||||
-- update_simple rrid v = (UpdateLocalForm rrid) <<< Update_Local_Form_SRR <<< v
|
||||
-- update_simple rrid v = (UpdateLocalRR rrid) <<< Update_Local_Form_SRR <<< v
|
||||
-- error_row rr = case Hash.lookup rr.rrid errors of
|
||||
-- Nothing -> []
|
||||
-- Just error_array -> [ HH.tr_ $
|
||||
@ -850,7 +867,7 @@ render_records errors records
|
||||
, HH.td_ [ Bulma.btn_delete (\_ -> DeleteRRModal rr.rrid) ]
|
||||
]
|
||||
] <> error_row rr
|
||||
update_simple rrid v = (UpdateLocalForm rrid) <<< Update_Local_Form_SRR <<< v
|
||||
update_simple rrid v = (UpdateLocalRR rrid) <<< Update_Local_Form_SRR <<< v
|
||||
error_row rr = case Hash.lookup rr.rrid errors of
|
||||
Nothing -> []
|
||||
Just error_array -> [ HH.tr_ $
|
||||
@ -895,7 +912,7 @@ render_mx_records errors records
|
||||
, HH.td_ [ Bulma.btn_delete (\_ -> DeleteRRModal rr.rrid) ]
|
||||
]
|
||||
] <> error_row rr
|
||||
update_mx rrid v = (UpdateLocalForm rrid) <<< Update_Local_Form_MXRR <<< v
|
||||
update_mx rrid v = (UpdateLocalRR rrid) <<< Update_Local_Form_MXRR <<< v
|
||||
error_row rr = case Hash.lookup rr.rrid errors of
|
||||
Nothing -> []
|
||||
Just error_array ->
|
||||
@ -936,7 +953,7 @@ render_srv_records errors records
|
||||
, HH.td_ [ Bulma.btn_delete (\_ -> DeleteRRModal rr.rrid) ]
|
||||
]
|
||||
] <> error_row rr
|
||||
update_srv rrid v = (UpdateLocalForm rrid) <<< Update_Local_Form_SRVRR <<< v
|
||||
update_srv rrid v = (UpdateLocalRR rrid) <<< Update_Local_Form_SRVRR <<< v
|
||||
error_row rr = case Hash.lookup rr.rrid errors of
|
||||
Nothing -> []
|
||||
Just error_array ->
|
||||
@ -1033,7 +1050,7 @@ update f rr_id records = map doSmth records
|
||||
where
|
||||
doSmth rr
|
||||
| rr_id == rr.rrid = f rr
|
||||
| otherwise = rr
|
||||
| otherwise = rr
|
||||
|
||||
fromResourceRecordToLocalRepresentationSimpleRR :: ResourceRecord -> Maybe (SimpleRR ())
|
||||
fromResourceRecordToLocalRepresentationSimpleRR new_rr =
|
||||
|
Loading…
Reference in New Issue
Block a user