From 19caf9034153bc0e7abde6ddc7690ace8621221c Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Wed, 13 Mar 2024 15:24:20 +0100 Subject: [PATCH] Code refactoring. Serious code refactoring. --- src/App/Container.purs | 12 ++++++------ src/App/Log.purs | 2 +- .../AuthenticationDaemon.purs | 10 +++++----- .../{Messages => Message}/DNSManagerDaemon.purs | 12 ++++++------ src/App/{ => Message}/IPC.purs | 4 ++-- src/App/Page/Administration.purs | 10 +++++----- src/App/Page/Authentication.purs | 4 ++-- src/App/Page/DomainList.purs | 4 ++-- src/App/Page/MailValidation.purs | 4 ++-- src/App/Page/Navigation.purs | 16 ++++++++-------- src/App/Page/Registration.purs | 6 +++--- src/App/Page/Setup.purs | 4 ++-- src/App/Page/Zone.purs | 14 +++++++------- src/App/{ => Type}/AcceptedRRTypes.purs | 2 +- src/App/{ => Type}/DKIM.purs | 2 +- src/App/{ => Type}/DNSZone.purs | 4 ++-- src/App/{ => Type}/Email.purs | 2 +- src/App/{ => Type}/LogMessage.purs | 2 +- src/App/{ => Type}/MaintenanceSubject.purs | 2 +- src/App/{ => Type}/Pages.purs | 2 +- src/App/{ => Type}/PermissionLevel.purs | 2 +- src/App/{ => Type}/ResourceRecord.purs | 4 ++-- src/App/{ => Type}/UserPublic.purs | 2 +- src/App/Validation/DNS.purs | 8 ++++---- src/App/WS.purs | 2 +- 25 files changed, 68 insertions(+), 68 deletions(-) rename src/App/{Messages => Message}/AuthenticationDaemon.purs (99%) rename src/App/{Messages => Message}/DNSManagerDaemon.purs (98%) rename src/App/{ => Message}/IPC.purs (96%) rename src/App/{ => Type}/AcceptedRRTypes.purs (92%) rename src/App/{ => Type}/DKIM.purs (99%) rename src/App/{ => Type}/DNSZone.purs (88%) rename src/App/{ => Type}/Email.purs (95%) rename src/App/{ => Type}/LogMessage.purs (75%) rename src/App/{ => Type}/MaintenanceSubject.purs (92%) rename src/App/{ => Type}/Pages.purs (95%) rename src/App/{ => Type}/PermissionLevel.purs (94%) rename src/App/{ => Type}/ResourceRecord.purs (99%) rename src/App/{ => Type}/UserPublic.purs (95%) diff --git a/src/App/Container.purs b/src/App/Container.purs index 61938ea..1ebbea8 100644 --- a/src/App/Container.purs +++ b/src/App/Container.purs @@ -15,7 +15,7 @@ -- | In case the old page is `Zone`, send a request to `dnsmanagerd` to get the zone content again. -- | -- | Once a message is received, it is transfered to the module of the current page; --- | except for the `App.Messages.DNSManagerDaemon.AnswerMessage` `Logged` which is an hint when the +-- | except for the `App.Message.DNSManagerDaemon.AnswerMessage` `Logged` which is an hint when the -- | page has been reloaded, thus having a special treatment. -- | -- | TODO: @@ -60,8 +60,8 @@ import Type.Proxy (Proxy(..)) import Effect.Aff.Class (class MonadAff) import Data.ArrayBuffer.Types (ArrayBuffer) -import App.Messages.DNSManagerDaemon as DNSManager -import App.Messages.AuthenticationDaemon as AuthD +import App.Message.DNSManagerDaemon as DNSManager +import App.Message.AuthenticationDaemon as AuthD import App.Log as AppLog import App.WS as WS @@ -80,11 +80,11 @@ import Web.HTML (window) as HTML import Web.HTML.Window (sessionStorage) as Window import Web.Storage.Storage as Storage -import App.Email as Email +import App.Type.Email as Email -import App.LogMessage (LogMessage(..)) +import App.Type.LogMessage (LogMessage(..)) -import App.Pages +import App.Type.Pages import CSSClasses as C type Token = String diff --git a/src/App/Log.purs b/src/App/Log.purs index 2a8f18c..df5baf5 100644 --- a/src/App/Log.purs +++ b/src/App/Log.purs @@ -11,7 +11,7 @@ import Effect.Aff.Class (class MonadAff) import Halogen as H import Halogen.HTML as HH -import App.LogMessage +import App.Type.LogMessage data Output = Void type Slot = H.Slot Query Output diff --git a/src/App/Messages/AuthenticationDaemon.purs b/src/App/Message/AuthenticationDaemon.purs similarity index 99% rename from src/App/Messages/AuthenticationDaemon.purs rename to src/App/Message/AuthenticationDaemon.purs index 999a734..4aaaf58 100644 --- a/src/App/Messages/AuthenticationDaemon.purs +++ b/src/App/Message/AuthenticationDaemon.purs @@ -1,4 +1,4 @@ -module App.Messages.AuthenticationDaemon where +module App.Message.AuthenticationDaemon where import Prelude (bind, pure, show, ($)) @@ -14,15 +14,15 @@ import Data.UInt (fromInt, toInt, UInt) import Data.Tuple (Tuple(..)) import Data.ArrayBuffer.Types (ArrayBuffer) -import App.Email as Email -import App.UserPublic as UserPublic -import App.PermissionLevel as PermissionLevel +import App.Type.Email as Email +import App.Type.UserPublic as UserPublic +import App.Type.PermissionLevel as PermissionLevel import Effect.Class (liftEffect) import Data.Argonaut.Parser as JSONParser import Data.Bifunctor (lmap) -import App.IPC as IPC +import App.Message.IPC as IPC {- TODO: For a few messages, user can be designated by a string (login) or a number (its UID). diff --git a/src/App/Messages/DNSManagerDaemon.purs b/src/App/Message/DNSManagerDaemon.purs similarity index 98% rename from src/App/Messages/DNSManagerDaemon.purs rename to src/App/Message/DNSManagerDaemon.purs index 1d6545f..1ed13cd 100644 --- a/src/App/Messages/DNSManagerDaemon.purs +++ b/src/App/Message/DNSManagerDaemon.purs @@ -1,4 +1,4 @@ -module App.Messages.DNSManagerDaemon where +module App.Message.DNSManagerDaemon where import Prelude (bind, pure, show, ($)) @@ -14,16 +14,16 @@ import Data.UInt (fromInt, toInt, UInt) import Data.Tuple (Tuple(..)) import Data.ArrayBuffer.Types (ArrayBuffer) --- import App.PermissionLevel as PermissionLevel -import App.MaintenanceSubject as MaintenanceSubject +-- import App.Type.PermissionLevel as PermissionLevel +import App.Type.MaintenanceSubject as MaintenanceSubject import Effect.Class (liftEffect) import Data.Argonaut.Parser as JSONParser import Data.Bifunctor (lmap) -import App.IPC as IPC -import App.DNSZone as DNSZone -import App.ResourceRecord as ResourceRecord +import App.Message.IPC as IPC +import App.Type.DNSZone as DNSZone +import App.Type.ResourceRecord as ResourceRecord {- UserID should be in a separate module with a dedicated codec. -} type UserID = Int -- UserID is either a login or an uid number diff --git a/src/App/IPC.purs b/src/App/Message/IPC.purs similarity index 96% rename from src/App/IPC.purs rename to src/App/Message/IPC.purs index f681f86..4baecc9 100644 --- a/src/App/IPC.purs +++ b/src/App/Message/IPC.purs @@ -1,4 +1,4 @@ -module App.IPC (toIPC, fromIPC, toTypedIPC, fromTypedIPC) where +module App.Message.IPC (toIPC, fromIPC, toTypedIPC, fromTypedIPC) where {- This file contains raw serialization and deserialization of IPC messages. @@ -10,7 +10,7 @@ module App.IPC (toIPC, fromIPC, toTypedIPC, fromTypedIPC) where The message type informs what format should be expected. For example: an authentication attempt, a page request, etc. - Actual message formats can be found in the App.Messages folder. + Actual message formats can be found in the App.Message folder. -} import Prelude (bind, (<$>), discard, ($), (>>>), (+), (-)) diff --git a/src/App/Page/Administration.purs b/src/App/Page/Administration.purs index 5fbdd97..622581d 100644 --- a/src/App/Page/Administration.purs +++ b/src/App/Page/Administration.purs @@ -30,15 +30,15 @@ import Web.HTML (window) as HTML import Web.HTML.Window (sessionStorage) as Window import Web.Storage.Storage as Storage -import App.UserPublic (UserPublic) +import App.Type.UserPublic (UserPublic) import Data.ArrayBuffer.Types (ArrayBuffer) -import App.LogMessage +import App.Type.LogMessage -- import App.IPC as IPC -import App.Email as Email +import App.Type.Email as Email --- import App.Messages.DNSManagerDaemon as DNSManager -import App.Messages.AuthenticationDaemon as AuthD +-- import App.Message.DNSManagerDaemon as DNSManager +import App.Message.AuthenticationDaemon as AuthD data Output = MessageToSend ArrayBuffer diff --git a/src/App/Page/Authentication.purs b/src/App/Page/Authentication.purs index 3073261..b706104 100644 --- a/src/App/Page/Authentication.purs +++ b/src/App/Page/Authentication.purs @@ -19,8 +19,8 @@ import Web.Event.Event (Event) import Bulma as Bulma -import App.LogMessage -import App.Messages.AuthenticationDaemon as AuthD +import App.Type.LogMessage +import App.Message.AuthenticationDaemon as AuthD import App.Validation.Login as L import App.Validation.Email as E diff --git a/src/App/Page/DomainList.purs b/src/App/Page/DomainList.purs index aa25f37..4c588ef 100644 --- a/src/App/Page/DomainList.purs +++ b/src/App/Page/DomainList.purs @@ -33,8 +33,8 @@ import App.DisplayErrors (error_to_paragraph_label) import App.Validation.Label as Validation import CSSClasses as C -import App.LogMessage -import App.Messages.DNSManagerDaemon as DNSManager +import App.Type.LogMessage +import App.Message.DNSManagerDaemon as DNSManager -- | `App.DomainListInterface` can send messages through websocket interface -- | connected to dnsmanagerd. See `App.WS`. diff --git a/src/App/Page/MailValidation.purs b/src/App/Page/MailValidation.purs index 3abaa55..1346aee 100644 --- a/src/App/Page/MailValidation.purs +++ b/src/App/Page/MailValidation.purs @@ -19,8 +19,8 @@ import Web.Event.Event (Event) import Bulma as Bulma -import App.LogMessage -import App.Messages.AuthenticationDaemon as AuthD +import App.Type.LogMessage +import App.Message.AuthenticationDaemon as AuthD import App.Validation.Login as L import App.Validation.Token as T diff --git a/src/App/Page/Navigation.purs b/src/App/Page/Navigation.purs index 51e034e..20da4aa 100644 --- a/src/App/Page/Navigation.purs +++ b/src/App/Page/Navigation.purs @@ -20,8 +20,8 @@ import Halogen.HTML.Properties.ARIA as ARIA import CSSClasses as C import Bulma as Bulma -import App.Pages (Page(..)) -import App.LogMessage (LogMessage) +import App.Type.Pages (Page(..)) +import App.Type.LogMessage (LogMessage) data Output = Log LogMessage @@ -163,8 +163,8 @@ render { logged, active, admin } = dropdown_element link str = HH.a [HP.classes C.navbar_item, HP.href link] [HH.text str] dropdown_separator = HH.hr [HP.classes C.navbar_divider] - nav_button_strong str action = btn C.is_primary action (HH.strong [] [ HH.text str ]) - nav_button classes str action = btn classes action (HH.text str) + --nav_button_strong str action = btn C.is_primary action (HH.strong [] [ HH.text str ]) + --nav_button classes str action = btn classes action (HH.text str) nav_link_strong str action = HH.a [ HP.classes (C.navbar_item <> C.is_danger <> C.has_background_success_dark) @@ -189,7 +189,7 @@ render { logged, active, admin } = "(temporary repo) dnsmanager website" ] - btn c action str - = HH.a [ HP.classes (C.navbar_item <> C.button <> c) - , HE.onClick (\_ -> action) - ] [ str ] + --btn c action str + -- = HH.a [ HP.classes (C.navbar_item <> C.button <> c) + -- , HE.onClick (\_ -> action) + -- ] [ str ] diff --git a/src/App/Page/Registration.purs b/src/App/Page/Registration.purs index 4495c8b..3923eb7 100644 --- a/src/App/Page/Registration.purs +++ b/src/App/Page/Registration.purs @@ -18,9 +18,9 @@ import Web.Event.Event (Event) import Bulma as Bulma -import App.Email as Email -import App.LogMessage -import App.Messages.AuthenticationDaemon as AuthD +import App.Type.Email as Email +import App.Type.LogMessage +import App.Message.AuthenticationDaemon as AuthD import App.Validation.Login as L import App.Validation.Email as E diff --git a/src/App/Page/Setup.purs b/src/App/Page/Setup.purs index 04b4631..e575d65 100644 --- a/src/App/Page/Setup.purs +++ b/src/App/Page/Setup.purs @@ -15,8 +15,8 @@ import Web.Event.Event (Event) import Bulma as Bulma -import App.LogMessage -import App.Messages.AuthenticationDaemon as AuthD +import App.Type.LogMessage +import App.Message.AuthenticationDaemon as AuthD data Output = Log LogMessage diff --git a/src/App/Page/Zone.purs b/src/App/Page/Zone.purs index 9112c37..84cb3b0 100644 --- a/src/App/Page/Zone.purs +++ b/src/App/Page/Zone.purs @@ -43,20 +43,20 @@ import CSSClasses as C import App.Text.Explanations as Explanations -import App.AcceptedRRTypes (AcceptedRRTypes(..)) -import App.ResourceRecord (ResourceRecord, emptyRR +import App.Type.AcceptedRRTypes (AcceptedRRTypes(..)) +import App.Type.ResourceRecord (ResourceRecord, emptyRR , show_qualifier, show_qualifier_char , show_mechanism_type, show_mechanism, to_mechanism , show_modifier_type, show_modifier, to_modifier , all_qualifiers , mechanism_types, qualifier_types, modifier_types) -import App.ResourceRecord (Mechanism, Modifier, Qualifier(..)) as RR -import App.DKIM as DKIM +import App.Type.ResourceRecord (Mechanism, Modifier, Qualifier(..)) as RR +import App.Type.DKIM as DKIM import App.DisplayErrors (error_to_paragraph) -import App.LogMessage (LogMessage(..)) -import App.Messages.DNSManagerDaemon as DNSManager +import App.Type.LogMessage (LogMessage(..)) +import App.Message.DNSManagerDaemon as DNSManager import App.Validation.DNS as Validation type RRId = Int @@ -827,7 +827,7 @@ render_resources records then [ Bulma.box_ (C.no_padding_left <> C.no_padding_top <> colors) [title, Bulma.table_ (C.margin_left 3) [] [header, dp rrs]] ] else [] - title_col_props = C.is 1 + --title_col_props = C.is 1 table_content_w_seps records_ = HH.tbody_ $ A.groupAllBy (comparing (_.rrtype)) records_ -- [x x y y z] -> [NE[xx], NE[yy], NE[z]] diff --git a/src/App/AcceptedRRTypes.purs b/src/App/Type/AcceptedRRTypes.purs similarity index 92% rename from src/App/AcceptedRRTypes.purs rename to src/App/Type/AcceptedRRTypes.purs index 3eaeca2..afcddc6 100644 --- a/src/App/AcceptedRRTypes.purs +++ b/src/App/Type/AcceptedRRTypes.purs @@ -1,7 +1,7 @@ -- | The application accepts to add a few new entry types in a DNS zone. -- | Each resource record has a specific form, with dedicated inputs and -- | dedicated validation. -module App.AcceptedRRTypes where +module App.Type.AcceptedRRTypes where import Prelude import Data.Generic.Rep (class Generic) diff --git a/src/App/DKIM.purs b/src/App/Type/DKIM.purs similarity index 99% rename from src/App/DKIM.purs rename to src/App/Type/DKIM.purs index ef80f2b..b1580d1 100644 --- a/src/App/DKIM.purs +++ b/src/App/Type/DKIM.purs @@ -1,4 +1,4 @@ -module App.DKIM where +module App.Type.DKIM where import Data.Maybe (Maybe(..)) diff --git a/src/App/DNSZone.purs b/src/App/Type/DNSZone.purs similarity index 88% rename from src/App/DNSZone.purs rename to src/App/Type/DNSZone.purs index 0eed95a..5e2e691 100644 --- a/src/App/DNSZone.purs +++ b/src/App/Type/DNSZone.purs @@ -1,9 +1,9 @@ -module App.DNSZone where +module App.Type.DNSZone where import Data.Codec.Argonaut (JsonCodec) import Data.Codec.Argonaut as CA import Data.Codec.Argonaut.Record as CAR -import App.ResourceRecord as RR +import App.Type.ResourceRecord as RR type DNSZone = { domain :: String diff --git a/src/App/Email.purs b/src/App/Type/Email.purs similarity index 95% rename from src/App/Email.purs rename to src/App/Type/Email.purs index d4eddf1..e56f97c 100644 --- a/src/App/Email.purs +++ b/src/App/Type/Email.purs @@ -1,6 +1,6 @@ -- | TODO: Email module should include at least some sort of smart -- | constructors, rejecting invalid email addresses. -module App.Email where +module App.Type.Email where import Prelude diff --git a/src/App/LogMessage.purs b/src/App/Type/LogMessage.purs similarity index 75% rename from src/App/LogMessage.purs rename to src/App/Type/LogMessage.purs index 0fce9e3..b43a930 100644 --- a/src/App/LogMessage.purs +++ b/src/App/Type/LogMessage.purs @@ -1,4 +1,4 @@ -module App.LogMessage where +module App.Type.LogMessage where data LogMessage = SystemLog String diff --git a/src/App/MaintenanceSubject.purs b/src/App/Type/MaintenanceSubject.purs similarity index 92% rename from src/App/MaintenanceSubject.purs rename to src/App/Type/MaintenanceSubject.purs index 0fc7c77..5a04279 100644 --- a/src/App/MaintenanceSubject.purs +++ b/src/App/Type/MaintenanceSubject.purs @@ -1,4 +1,4 @@ -module App.MaintenanceSubject where +module App.Type.MaintenanceSubject where import Data.Codec.Argonaut as CA import Data.Maybe (Maybe(..)) diff --git a/src/App/Pages.purs b/src/App/Type/Pages.purs similarity index 95% rename from src/App/Pages.purs rename to src/App/Type/Pages.purs index fbd6fd3..7d85a29 100644 --- a/src/App/Pages.purs +++ b/src/App/Type/Pages.purs @@ -1,4 +1,4 @@ -module App.Pages where +module App.Type.Pages where -- | This list will grow in a near future. -- | -- | TODO: diff --git a/src/App/PermissionLevel.purs b/src/App/Type/PermissionLevel.purs similarity index 94% rename from src/App/PermissionLevel.purs rename to src/App/Type/PermissionLevel.purs index 2344861..e266067 100644 --- a/src/App/PermissionLevel.purs +++ b/src/App/Type/PermissionLevel.purs @@ -1,4 +1,4 @@ -module App.PermissionLevel where +module App.Type.PermissionLevel where import Data.Codec.Argonaut as CA import Data.Maybe (Maybe(..)) diff --git a/src/App/ResourceRecord.purs b/src/App/Type/ResourceRecord.purs similarity index 99% rename from src/App/ResourceRecord.purs rename to src/App/Type/ResourceRecord.purs index d537545..e5a7953 100644 --- a/src/App/ResourceRecord.purs +++ b/src/App/Type/ResourceRecord.purs @@ -1,4 +1,4 @@ -module App.ResourceRecord where +module App.Type.ResourceRecord where import Prelude ((<>), map, bind, pure) @@ -8,7 +8,7 @@ import Data.Codec.Argonaut (JsonCodec) import Data.Codec.Argonaut as CA import Data.Codec.Argonaut.Record as CAR -import App.DKIM as DKIM +import App.Type.DKIM as DKIM type ResourceRecord = { rrtype :: String diff --git a/src/App/UserPublic.purs b/src/App/Type/UserPublic.purs similarity index 95% rename from src/App/UserPublic.purs rename to src/App/Type/UserPublic.purs index 8de85a0..20707e8 100644 --- a/src/App/UserPublic.purs +++ b/src/App/Type/UserPublic.purs @@ -1,4 +1,4 @@ -module App.UserPublic where +module App.Type.UserPublic where import Data.Maybe (Maybe) diff --git a/src/App/Validation/DNS.purs b/src/App/Validation/DNS.purs index e3e0cfd..1af4ec5 100644 --- a/src/App/Validation/DNS.purs +++ b/src/App/Validation/DNS.purs @@ -1,6 +1,6 @@ module App.Validation.DNS where -import Prelude (apply, between, bind, map, pure, ($), (-), (<), (<>), (<$>)) +import Prelude (apply, between, bind, map, pure, ($), (-), (<), (<>)) import Control.Alt ((<|>)) import Data.Array as A @@ -10,8 +10,8 @@ import Data.String.CodeUnits as CU import Data.String as S import Data.Validation.Semigroup (V, invalid, toEither) -import App.ResourceRecord (ResourceRecord, emptyRR, Mechanism, Modifier, Qualifier) -import App.ResourceRecord (MechanismType(..), ModifierType(..)) as RR +import App.Type.ResourceRecord (ResourceRecord, emptyRR, Mechanism, Modifier) +import App.Type.ResourceRecord (MechanismType(..), ModifierType(..)) as RR import GenericParser.SomeParsers as SomeParsers import GenericParser.Parser as G import GenericParser.DomainParser.Common (DomainError) as DomainParser @@ -19,7 +19,7 @@ import GenericParser.DomainParser (sub_eof) as DomainParser import GenericParser.IPAddress as IPAddress import GenericParser.RFC5234 as RFC5234 -import App.DKIM as DKIM +import App.Type.DKIM as DKIM -- | **History:** -- | The module once used dedicated types for each type of RR. diff --git a/src/App/WS.purs b/src/App/WS.purs index 504d73f..c64aa92 100644 --- a/src/App/WS.purs +++ b/src/App/WS.purs @@ -32,7 +32,7 @@ import Web.Socket.Event.MessageEvent as WSME import Web.Socket.ReadyState (ReadyState(Connecting, Open, Closing, Closed)) import Web.Socket.WebSocket as WS -import App.LogMessage +import App.Type.LogMessage keepalive = 30000.0 :: Number