WIP: a single entry in the state for all resources.
parent
cfd356a650
commit
08dcd6d875
|
@ -141,6 +141,8 @@ data Action
|
||||||
| 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
|
||||||
|
| ValidateLocal RRId AcceptedRRTypes
|
||||||
|
| 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
|
||||||
|
@ -166,6 +168,11 @@ type State =
|
||||||
-- A modal to present a form for adding a new RR.
|
-- A modal to present a form for adding a new RR.
|
||||||
, active_new_rr_modal :: Maybe AcceptedRRTypes
|
, active_new_rr_modal :: Maybe AcceptedRRTypes
|
||||||
|
|
||||||
|
-- TODO: get all the resources in a single entry.
|
||||||
|
-- Better that way: simpler code.
|
||||||
|
, _resources :: Array (SRVRR ())
|
||||||
|
, _local_errors :: Hash.HashMap RRId (Array Validation.ValidationError)
|
||||||
|
|
||||||
-- current entries
|
-- current entries
|
||||||
, _soa :: Maybe (SOARR ())
|
, _soa :: Maybe (SOARR ())
|
||||||
, _srr :: Array (SimpleRR ())
|
, _srr :: Array (SimpleRR ())
|
||||||
|
@ -211,6 +218,9 @@ initialState domain =
|
||||||
|
|
||||||
, _domain: domain
|
, _domain: domain
|
||||||
|
|
||||||
|
, _resources: []
|
||||||
|
, _local_errors: Hash.empty
|
||||||
|
|
||||||
, _soa: Nothing
|
, _soa: Nothing
|
||||||
, _srr: []
|
, _srr: []
|
||||||
, _mxrr: []
|
, _mxrr: []
|
||||||
|
@ -240,6 +250,8 @@ render state
|
||||||
true, Just rr_id, _ -> modal_rr_delete rr_id
|
true, Just rr_id, _ -> modal_rr_delete rr_id
|
||||||
true, Nothing, Just t -> modal_add_new_rr t
|
true, Nothing, Just t -> modal_add_new_rr t
|
||||||
true, Nothing, Nothing -> HH.div_ [ Bulma.h1 state._domain
|
true, Nothing, Nothing -> HH.div_ [ Bulma.h1 state._domain
|
||||||
|
, Bulma.hr
|
||||||
|
, render_resources state._local_errors $ sorted state._resources
|
||||||
, Bulma.hr
|
, Bulma.hr
|
||||||
, render_soa state._soa
|
, render_soa state._soa
|
||||||
, render_records state._errors $ sorted state._srr
|
, render_records state._errors $ sorted state._srr
|
||||||
|
@ -566,6 +578,35 @@ 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.
|
||||||
|
ValidateLocal local_rr_id t -> do
|
||||||
|
state <- H.get
|
||||||
|
case first (\rr -> rr.rrid == local_rr_id) state._resources of
|
||||||
|
Nothing -> H.raise $ Log $ SimpleLog $ "Cannot find RR number: " <> show local_rr_id
|
||||||
|
Just local_rr -> do
|
||||||
|
case Validation.validation local_rr t of
|
||||||
|
Left actual_errors -> do
|
||||||
|
let new_error_hash = Hash.insert local_rr.rrid actual_errors state._local_errors
|
||||||
|
H.modify_ _ { _local_errors = new_error_hash }
|
||||||
|
H.raise $ Log $ SimpleLog $ "[😈] Errors in RR id " <> show local_rr_id
|
||||||
|
<> ". Please fix them before update."
|
||||||
|
Right rr -> do
|
||||||
|
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
|
||||||
|
H.raise $ Log $ SimpleLog $ "Updating RR " <> show rr.rrid
|
||||||
|
message <- H.liftEffect
|
||||||
|
$ DNSManager.serialize
|
||||||
|
$ DNSManager.MkUpdateRR { domain: state._domain, rr: rr }
|
||||||
|
H.raise $ MessageToSend message
|
||||||
|
|
||||||
SaveSRR local_rr_id -> do
|
SaveSRR local_rr_id -> do
|
||||||
state <- H.get
|
state <- H.get
|
||||||
let maybe_local_rr = first (\rr -> rr.rrid == local_rr_id) state._srr
|
let maybe_local_rr = first (\rr -> rr.rrid == local_rr_id) state._srr
|
||||||
|
@ -738,6 +779,49 @@ render_soa (Just soa) = Bulma.box [ Bulma.zone_rr_title "Start Of Authority (SOA
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
-- | Render all Resource Records.
|
||||||
|
render_resources :: forall (w :: Type). Hash.HashMap RRId (Array Validation.ValidationError) -> Array (SRVRR ()) -> HH.HTML w Action
|
||||||
|
render_resources _ []
|
||||||
|
= Bulma.box [ Bulma.zone_rr_title "All records (TEST)"
|
||||||
|
, Bulma.subtitle "No records for now"
|
||||||
|
]
|
||||||
|
render_resources errors records
|
||||||
|
= Bulma.box [ Bulma.zone_rr_title "All records (TEST)"
|
||||||
|
, Bulma.subtitle "TODO: display the records."
|
||||||
|
]
|
||||||
|
--render_resources errors records
|
||||||
|
-- = Bulma.box [ Bulma.zone_rr_title "All records (TEST)"
|
||||||
|
-- , table_rr
|
||||||
|
-- ]
|
||||||
|
-- where
|
||||||
|
-- table_rr = Bulma.table [] [ Bulma.zone_rr_title "XXX", table_content ]
|
||||||
|
-- table_content = HH.tbody_ $ A.concat $ map rows records
|
||||||
|
-- rows rr
|
||||||
|
-- = [ HH.tr_ $
|
||||||
|
-- [ Bulma.txt_name rr.rrtype
|
||||||
|
-- , HH.td_ [ Bulma.input_domain (update_simple rr.rrid Update_SRR_Domain) rr.name rr.valid ]
|
||||||
|
-- , HH.td_ [ Bulma.input_ttl (update_simple rr.rrid Update_SRR_TTL ) rr.ttl rr.valid ]
|
||||||
|
-- , HH.td_ [ case rr.rrtype of
|
||||||
|
-- "TXT" -> Bulma.textarea (update_simple rr.rrid Update_SRR_Target) rr.target rr.valid
|
||||||
|
-- _ -> Bulma.input_target (update_simple rr.rrid Update_SRR_Target) rr.target rr.valid
|
||||||
|
-- ]
|
||||||
|
-- , HH.td_ [ Bulma.btn_change (SaveSRR rr.rrid) (TellSomethingWentWrong rr.rrid "cannot update") rr.modified rr.valid ]
|
||||||
|
-- , HH.td_ [ Bulma.btn_delete (\_ -> DeleteRRModal rr.rrid) ]
|
||||||
|
-- ]
|
||||||
|
-- ] <> error_row rr
|
||||||
|
-- update_simple rrid v = (UpdateLocalForm rrid) <<< Update_Local_Form_SRR <<< v
|
||||||
|
-- error_row rr = case Hash.lookup rr.rrid errors of
|
||||||
|
-- Nothing -> []
|
||||||
|
-- Just error_array -> [ HH.tr_ $
|
||||||
|
-- [ Bulma.txt_name ""
|
||||||
|
-- , HH.td_ $ from_error_array_to_td error_array Validation.Name
|
||||||
|
-- , HH.td_ $ from_error_array_to_td error_array Validation.TTL
|
||||||
|
-- , HH.td_ $ from_error_array_to_td error_array Validation.Target
|
||||||
|
-- , HH.td_ []
|
||||||
|
-- , HH.td_ []
|
||||||
|
-- ]
|
||||||
|
-- ]
|
||||||
|
|
||||||
render_records :: forall (w :: Type). Hash.HashMap RRId Validation.Errors -> Array (SimpleRR ()) -> HH.HTML w Action
|
render_records :: forall (w :: Type). Hash.HashMap RRId Validation.Errors -> Array (SimpleRR ()) -> HH.HTML w Action
|
||||||
render_records _ []
|
render_records _ []
|
||||||
= Bulma.box [ Bulma.zone_rr_title $ S.joinWith ", " baseRecords
|
= Bulma.box [ Bulma.zone_rr_title $ S.joinWith ", " baseRecords
|
||||||
|
@ -756,16 +840,17 @@ render_records errors records
|
||||||
rows rr
|
rows rr
|
||||||
= [ HH.tr_ $
|
= [ HH.tr_ $
|
||||||
[ Bulma.txt_name rr.rrtype
|
[ Bulma.txt_name rr.rrtype
|
||||||
, HH.td_ [ Bulma.input_domain ((UpdateLocalForm rr.rrid) <<< Update_Local_Form_SRR <<< Update_SRR_Domain) rr.name rr.valid ]
|
, HH.td_ [ Bulma.input_domain (update_simple rr.rrid Update_SRR_Domain) rr.name rr.valid ]
|
||||||
, HH.td_ [ Bulma.input_ttl ((UpdateLocalForm rr.rrid) <<< Update_Local_Form_SRR <<< Update_SRR_TTL ) rr.ttl rr.valid ]
|
, HH.td_ [ Bulma.input_ttl (update_simple rr.rrid Update_SRR_TTL ) rr.ttl rr.valid ]
|
||||||
, HH.td_ [ case rr.rrtype of
|
, HH.td_ [ case rr.rrtype of
|
||||||
"TXT" -> Bulma.textarea ((UpdateLocalForm rr.rrid) <<< Update_Local_Form_SRR <<< Update_SRR_Target) rr.target rr.valid
|
"TXT" -> Bulma.textarea (update_simple rr.rrid Update_SRR_Target) rr.target rr.valid
|
||||||
_ -> Bulma.input_target ((UpdateLocalForm rr.rrid) <<< Update_Local_Form_SRR <<< Update_SRR_Target) rr.target rr.valid
|
_ -> Bulma.input_target (update_simple rr.rrid Update_SRR_Target) rr.target rr.valid
|
||||||
]
|
]
|
||||||
, HH.td_ [ Bulma.btn_change (SaveSRR rr.rrid) (TellSomethingWentWrong rr.rrid "cannot update") rr.modified rr.valid ]
|
, HH.td_ [ Bulma.btn_change (SaveSRR rr.rrid) (TellSomethingWentWrong rr.rrid "cannot update") rr.modified rr.valid ]
|
||||||
, 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
|
||||||
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_ $
|
||||||
|
@ -802,14 +887,15 @@ render_mx_records errors records
|
||||||
table_content = HH.tbody_ $ A.concat $ map rows records
|
table_content = HH.tbody_ $ A.concat $ map rows records
|
||||||
|
|
||||||
rows rr = [ HH.tr_ $
|
rows rr = [ HH.tr_ $
|
||||||
[ HH.td_ [ Bulma.input_domain ((UpdateLocalForm rr.rrid) <<< Update_Local_Form_MXRR <<< Update_MX_Domain) rr.name rr.valid ]
|
[ HH.td_ [ Bulma.input_domain (update_mx rr.rrid Update_MX_Domain) rr.name rr.valid ]
|
||||||
, HH.td_ [ Bulma.input_ttl ((UpdateLocalForm rr.rrid) <<< Update_Local_Form_MXRR <<< Update_MX_TTL) rr.ttl rr.valid ]
|
, HH.td_ [ Bulma.input_ttl (update_mx rr.rrid Update_MX_TTL) rr.ttl rr.valid ]
|
||||||
, HH.td_ [ Bulma.input_priority ((UpdateLocalForm rr.rrid) <<< Update_Local_Form_MXRR <<< Update_MX_Priority) rr.priority rr.valid ]
|
, HH.td_ [ Bulma.input_priority (update_mx rr.rrid Update_MX_Priority) rr.priority rr.valid ]
|
||||||
, HH.td_ [ Bulma.input_target ((UpdateLocalForm rr.rrid) <<< Update_Local_Form_MXRR <<< Update_MX_Target) rr.target rr.valid ]
|
, HH.td_ [ Bulma.input_target (update_mx rr.rrid Update_MX_Target) rr.target rr.valid ]
|
||||||
, HH.td_ [ Bulma.btn_change (SaveMXRR rr.rrid) (TellSomethingWentWrong rr.rrid "cannot update") rr.modified rr.valid ]
|
, HH.td_ [ Bulma.btn_change (SaveMXRR rr.rrid) (TellSomethingWentWrong rr.rrid "cannot update") rr.modified rr.valid ]
|
||||||
, 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
|
||||||
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 ->
|
||||||
|
@ -839,17 +925,18 @@ render_srv_records errors records
|
||||||
|
|
||||||
rows rr
|
rows rr
|
||||||
= [ HH.tr_ $
|
= [ HH.tr_ $
|
||||||
[ HH.td_ [ Bulma.input_domain ((UpdateLocalForm rr.rrid) <<< Update_Local_Form_SRVRR <<< Update_SRV_Domain ) rr.name rr.valid ]
|
[ HH.td_ [ Bulma.input_domain (update_srv rr.rrid Update_SRV_Domain ) rr.name rr.valid ]
|
||||||
, HH.td_ [ Bulma.input_ttl ((UpdateLocalForm rr.rrid) <<< Update_Local_Form_SRVRR <<< Update_SRV_TTL ) rr.ttl rr.valid ]
|
, HH.td_ [ Bulma.input_ttl (update_srv rr.rrid Update_SRV_TTL ) rr.ttl rr.valid ]
|
||||||
, HH.td_ [ Bulma.input_priority ((UpdateLocalForm rr.rrid) <<< Update_Local_Form_SRVRR <<< Update_SRV_Priority) rr.priority rr.valid ]
|
, HH.td_ [ Bulma.input_priority (update_srv rr.rrid Update_SRV_Priority) rr.priority rr.valid ]
|
||||||
, HH.td_ [ Bulma.input_protocol ((UpdateLocalForm rr.rrid) <<< Update_Local_Form_SRVRR <<< Update_SRV_Protocol) rr.protocol rr.valid ]
|
, HH.td_ [ Bulma.input_protocol (update_srv rr.rrid Update_SRV_Protocol) rr.protocol rr.valid ]
|
||||||
, HH.td_ [ Bulma.input_weight ((UpdateLocalForm rr.rrid) <<< Update_Local_Form_SRVRR <<< Update_SRV_Weight ) rr.weight rr.valid ]
|
, HH.td_ [ Bulma.input_weight (update_srv rr.rrid Update_SRV_Weight ) rr.weight rr.valid ]
|
||||||
, HH.td_ [ Bulma.input_port ((UpdateLocalForm rr.rrid) <<< Update_Local_Form_SRVRR <<< Update_SRV_Port ) rr.port rr.valid ]
|
, HH.td_ [ Bulma.input_port (update_srv rr.rrid Update_SRV_Port ) rr.port rr.valid ]
|
||||||
, HH.td_ [ Bulma.input_target ((UpdateLocalForm rr.rrid) <<< Update_Local_Form_SRVRR <<< Update_SRV_Target ) rr.target rr.valid ]
|
, HH.td_ [ Bulma.input_target (update_srv rr.rrid Update_SRV_Target ) rr.target rr.valid ]
|
||||||
, HH.td_ [ Bulma.btn_change (SaveSRVRR rr.rrid) (TellSomethingWentWrong rr.rrid "cannot update") rr.modified rr.valid ]
|
, HH.td_ [ Bulma.btn_change (SaveSRVRR rr.rrid) (TellSomethingWentWrong rr.rrid "cannot update") rr.modified rr.valid ]
|
||||||
, 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
|
||||||
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 ->
|
||||||
|
|
Loading…
Reference in New Issue