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