Can add new MX RR. RR removal implies a modal.

This commit is contained in:
Philippe Pittoli 2023-07-11 02:00:29 +02:00
parent 2f7ac68e2c
commit e60ce8f8b4
2 changed files with 37 additions and 32 deletions

View File

@ -18,6 +18,7 @@
, "foreign"
, "halogen"
, "halogen-subscriptions"
, "integers"
, "maybe"
, "newtype"
, "parsing"

View File

@ -11,6 +11,7 @@ module App.ZoneInterface where
import Prelude (Unit, bind, comparing, discard, map, max, otherwise, pure, show, ($), (+), (/=), (<<<), (<>), (==))
import Data.Array as A
import Data.Int (fromString)
import Data.ArrayBuffer.Types (ArrayBuffer)
import Data.Array.NonEmpty as NonEmpty
import Data.Either (Either(..))
@ -89,7 +90,7 @@ data Update_SRV_Form
| Update_SRV_Port Port
data Action
= DeleteRRModal Int
= DeleteRRModal RRId
| CancelModal
| Initialize
@ -106,17 +107,12 @@ data Action
| AddSRV
-- Entry already in our zone.
| UpdateLocalSRRForm RRId Update_SRR_Form
| UpdateLocalMXForm RRId Update_MX_Form
| UpdateLocalSRVForm RRId Update_SRV_Form
| UpdateLocalSRRForm RRId Update_SRR_Form
| UpdateLocalMXForm RRId Update_MX_Form
| UpdateLocalSRVForm RRId Update_SRV_Form
| SyncRR RRId
| RemoveRR RRId
| DeleteSimple RRId
| DeleteMX RRId
| DeleteSRV RRId
| RemoveRR RRId
| TellSomethingWentWrong RRId String
@ -307,8 +303,33 @@ handleAction = case _ of
H.put $ add_new_entry state state._current_entry
AddMX -> do
state <- H.get
let form = state._current_entry_mx
newttl = fromMaybe 3600 $ fromString form.ttl
newpriority = fromMaybe 10 $ fromString form.priority
newrr = { rrtype: form.t
, rrid: 0 -- garbage value anyway
, name: form.domain
, ttl: newttl
, target: form.value
, readonly: false
, priority: Just newpriority
, port: Nothing
, protocol: Nothing
, weight: Nothing
, mname: Nothing
, rname: Nothing
, serial: Nothing
, refresh: Nothing
, retry: Nothing
, expire: Nothing
, minttl: Nothing
}
H.raise $ Log $ SimpleLog ("Add new MX: " <> show state._current_entry_mx)
H.put $ add_new_mx state state._current_entry_mx
-- H.put $ add_new_mx state state._current_entry_mx
message <- H.liftEffect
$ DNSManager.serialize
$ DNSManager.MkAddRR { domain: state._current_domain, rr: newrr }
H.raise $ MessageToSend message
AddSRV -> do
state <- H.get
H.raise $ Log $ SimpleLog ("Add new SRV: " <> show state._current_entry_srv)
@ -392,22 +413,7 @@ handleAction = case _ of
$ DNSManager.serialize
$ DNSManager.MkDeleteRR { domain: _current_domain, rrid: rr_id }
H.raise $ MessageToSend message
DeleteSimple rr_id -> do
H.raise $ Log $ SimpleLog ("Delete SimpleRR: " <> show rr_id)
state <- H.get
H.modify_ _ { _srr = A.filter (\rr -> rr.id /= rr_id) state._srr }
H.raise $ Log $ SimpleLog ("TODO: remove from server")
DeleteMX rr_id -> do
H.raise $ Log $ SimpleLog ("Delete MX: " <> show rr_id)
state <- H.get
H.modify_ _ { _mxrr = A.filter (\rr -> rr.id /= rr_id) state._mxrr }
H.raise $ Log $ SimpleLog ("TODO: remove from server")
DeleteSRV rr_id -> do
H.raise $ Log $ SimpleLog ("Delete SRV: " <> show rr_id)
state <- H.get
H.modify_ _ { _srvrr = A.filter (\rr -> rr.id /= rr_id) state._srvrr }
H.raise $ Log $ SimpleLog ("TODO: remove from server")
H.modify_ _ { active_modal = Nothing }
-- TODO: change the state to indicate problems?
TellSomethingWentWrong rr_id val -> do
@ -568,7 +574,7 @@ render_records records
, HH.td_ [ Bulma.input_ttl ((UpdateLocalSRRForm rr.id) <<< Update_SRR_TTL ) rr.ttl rr.valid ]
, HH.td_ [ Bulma.input_value ((UpdateLocalSRRForm rr.id) <<< Update_SRR_Value) rr.value rr.valid ]
, HH.td_ [ Bulma.btn_change (SyncRR rr.id) (TellSomethingWentWrong rr.id "cannot update") rr.modified rr.valid ]
, HH.td_ [ Bulma.btn_delete (\_ -> DeleteSimple rr.id) ]
, HH.td_ [ Bulma.btn_delete (\_ -> DeleteRRModal rr.id) ]
]
@ -593,7 +599,7 @@ render_mx_records records
, HH.td_ [ Bulma.input_priority ((UpdateLocalMXForm rr.id) <<< Update_MX_Priority) rr.priority rr.valid ]
, HH.td_ [ Bulma.input_value ((UpdateLocalMXForm rr.id) <<< Update_MX_Value) rr.value rr.valid ]
, HH.td_ [ Bulma.btn_change (SyncRR rr.id) (TellSomethingWentWrong rr.id "cannot update") rr.modified rr.valid ]
, HH.td_ [ Bulma.btn_delete (\_ -> DeleteMX rr.id) ]
, HH.td_ [ Bulma.btn_delete (\_ -> DeleteRRModal rr.id) ]
]
@ -619,7 +625,7 @@ render_srv_records records
, HH.td_ [ Bulma.input_port ((UpdateLocalSRVForm rr.id) <<< Update_SRV_Port ) rr.port rr.valid ]
, HH.td_ [ Bulma.input_value ((UpdateLocalSRVForm rr.id) <<< Update_SRV_Value ) rr.value rr.valid ]
, HH.td_ [ Bulma.btn_change (SyncRR rr.id) (TellSomethingWentWrong rr.id "cannot update") rr.modified rr.valid ]
, HH.td_ [ Bulma.btn_delete (\_ -> DeleteSRV rr.id) ]
, HH.td_ [ Bulma.btn_delete (\_ -> DeleteRRModal rr.id) ]
]
@ -812,7 +818,6 @@ update_weight rr_id val = update (\rr -> rr { modified = true, weight = val}) rr
update_port :: Int -> Priority -> Array (SRVRR ()) -> Array (SRVRR ())
update_port rr_id val = update (\rr -> rr { modified = true, port = val}) rr_id
isIntRegex :: Regex.Regex
isIntRegex = RegexUnsafe.unsafeRegex "^[0-9]*$" RegexFlags.noFlags
@ -839,4 +844,3 @@ getNewID state = (_ + 1)
maxIDrr = Foldable.foldl max 0 $ map _.id state._srr
maxIDmxrr = Foldable.foldl max 0 $ map _.id state._mxrr
maxIDsrvrr = Foldable.foldl max 0 $ map _.id state._srvrr