From 400a3449c5e68994ba0e872b590bef9c0acaf728 Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Thu, 23 Nov 2023 13:27:57 +0100 Subject: [PATCH] refactor(firm): fix build too --- .../uniworx/categories/firm/de-de-formal.msg | 2 ++ messages/uniworx/categories/firm/en-eu.msg | 2 ++ src/Handler/Firm.hs | 2 ++ src/Handler/Profile.hs | 8 +++---- src/Model/Types/Markup.hs | 7 ++++++ src/Utils.hs | 11 +++++---- templates/firm-contact-info.hamlet | 23 +++++++++++++++++++ templates/firm-users.hamlet | 13 +---------- .../i18n/firm-supervisors/de-de-formal.hamlet | 16 ++++--------- templates/i18n/firm-supervisors/en-eu.hamlet | 16 ++++--------- 10 files changed, 55 insertions(+), 45 deletions(-) create mode 100644 templates/firm-contact-info.hamlet diff --git a/messages/uniworx/categories/firm/de-de-formal.msg b/messages/uniworx/categories/firm/de-de-formal.msg index 8c9cf7a8e..5d81a2b03 100644 --- a/messages/uniworx/categories/firm/de-de-formal.msg +++ b/messages/uniworx/categories/firm/de-de-formal.msg @@ -3,6 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-or-later FirmAssociates: Firmenangehörige +FirmContact: Firmenkontakt +FirmNoContact: Keine allgemeinen Kontaktinformationen bekannt. FirmEmail: Allgemeine Email FirmAddress: Postanschrift FirmDefaultPreferenceInfo: Diese Voreinstellungen gelten nur für neue Firmenangehörige diff --git a/messages/uniworx/categories/firm/en-eu.msg b/messages/uniworx/categories/firm/en-eu.msg index 0d7ef77eb..250b9ca38 100644 --- a/messages/uniworx/categories/firm/en-eu.msg +++ b/messages/uniworx/categories/firm/en-eu.msg @@ -3,6 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-or-later FirmAssociates: Company associated users +FirmContact: Company Contact +FirmNoContact: No general contact information known. FirmEmail: General company email FirmAddress: Postal address FirmDefaultPreferenceInfo: Default setting for new company associates only diff --git a/src/Handler/Firm.hs b/src/Handler/Firm.hs index 9e4c7655d..9442d841a 100644 --- a/src/Handler/Firm.hs +++ b/src/Handler/Firm.hs @@ -806,6 +806,7 @@ postFirmUsersR fsh = do siteLayout (citext2widget companyName) $ do setTitle $ toHtml $ CI.original companyShorthand <> "-" <> tshow companyAvsId + let firmContactInfo = $(widgetFile "firm-contact-info") $(widgetFile "firm-users") @@ -1053,6 +1054,7 @@ postFirmSupersR fsh = do siteLayout (citext2widget fsh) $ do setTitle $ citext2Html $ fsh <> " Supers" + let firmContactInfo = $(widgetFile "firm-contact-info") $(i18nWidgetFile "firm-supervisors") diff --git a/src/Handler/Profile.hs b/src/Handler/Profile.hs index a92c54571..3a0103c58 100644 --- a/src/Handler/Profile.hs +++ b/src/Handler/Profile.hs @@ -475,11 +475,11 @@ serveProfileR (uid, user@User{..}) = do , UserWarningDays =. stgWarningDays , UserNotificationSettings =. stgNotificationSettings , UserShowSex =. stgShowSex - , UserPinPassword =. stgPinPassword -- TODO & canonical - , UserPostAddress =. stgPostAddress -- TODO & canonical + , UserPinPassword =. (stgPinPassword & canonical) + , UserPostAddress =. (stgPostAddress & canonical) , UserPrefersPostal =. stgPrefersPostal - , UserTelephone =. stgTelephone & canonical - , UserMobile =. stgMobile & canonical + , UserTelephone =. (stgTelephone & canonical) + , UserMobile =. (stgMobile & canonical) , UserExamOfficeGetSynced =. (stgExamOfficeSettings & eosettingsGetSynced) , UserExamOfficeGetLabels =. (stgExamOfficeSettings & eosettingsGetLabels) ] diff --git a/src/Model/Types/Markup.hs b/src/Model/Types/Markup.hs index c5555ceba..0715b65b5 100644 --- a/src/Model/Types/Markup.hs +++ b/src/Model/Types/Markup.hs @@ -50,6 +50,13 @@ data StoredMarkup = StoredMarkup deriving (Read, Show, Generic) deriving anyclass (Binary, Hashable, NFData) +instance Canonical (Maybe StoredMarkup) where + canonical Nothing = Nothing + canonical r@(Just s@StoredMarkup{..}) = let mi' = LT.strip markupInput in if + | LT.null mi' -> Nothing + | markupInput == mi' -> r + | otherwise -> Just s{markupInput = mi'} + htmlToStoredMarkup :: Html -> StoredMarkup htmlToStoredMarkup html = StoredMarkup { markupInputFormat = MarkupHtml diff --git a/src/Utils.hs b/src/Utils.hs index b879a2164..324f71aa7 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -1987,8 +1987,9 @@ instance {-# OVERLAPPABLE #-} (Canonical mono, MonoFoldable mono, Eq mono) => Ca instance (Ord a, Canonical a) => Canonical (Set a) where canonical = Set.map canonical -instance Canonical (Maybe Text) where - canonical Nothing = Nothing - canonical (Just t) = - let t' = Text.strip t - in if Text.null t' then Nothing else Just t' +instance Canonical (Maybe Text) where -- a split into Canonical Text and Canonical a => Maybe seems nicer, but the latter instance would be troublesome + canonical Nothing = Nothing + canonical r@(Just t) = let t' = Text.strip t in if + | Text.null t' -> Nothing + | t == t' -> r + | otherwise -> Just t' diff --git a/templates/firm-contact-info.hamlet b/templates/firm-contact-info.hamlet new file mode 100644 index 000000000..8aea13ab1 --- /dev/null +++ b/templates/firm-contact-info.hamlet @@ -0,0 +1,23 @@ +$newline never + +$# SPDX-FileCopyrightText: 2023 Steffen Jost +$# +$# SPDX-License-Identifier: AGPL-3.0-or-later + +
+

_{MsgFirmContact} +
+ $maybe fem <- companyEmail +
+ _{MsgFirmEmail} #{iconLetterOrEmail False} +
+ #{mailtoHtml fem} + $maybe addr <- companyPostAddress +
+ _{MsgFirmAddress} #{iconLetterOrEmail True} +
+ #{addr} + $nothing + $maybe _ <- companyEmail + $nothing + _{MsgFirmNoContact} diff --git a/templates/firm-users.hamlet b/templates/firm-users.hamlet index 2346ac4dd..19c41bb64 100644 --- a/templates/firm-users.hamlet +++ b/templates/firm-users.hamlet @@ -4,18 +4,7 @@ $# SPDX-FileCopyrightText: 2023 Steffen Jost $# $# SPDX-License-Identifier: AGPL-3.0-or-later -
-
- $maybe fem <- companyEmail -
- _{MsgFirmEmail} #{iconLetterOrEmail False} -
- #{mailtoHtml fem} - $maybe addr <- companyPostAddress -
- _{MsgFirmAddress} #{iconLetterOrEmail True} -
- #{addr} +^{firmContactInfo}
diff --git a/templates/i18n/firm-supervisors/de-de-formal.hamlet b/templates/i18n/firm-supervisors/de-de-formal.hamlet index d81248e80..5e432e780 100644 --- a/templates/i18n/firm-supervisors/de-de-formal.hamlet +++ b/templates/i18n/firm-supervisors/de-de-formal.hamlet @@ -9,19 +9,11 @@ $# SPDX-License-Identifier: AGPL-3.0-or-later Daraus folgt zum Beispiel, dass wenn x ein Standard-Ansprechpartner für Firma a ist und wenn y sowohl Firma a als auch b angehört, dass dann x als firmenfremd in der Liste der Ansprechpartner von Firma b angezeigt wird. -
-
- $maybe fem <- companyEmail -
- _{MsgFirmEmail} #{iconLetterOrEmail False} -
- #{mailtoHtml fem} - $maybe addr <- companyPostAddress -
- _{MsgFirmAddress} #{iconLetterOrEmail True} -
- #{addr} + +^{firmContactInfo} +
^{fsprTable} +
^{addSuperForm} \ No newline at end of file diff --git a/templates/i18n/firm-supervisors/en-eu.hamlet b/templates/i18n/firm-supervisors/en-eu.hamlet index 400fc543b..b34a75431 100644 --- a/templates/i18n/firm-supervisors/en-eu.hamlet +++ b/templates/i18n/firm-supervisors/en-eu.hamlet @@ -8,19 +8,11 @@ $# SPDX-License-Identifier: AGPL-3.0-or-later Note that supervision is company independent. For example, if x is a regular supervisor for company a and y belongs to companies a and b, then x will be listed as a foreign supervisor for company b. -
-
- $maybe fem <- companyEmail -
- _{MsgFirmEmail} #{iconLetterOrEmail False} -
- #{mailtoHtml fem} - $maybe addr <- companyPostAddress -
- _{MsgFirmAddress} #{iconLetterOrEmail True} -
- #{addr} + +^{firmContactInfo} +
^{fsprTable} +
^{addSuperForm}