Code cleaning (buttons).

beta
Philippe Pittoli 2024-02-17 06:21:55 +01:00
parent c017dc1b05
commit 58eee12511
4 changed files with 43 additions and 117 deletions

View File

@ -126,7 +126,7 @@ render { addUserForm, searchUserForm, page, wsUp }
, Bulma.btn (show addUserForm.admin) (HandleAddUserInput ADDUSER_toggle_admin) , Bulma.btn (show addUserForm.admin) (HandleAddUserInput ADDUSER_toggle_admin)
, Bulma.box_input "email" "User email" "email" (up ADDUSER_INP_email) addUserForm.email active , Bulma.box_input "email" "User email" "email" (up ADDUSER_INP_email) addUserForm.email active
, Bulma.box_password "password" "User password" "password" (up ADDUSER_INP_pass) addUserForm.pass active , Bulma.box_password "password" "User password" "password" (up ADDUSER_INP_pass) addUserForm.pass active
, generic_button AddUserAttempt wsUp , Bulma.btn "Send" AddUserAttempt
] ]
] ]
up x = HandleAddUserInput <<< x up x = HandleAddUserInput <<< x
@ -139,7 +139,7 @@ render { addUserForm, searchUserForm, page, wsUp }
, Bulma.box_input "email" "User email" "email" (up SEARCHUSER_INP_email) searchUserForm.email active , Bulma.box_input "email" "User email" "email" (up SEARCHUSER_INP_email) searchUserForm.email active
--, Bulma.box_input "domain" "Domain owned" "blah.netlib.re." --, Bulma.box_input "domain" "Domain owned" "blah.netlib.re."
-- (up SEARCHUSER_INP_domain) searchUserForm.email active -- (up SEARCHUSER_INP_domain) searchUserForm.email active
, generic_button SearchUserAttempt wsUp , Bulma.btn "Send" SearchUserAttempt
] ]
] ]
@ -147,16 +147,6 @@ render { addUserForm, searchUserForm, page, wsUp }
routing_add_button = Bulma.btn "Add" $ Routing Add routing_add_button = Bulma.btn "Add" $ Routing Add
cancel_button = Bulma.cancel_button CancelModal cancel_button = Bulma.cancel_button CancelModal
generic_button :: forall w. Action -> Boolean -> HH.HTML w Action
generic_button action active =
HH.button
[ HP.style "padding: 0.5rem 1.25rem;"
, HP.type_ HP.ButtonSubmit
, HE.onClick \_ -> action
, (if active then (HP.enabled true) else (HP.disabled true))
]
[ HH.text "Send Message to Server" ]
handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit
handleAction = case _ of handleAction = case _ of
Initialize -> do Initialize -> do

View File

@ -23,11 +23,9 @@ import Halogen as H
import Halogen.HTML as HH import Halogen.HTML as HH
import Halogen.HTML.Events as HE import Halogen.HTML.Events as HE
import Halogen.HTML.Events as HHE import Halogen.HTML.Events as HHE
import Halogen.HTML.Properties as HP
import Web.Event.Event as Event import Web.Event.Event as Event
import Web.Event.Event (Event) import Web.Event.Event (Event)
import Bulma as Bulma import Bulma as Bulma
import CSSClasses as C
import GenericParser (DomainError(..), parse) import GenericParser (DomainError(..), parse)
import GenericParser.DomainParserRFC1035 as RFC1035 import GenericParser.DomainParserRFC1035 as RFC1035
@ -162,37 +160,19 @@ render { accepted_domains, my_domains, newDomainForm, wsUp, active_modal }
[ case wsUp of [ case wsUp of
false -> Bulma.p "You are disconnected." false -> Bulma.p "You are disconnected."
true -> case active_modal of true -> case active_modal of
Nothing -> Bulma.columns_ [ Bulma.column_ newdomain_form, Bulma.column_ list_of_own_domains ] Nothing -> Bulma.columns_
Just domain -> modal_domain_delete domain [ Bulma.column_ [ Bulma.h3 "Add a domain!", render_add_domain_form]
, Bulma.column_ [ Bulma.h3 "My domains"
, HH.ul_ $ map (\domain -> HH.li_ (domain_buttons domain)) my_domains
]
]
Just domain -> Bulma.modal "Deleting a domain"
[warning_message domain] [modal_delete_button domain, modal_cancel_button]
] ]
where where
modal_delete_button domain = Bulma.alert_btn "Delete the domain" (RemoveDomain domain)
modal_domain_delete :: forall w. String -> HH.HTML w Action modal_cancel_button = Bulma.cancel_button CancelModal
modal_domain_delete domain = warning_message domain
modal
[ modal_background
, modal_card [modal_header, modal_body]
, modal_foot [modal_delete_button, modal_cancel_button]
]
where
modal = HH.div [HP.classes (C.modal <> C.is_active)]
modal_background = HH.div [HP.classes C.modal_background] []
modal_card = HH.div [HP.classes C.modal_card]
modal_header = HH.header [HP.classes C.modal_card_head]
[ HH.p [HP.classes C.modal_card_title] [HH.text "Deleting a domain"]
--, HH.button [HP.classes C.delete, ARIA.label "close"] []
]
modal_body = HH.section [HP.classes C.modal_card_body] [ warning_message ]
modal_foot = HH.div [HP.classes C.modal_card_foot]
modal_delete_button
= HH.button [ HP.classes (C.button <> C.is_success)
, HE.onClick \_ -> RemoveDomain domain
] [HH.text "Delete the domain."]
modal_cancel_button
= HH.button [ HP.classes C.button
, HE.onClick \_ -> CancelModal
] [HH.text "Cancel"]
warning_message
= HH.p [] [ HH.text $ "You are about to delete your domain '" = HH.p [] [ HH.text $ "You are about to delete your domain '"
<> domain <> domain
<> "'. Are you sure you want to do this? This is " <> "'. Are you sure you want to do this? This is "
@ -200,29 +180,9 @@ render { accepted_domains, my_domains, newDomainForm, wsUp, active_modal }
, HH.text "." , HH.text "."
] ]
newdomain_form
= [ Bulma.h3 "Add a domain!"
, render_add_domain_form
]
list_of_own_domains
= [ Bulma.h3 "My domains"
, HH.ul_ $ map (\domain -> HH.li_ (domain_buttons domain)) my_domains
]
domain_buttons domain domain_buttons domain
= [ HH.button = [ Bulma.alert_btn "delete" (DeleteDomainModal domain)
[ HP.type_ HP.ButtonSubmit , Bulma.btn domain (EnterDomain domain)
, HE.onClick \_ -> DeleteDomainModal domain
, HP.classes $ C.button <> C.is_danger
]
[ HH.text "delete" ]
, HH.button
[ HP.type_ HP.ButtonSubmit
, HE.onClick \_ -> EnterDomain domain
, HP.classes C.button
]
[ HH.text domain ]
] ]
render_add_domain_form = HH.form render_add_domain_form = HH.form

View File

@ -365,7 +365,7 @@ render state
should_be_disabled = (if true then (HP.enabled true) else (HP.disabled true)) should_be_disabled = (if true then (HP.enabled true) else (HP.disabled true))
foot_content x = [ case state.rr_modal of foot_content x = [ case state.rr_modal of
NewRRModal _ -> Bulma.btn_add (ValidateRR x) true -- state._currentRR.valid NewRRModal _ -> Bulma.btn_add (ValidateRR x)
UpdateRRModal -> Bulma.btn_save ValidateLocal UpdateRRModal -> Bulma.btn_save ValidateLocal
_ -> Bulma.p "state.rr_modal should either be NewRRModal or UpdateRRModal." _ -> Bulma.p "state.rr_modal should either be NewRRModal or UpdateRRModal."
] ]
@ -744,7 +744,7 @@ render_resources records
, HH.td_ [ Bulma.p $ maybe "" show rr.port ] , HH.td_ [ Bulma.p $ maybe "" show rr.port ]
, HH.td_ [ Bulma.p rr.target ] , HH.td_ [ Bulma.p rr.target ]
, HH.td_ [ Bulma.btn_modify (CreateUpdateRRModal rr.rrid) ] , HH.td_ [ Bulma.btn_modify (CreateUpdateRRModal rr.rrid) ]
, HH.td_ [ Bulma.btn_delete (\_ -> DeleteRRModal rr.rrid) ] , HH.td_ [ Bulma.btn_delete (DeleteRRModal rr.rrid) ]
] ]
"MX" -> "MX" ->
[ Bulma.txt_name rr.rrtype [ Bulma.txt_name rr.rrtype
@ -753,7 +753,7 @@ render_resources records
, HH.td_ [ Bulma.p $ maybe "" show rr.priority ] , HH.td_ [ Bulma.p $ maybe "" show rr.priority ]
, HH.td_ [ Bulma.p rr.target ] , HH.td_ [ Bulma.p rr.target ]
, HH.td_ [ Bulma.btn_modify (CreateUpdateRRModal rr.rrid) ] , HH.td_ [ Bulma.btn_modify (CreateUpdateRRModal rr.rrid) ]
, HH.td_ [ Bulma.btn_delete (\_ -> DeleteRRModal rr.rrid) ] , HH.td_ [ Bulma.btn_delete (DeleteRRModal rr.rrid) ]
] ]
_ -> _ ->
[ Bulma.txt_name rr.rrtype [ Bulma.txt_name rr.rrtype
@ -761,7 +761,7 @@ render_resources records
, HH.td_ [ Bulma.p $ show rr.ttl ] , HH.td_ [ Bulma.p $ show rr.ttl ]
, HH.td_ [ Bulma.p rr.target ] , HH.td_ [ Bulma.p rr.target ]
, HH.td_ [ Bulma.btn_modify (CreateUpdateRRModal rr.rrid) ] , HH.td_ [ Bulma.btn_modify (CreateUpdateRRModal rr.rrid) ]
, HH.td_ [ Bulma.btn_delete (\_ -> DeleteRRModal rr.rrid) ] , HH.td_ [ Bulma.btn_delete (DeleteRRModal rr.rrid) ]
] ]
baseRecords :: Array String baseRecords :: Array String
@ -776,13 +776,13 @@ render_new_records _
, Bulma.hr , Bulma.hr
-- use "level" to get horizontal buttons next to each other (probably vertical on mobile) -- use "level" to get horizontal buttons next to each other (probably vertical on mobile)
, Bulma.level [ , Bulma.level [
Bulma.btn_add_new_rr (CreateNewRRModal A) "A" Bulma.btn "A" (CreateNewRRModal A)
, Bulma.btn_add_new_rr (CreateNewRRModal AAAA) "AAAA" , Bulma.btn "AAAA" (CreateNewRRModal AAAA)
, Bulma.btn_add_new_rr (CreateNewRRModal TXT) "TXT" , Bulma.btn "TXT" (CreateNewRRModal TXT)
, Bulma.btn_add_new_rr (CreateNewRRModal CNAME) "CNAME" , Bulma.btn "CNAME" (CreateNewRRModal CNAME)
, Bulma.btn_add_new_rr (CreateNewRRModal NS) "NS" , Bulma.btn "NS" (CreateNewRRModal NS)
, Bulma.btn_add_new_rr (CreateNewRRModal MX) "MX" , Bulma.btn "MX" (CreateNewRRModal MX)
, Bulma.btn_add_new_rr (CreateNewRRModal SRV) "SRV" , Bulma.btn "SRV" (CreateNewRRModal SRV)
] [] ] []
] ]

View File

@ -131,32 +131,16 @@ textarea action value validity
] ]
btn_modify :: forall w i. i -> HH.HTML w i btn_modify :: forall w i. i -> HH.HTML w i
btn_modify action btn_modify action = btn_ (C.is_small <> C.is_info) "modify" action
= HH.button
[ HE.onClick \_ -> action
, HP.classes $ btn_classes true
] [ HH.text "modify" ]
btn_save :: forall w i. i -> HH.HTML w i btn_save :: forall w i. i -> HH.HTML w i
btn_save action btn_save action = btn_ C.is_info "Save" action
= HH.button
[ HE.onClick \_ -> action
, HP.classes $ btn_classes true
] [ HH.text "save" ]
btn_delete :: forall w i. (MouseEvent -> i) -> HH.HTML w i btn_add :: forall w i. i -> HH.HTML w i
btn_delete action btn_add action = btn_ C.is_info "Add" action
= HH.button
[ HE.onClick action
, HP.classes [ HH.ClassName "button is-small is-danger" ]
] [ HH.text "remove" ]
btn_add :: forall w i. i -> Boolean -> HH.HTML w i btn_delete :: forall w i. i -> HH.HTML w i
btn_add action validity btn_delete action = btn_ (C.is_small <> C.is_danger) "remove" action
= HH.button
[ HE.onClick \_ -> action
, HP.classes $ btn_classes validity
] [ HH.text "Add" ]
-- | Create a `level`, different components that should appear on the same horizontal line. -- | Create a `level`, different components that should appear on the same horizontal line.
-- | First argument, elements that should appear on the left, second on the right. -- | First argument, elements that should appear on the left, second on the right.
@ -167,26 +151,18 @@ level left right = HH.nav [ HP.classes C.level ]
] ]
where itemize = map (\v -> HH.div [ HP.classes C.level_item ] [v]) where itemize = map (\v -> HH.div [ HP.classes C.level_item ] [v])
btn_add_new_rr :: forall w i. i -> String -> HH.HTML w i btn_ :: forall w action. Array HH.ClassName -> String -> action -> HH.HTML w action
btn_add_new_rr action title btn_ classes title action
= HH.button = HH.button
[ HE.onClick \_ -> action [ HE.onClick \_ -> action
, HP.classes $ C.button <> C.is_small <> C.is_info , HP.classes $ C.button <> classes
] [ HH.text title ] ] [ HH.text title ]
btn :: forall w action. String -> action -> HH.HTML w action btn :: forall w action. String -> action -> HH.HTML w action
btn title action btn title action = btn_ [] title action
= HH.button
[ HE.onClick \_ -> action
, HP.classes $ btn_classes true
] [ HH.text title ]
alert_btn :: forall w action. String -> action -> HH.HTML w action alert_btn :: forall w action. String -> action -> HH.HTML w action
alert_btn title action alert_btn title action = btn_ C.is_danger title action
= HH.button
[ HE.onClick \_ -> action
, HP.classes $ btn_classes false
] [ HH.text title ]
render_input :: forall w i. render_input :: forall w i.
Boolean -> String -> String -> (String -> i) -> String -> (HP.IProp DHI.HTMLinput i) -> HH.HTML w i Boolean -> String -> String -> (String -> i) -> String -> (HP.IProp DHI.HTMLinput i) -> HH.HTML w i