Minor code changes.
This commit is contained in:
parent
c35544f55e
commit
2f2d02249b
@ -34,7 +34,6 @@ error_to_paragraph v = Bulma.error_message (Bulma.p $ show_error_title v)
|
||||
<> ", current value: " <> show n <> "."
|
||||
ValidationDNS.VEWeight min max n -> Bulma.p $ "Weight should have a value between " <> show min <> " and " <> show max
|
||||
<> ", current value: " <> show n <> "."
|
||||
ValidationDNS.VESPF err -> maybe default_error show_error_domain err.error
|
||||
)
|
||||
where default_error = Bulma.p ""
|
||||
|
||||
@ -55,7 +54,6 @@ show_error_title v = case v of
|
||||
ValidationDNS.VEProtocol err -> "The Protocol input is wrong (position: " <> show err.position <> ")"
|
||||
ValidationDNS.VEPort min max n -> "Invalid Port (min: " <> show min <> ", max: " <> show max <> ", n: " <> show n <> ")"
|
||||
ValidationDNS.VEWeight min max n -> "Invalid Weight (min: " <> show min <> ", max: " <> show max <> ", n: " <> show n <> ")"
|
||||
ValidationDNS.VESPF err -> "The SPF target input is wrong (position: " <> show err.position <> ")"
|
||||
|
||||
show_error_domain :: forall w i. DomainParser.DomainError -> HH.HTML w i
|
||||
show_error_domain e = case e of
|
||||
|
@ -44,7 +44,6 @@ data Error
|
||||
| VEMX (G.Error DomainParser.DomainError)
|
||||
| VEPriority Int Int Int
|
||||
| VESRV (G.Error DomainParser.DomainError)
|
||||
| VESPF (G.Error DomainParser.DomainError)
|
||||
| VEProtocol (G.Error ProtocolError)
|
||||
| VEPort Int Int Int
|
||||
| VEWeight Int Int Int
|
||||
@ -183,9 +182,8 @@ validationSPF :: ResourceRecord -> V (Array Error) ResourceRecord
|
||||
validationSPF form = ado
|
||||
name <- parse DomainParser.sub_eof form.name VEName
|
||||
ttl <- is_between min_ttl max_ttl form.ttl VETTL
|
||||
target <- parse DomainParser.sub_eof form.target VESPF
|
||||
in emptyRR { rrid = form.rrid, readonly = form.readonly, rrtype = "SPF"
|
||||
, name = name, ttl = ttl, target = target
|
||||
, name = name, ttl = ttl, target = ""
|
||||
, v = form.v, mechanisms = maybe (Just []) Just form.mechanisms
|
||||
, modifiers = form.modifiers, q = form.q }
|
||||
|
||||
|
@ -395,10 +395,6 @@ render state
|
||||
(updateForm Field_TTL)
|
||||
(show state._currentRR.ttl)
|
||||
should_be_disabled
|
||||
, Bulma.box_input "targetSPF" "Target" "www"
|
||||
(updateForm Field_Target)
|
||||
state._currentRR.target
|
||||
should_be_disabled
|
||||
, case state._currentRR.v of
|
||||
Nothing -> Bulma.p "default value for the version (spf1)"
|
||||
Just v -> Bulma.box_input "vSPF" "Version" "spf1" (updateForm Field_SPF_v) v should_be_disabled
|
||||
@ -676,46 +672,38 @@ handleQuery = case _ of
|
||||
add_RR state new_rr = state { _resources = (state._resources <> [ new_rr ]) }
|
||||
|
||||
-- Rendering
|
||||
render_soa :: forall (w :: Type). Maybe ResourceRecord -> HH.HTML w Action
|
||||
render_soa Nothing = Bulma.box [ HH.text "SOA not loaded, yet" ]
|
||||
render_soa (Just soa) = Bulma.box [ Bulma.zone_rr_title "Start Of Authority (SOA)"
|
||||
, table_rr
|
||||
]
|
||||
where table_rr = Bulma.table [] [ Bulma.soa_table_header, table_content ]
|
||||
table_content
|
||||
= HH.tbody_ $ [ HH.tr_ $ [
|
||||
--, Bulma.p $ "rrtype: " <> soa.rrtype
|
||||
--, Bulma.p $ "rrid: " <> show soa.rrid
|
||||
HH.td_ [ HH.text soa.name ]
|
||||
, HH.td_ [ HH.text $ show soa.ttl ]
|
||||
, HH.td_ [ HH.text soa.target ]
|
||||
, HH.td_ [ HH.text $ maybe "" id soa.mname ]
|
||||
, HH.td_ [ HH.text $ maybe "" id soa.rname ]
|
||||
, HH.td_ [ HH.text $ maybe "" show soa.serial ]
|
||||
, HH.td_ [ HH.text $ maybe "" show soa.refresh ]
|
||||
, HH.td_ [ HH.text $ maybe "" show soa.retry ]
|
||||
, HH.td_ [ HH.text $ maybe "" show soa.expire ]
|
||||
, HH.td_ [ HH.text $ maybe "" show soa.minttl ]
|
||||
]
|
||||
]
|
||||
render_soa :: forall w. Maybe ResourceRecord -> Array (HH.HTML w Action)
|
||||
render_soa Nothing = [ HH.text "SOA not loaded, yet" ]
|
||||
render_soa (Just soa) = [ Bulma.zone_rr_title "Start Of Authority (SOA)", table_rr ]
|
||||
where
|
||||
table_rr = Bulma.table [] [ Bulma.soa_table_header, table_content ]
|
||||
table_content
|
||||
= HH.tbody_ $ [ HH.tr_ $ [ HH.td_ [ HH.text soa.name ]
|
||||
, HH.td_ [ HH.text $ show soa.ttl ]
|
||||
, HH.td_ [ HH.text soa.target ]
|
||||
, HH.td_ [ HH.text $ maybe "" id soa.mname ]
|
||||
, HH.td_ [ HH.text $ maybe "" id soa.rname ]
|
||||
, HH.td_ [ HH.text $ maybe "" show soa.serial ]
|
||||
, HH.td_ [ HH.text $ maybe "" show soa.refresh ]
|
||||
, HH.td_ [ HH.text $ maybe "" show soa.retry ]
|
||||
, HH.td_ [ HH.text $ maybe "" show soa.expire ]
|
||||
, HH.td_ [ HH.text $ maybe "" show soa.minttl ]
|
||||
]
|
||||
]
|
||||
|
||||
bg_color_ro = C.has_background_warning_light :: Array HH.ClassName
|
||||
|
||||
-- | Render all Resource Records.
|
||||
render_resources :: forall w
|
||||
-- . Hash.HashMap RRId (Array Validation.Error)
|
||||
. Array (ResourceRecord)
|
||||
-> HH.HTML w Action
|
||||
render_resources []
|
||||
= Bulma.box [ Bulma.zone_rr_title "Resource records"
|
||||
, Bulma.subtitle "No records for now"
|
||||
]
|
||||
render_resources :: forall w. Array ResourceRecord -> HH.HTML w Action
|
||||
render_resources [] = Bulma.box [Bulma.zone_rr_title "Resource records", Bulma.subtitle "No records for now"]
|
||||
render_resources records
|
||||
= HH.div_ $ [ render_soa $ A.head $ A.filter (\rr -> rr.rrtype == "SOA") records ]
|
||||
<> (if A.length all_basic_rr > 0 then [Bulma.box [basic_records_section]] else [])
|
||||
<> (if A.length all_mx_rr > 0 then [Bulma.box [mx_records_section ]] else [])
|
||||
<> (if A.length all_srv_rr > 0 then [Bulma.box [srv_records_section ]] else [])
|
||||
<> (if A.length all_spf_rr > 0 then [Bulma.box [spf_records_section ]] else [])
|
||||
<> (if A.length all_basic_ro_rr > 0
|
||||
then [Bulma.box_ C.has_background_warning_light [basic_readonly_records_section]] else [])
|
||||
= HH.div_ $
|
||||
[ Bulma.box $ render_soa $ A.head $ A.filter (\rr -> rr.rrtype == "SOA") records ]
|
||||
<> (rr_box [] Bulma.simple_table_header table_content_with_separations all_basic_rr)
|
||||
<> (rr_box [] Bulma.mx_table_header table_content all_mx_rr)
|
||||
<> (rr_box [] Bulma.srv_table_header table_content all_srv_rr)
|
||||
<> (rr_box [] Bulma.spf_table_header table_content all_spf_rr)
|
||||
<> (rr_box bg_color_ro Bulma.simple_table_header_ro table_content_with_separations all_basic_ro_rr)
|
||||
where
|
||||
all_basic_rr = A.filter (\rr -> A.elem rr.rrtype baseRecords && not rr.readonly) records
|
||||
all_basic_ro_rr = A.filter (\rr -> A.elem rr.rrtype baseRecords && rr.readonly) records
|
||||
@ -723,35 +711,15 @@ render_resources records
|
||||
all_srv_rr = A.filter (\rr -> rr.rrtype == "SRV") records
|
||||
all_spf_rr = A.filter (\rr -> rr.rrtype == "SPF") records
|
||||
|
||||
basic_records_section
|
||||
= if A.length all_basic_rr > 0
|
||||
then Bulma.table [] [ Bulma.simple_table_header, render_basic_records all_basic_rr]
|
||||
else Bulma.p "no basic records"
|
||||
|
||||
basic_readonly_records_section
|
||||
= if A.length all_basic_ro_rr > 0
|
||||
then Bulma.table [] [ Bulma.simple_table_header_ro, render_basic_records all_basic_ro_rr]
|
||||
else Bulma.p "no read only records?"
|
||||
|
||||
mx_records_section
|
||||
= if A.length all_mx_rr > 0
|
||||
then Bulma.table [] [ Bulma.mx_table_header, render_mx_records ]
|
||||
else Bulma.p "no mx records"
|
||||
|
||||
srv_records_section
|
||||
= if A.length all_srv_rr > 0
|
||||
then Bulma.table [] [ Bulma.srv_table_header, render_srv_records ]
|
||||
else Bulma.p "no srv records"
|
||||
|
||||
spf_records_section
|
||||
= if A.length all_spf_rr > 0
|
||||
then Bulma.table [] [ Bulma.spf_table_header, render_spf_records ]
|
||||
else Bulma.p "no spf records"
|
||||
|
||||
render_basic_records _rrs = table_content_with_separations _rrs
|
||||
render_mx_records = table_content all_mx_rr
|
||||
render_srv_records = table_content all_srv_rr
|
||||
render_spf_records = table_content all_spf_rr
|
||||
rr_box :: Array HH.ClassName
|
||||
-> HH.HTML w Action
|
||||
-> (Array ResourceRecord -> HH.HTML w Action)
|
||||
-> Array ResourceRecord
|
||||
-> Array (HH.HTML w Action)
|
||||
rr_box colors header dp rrs =
|
||||
if A.length rrs > 0
|
||||
then [Bulma.box_ colors [Bulma.table [] [header, dp rrs]]]
|
||||
else []
|
||||
|
||||
table_content_with_separations records_ = HH.tbody_ $
|
||||
A.groupAllBy (comparing (_.rrtype)) records_ -- [x x y y z] -> [NE[xx], NE[yy], NE[z]]
|
||||
@ -790,8 +758,7 @@ render_resources records
|
||||
[ Bulma.txt_name rr.rrtype
|
||||
, HH.td_ [ Bulma.p rr.name]
|
||||
, HH.td_ [ Bulma.p $ show rr.ttl ]
|
||||
, HH.td_ [ Bulma.p rr.target ]
|
||||
, HH.td_ [ Bulma.p $ maybe "spf1 (default)" id rr.v ]
|
||||
, HH.td_ [ Bulma.p $ maybe "(default)" id rr.v ]
|
||||
, HH.td_ [ Bulma.p $ maybe "" (A.fold <<< A.intersperse " " <<< map show_mechanism) rr.mechanisms ]
|
||||
, HH.td_ [ Bulma.p $ maybe "" (A.fold <<< A.intersperse " " <<< map show_modifier) rr.modifiers ]
|
||||
, HH.td_ [ Bulma.p $ maybe "" show_qualifier_char rr.q ]
|
||||
|
@ -128,7 +128,6 @@ spf_table_header
|
||||
= HH.thead_ [ HH.tr_ [ HH.th [ HP.style "width: 50px;" ] [ HH.text "Type" ]
|
||||
, HH.th_ [ HH.text "Name" ]
|
||||
, HH.th_ [ HH.text "TTL" ]
|
||||
, HH.th_ [ HH.text "Target" ]
|
||||
, HH.th_ [ HH.text "Version" ]
|
||||
, HH.th_ [ HH.text "Mechanisms" ]
|
||||
, HH.th_ [ HH.text "Modifiers" ]
|
||||
@ -463,3 +462,6 @@ selection action values selected = HH.div [HP.classes $ C.select <> C.is_normal]
|
||||
[ HH.select [ HE.onSelectedIndexChange action ]
|
||||
$ map (\n -> HH.option [HP.value n, HP.selected (n == selected)] [HH.text n]) values
|
||||
]
|
||||
|
||||
tag_light_info :: forall w i. String -> HH.HTML w i
|
||||
tag_light_info str = HH.span [HP.classes (C.is_info <> C.is_light)] [HH.text str]
|
||||
|
Loading…
Reference in New Issue
Block a user