From 58eee1251136ba2a040f28be0d2ee2c7c9f5308e Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sat, 17 Feb 2024 06:21:55 +0100 Subject: [PATCH] Code cleaning (buttons). --- .../AuthenticationDaemonAdminInterface.purs | 14 +--- src/App/DomainListInterface.purs | 78 +++++-------------- src/App/ZoneInterface.purs | 22 +++--- src/Bulma.purs | 46 +++-------- 4 files changed, 43 insertions(+), 117 deletions(-) diff --git a/src/App/AuthenticationDaemonAdminInterface.purs b/src/App/AuthenticationDaemonAdminInterface.purs index a37d658..86a2812 100644 --- a/src/App/AuthenticationDaemonAdminInterface.purs +++ b/src/App/AuthenticationDaemonAdminInterface.purs @@ -126,7 +126,7 @@ render { addUserForm, searchUserForm, page, wsUp } , 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_password "password" "User password" "password" (up ADDUSER_INP_pass) addUserForm.pass active - , generic_button AddUserAttempt wsUp + , Bulma.btn "Send" AddUserAttempt ] ] 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 "domain" "Domain owned" "blah.netlib.re." -- (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 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 = case _ of Initialize -> do diff --git a/src/App/DomainListInterface.purs b/src/App/DomainListInterface.purs index de7b3df..5a0aa55 100644 --- a/src/App/DomainListInterface.purs +++ b/src/App/DomainListInterface.purs @@ -23,11 +23,9 @@ import Halogen as H import Halogen.HTML as HH import Halogen.HTML.Events as HE import Halogen.HTML.Events as HHE -import Halogen.HTML.Properties as HP import Web.Event.Event as Event import Web.Event.Event (Event) import Bulma as Bulma -import CSSClasses as C import GenericParser (DomainError(..), parse) import GenericParser.DomainParserRFC1035 as RFC1035 @@ -162,67 +160,29 @@ render { accepted_domains, my_domains, newDomainForm, wsUp, active_modal } [ case wsUp of false -> Bulma.p "You are disconnected." true -> case active_modal of - Nothing -> Bulma.columns_ [ Bulma.column_ newdomain_form, Bulma.column_ list_of_own_domains ] - Just domain -> modal_domain_delete domain + Nothing -> Bulma.columns_ + [ 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 - - modal_domain_delete :: forall w. String -> HH.HTML w Action - modal_domain_delete 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 '" - <> domain - <> "'. Are you sure you want to do this? This is " - , HH.strong_ [ HH.text "irreversible" ] - , 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 - ] + modal_delete_button domain = Bulma.alert_btn "Delete the domain" (RemoveDomain domain) + modal_cancel_button = Bulma.cancel_button CancelModal + warning_message domain + = HH.p [] [ HH.text $ "You are about to delete your domain '" + <> domain + <> "'. Are you sure you want to do this? This is " + , HH.strong_ [ HH.text "irreversible" ] + , HH.text "." + ] domain_buttons domain - = [ HH.button - [ HP.type_ HP.ButtonSubmit - , 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 ] + = [ Bulma.alert_btn "delete" (DeleteDomainModal domain) + , Bulma.btn domain (EnterDomain domain) ] render_add_domain_form = HH.form diff --git a/src/App/ZoneInterface.purs b/src/App/ZoneInterface.purs index fffebca..0cf46dc 100644 --- a/src/App/ZoneInterface.purs +++ b/src/App/ZoneInterface.purs @@ -365,7 +365,7 @@ render state should_be_disabled = (if true then (HP.enabled true) else (HP.disabled true)) 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 _ -> 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 rr.target ] , 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" -> [ Bulma.txt_name rr.rrtype @@ -753,7 +753,7 @@ render_resources records , HH.td_ [ Bulma.p $ maybe "" show rr.priority ] , HH.td_ [ Bulma.p rr.target ] , 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 @@ -761,7 +761,7 @@ render_resources records , HH.td_ [ Bulma.p $ show rr.ttl ] , HH.td_ [ Bulma.p rr.target ] , 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 @@ -776,13 +776,13 @@ render_new_records _ , Bulma.hr -- use "level" to get horizontal buttons next to each other (probably vertical on mobile) , Bulma.level [ - Bulma.btn_add_new_rr (CreateNewRRModal A) "A" - , Bulma.btn_add_new_rr (CreateNewRRModal AAAA) "AAAA" - , Bulma.btn_add_new_rr (CreateNewRRModal TXT) "TXT" - , Bulma.btn_add_new_rr (CreateNewRRModal CNAME) "CNAME" - , Bulma.btn_add_new_rr (CreateNewRRModal NS) "NS" - , Bulma.btn_add_new_rr (CreateNewRRModal MX) "MX" - , Bulma.btn_add_new_rr (CreateNewRRModal SRV) "SRV" + Bulma.btn "A" (CreateNewRRModal A) + , Bulma.btn "AAAA" (CreateNewRRModal AAAA) + , Bulma.btn "TXT" (CreateNewRRModal TXT) + , Bulma.btn "CNAME" (CreateNewRRModal CNAME) + , Bulma.btn "NS" (CreateNewRRModal NS) + , Bulma.btn "MX" (CreateNewRRModal MX) + , Bulma.btn "SRV" (CreateNewRRModal SRV) ] [] ] diff --git a/src/Bulma.purs b/src/Bulma.purs index 2cb4d1d..5ab15a7 100644 --- a/src/Bulma.purs +++ b/src/Bulma.purs @@ -131,32 +131,16 @@ textarea action value validity ] btn_modify :: forall w i. i -> HH.HTML w i -btn_modify action - = HH.button - [ HE.onClick \_ -> action - , HP.classes $ btn_classes true - ] [ HH.text "modify" ] +btn_modify action = btn_ (C.is_small <> C.is_info) "modify" action btn_save :: forall w i. i -> HH.HTML w i -btn_save action - = HH.button - [ HE.onClick \_ -> action - , HP.classes $ btn_classes true - ] [ HH.text "save" ] +btn_save action = btn_ C.is_info "Save" action -btn_delete :: forall w i. (MouseEvent -> i) -> HH.HTML w i -btn_delete action - = HH.button - [ HE.onClick action - , HP.classes [ HH.ClassName "button is-small is-danger" ] - ] [ HH.text "remove" ] +btn_add :: forall w i. i -> HH.HTML w i +btn_add action = btn_ C.is_info "Add" action -btn_add :: forall w i. i -> Boolean -> HH.HTML w i -btn_add action validity - = HH.button - [ HE.onClick \_ -> action - , HP.classes $ btn_classes validity - ] [ HH.text "Add" ] +btn_delete :: forall w i. i -> HH.HTML w i +btn_delete action = btn_ (C.is_small <> C.is_danger) "remove" action -- | 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. @@ -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]) -btn_add_new_rr :: forall w i. i -> String -> HH.HTML w i -btn_add_new_rr action title +btn_ :: forall w action. Array HH.ClassName -> String -> action -> HH.HTML w action +btn_ classes title action = HH.button [ HE.onClick \_ -> action - , HP.classes $ C.button <> C.is_small <> C.is_info + , HP.classes $ C.button <> classes ] [ HH.text title ] btn :: forall w action. String -> action -> HH.HTML w action -btn title action - = HH.button - [ HE.onClick \_ -> action - , HP.classes $ btn_classes true - ] [ HH.text title ] +btn title action = btn_ [] title action alert_btn :: forall w action. String -> action -> HH.HTML w action -alert_btn title action - = HH.button - [ HE.onClick \_ -> action - , HP.classes $ btn_classes false - ] [ HH.text title ] +alert_btn title action = btn_ C.is_danger title action render_input :: forall w i. Boolean -> String -> String -> (String -> i) -> String -> (HP.IProp DHI.HTMLinput i) -> HH.HTML w i