diff options
-rw-r--r-- | src/server/Model/Message/Key.hs | 1 | ||||
-rw-r--r-- | src/server/Model/Message/Translations.hs | 5 | ||||
-rw-r--r-- | src/server/Resource.hs | 6 | ||||
-rw-r--r-- | src/server/View/Mail/WeeklyReport.hs | 18 |
4 files changed, 20 insertions, 10 deletions
diff --git a/src/server/Model/Message/Key.hs b/src/server/Model/Message/Key.hs index e64cfb5..d00d8b8 100644 --- a/src/server/Model/Message/Key.hs +++ b/src/server/Model/Message/Key.hs @@ -131,6 +131,7 @@ data Key = -- Weekly report | WeeklyReport + | WeeklyReportEmpty | PaymentCreated | PaymentsCreated | PaymentEdited diff --git a/src/server/Model/Message/Translations.hs b/src/server/Model/Message/Translations.hs index cf11a5e..23e3a6c 100644 --- a/src/server/Model/Message/Translations.hs +++ b/src/server/Model/Message/Translations.hs @@ -492,6 +492,11 @@ m l WeeklyReport = English -> "Weekly report" French -> "Rapport hebdomadaire" +m l WeeklyReportEmpty = + case l of + English -> "No activity the previous week." + French -> "Pas d'activité la semaine passée." + m l PaymentCreated = case l of English -> "{1} payment created:" diff --git a/src/server/Resource.hs b/src/server/Resource.hs index 4dd8615..8999b77 100644 --- a/src/server/Resource.hs +++ b/src/server/Resource.hs @@ -4,6 +4,7 @@ module Resource , editedAt , deletedAt , Status(..) + , statuses , groupByStatus , statusDuring ) where @@ -22,7 +23,10 @@ data Status = Created | Edited | Deleted - deriving (Eq, Show, Read, Ord) + deriving (Eq, Show, Read, Ord, Enum, Bounded) + +statuses :: [Status] +statuses = [minBound..] groupByStatus :: Resource a => UTCTime -> UTCTime -> [a] -> Map Status [a] groupByStatus start end resources = diff --git a/src/server/View/Mail/WeeklyReport.hs b/src/server/View/Mail/WeeklyReport.hs index b333891..f76fb0e 100644 --- a/src/server/View/Mail/WeeklyReport.hs +++ b/src/server/View/Mail/WeeklyReport.hs @@ -14,7 +14,7 @@ import Data.Time.Clock (UTCTime) import Data.Time.Calendar (Day, toGregorian) import Data.List (sortOn) -import Resource (Status(..), groupByStatus) +import Resource (Status(..), groupByStatus, statuses) import Database.Persist (Entity, entityVal) @@ -44,14 +44,14 @@ mail conf users payments incomes start end = body :: Conf -> [Entity User] -> Map Status [Payment] -> Map Status [Income] -> Text body conf users paymentsByStatus incomesByStatus = - T.intercalate "\n\n" . catMaybes $ - [ paymentSection Created conf users <$> M.lookup Created paymentsByStatus - , paymentSection Edited conf users <$> M.lookup Edited paymentsByStatus - , paymentSection Deleted conf users <$> M.lookup Deleted paymentsByStatus - , incomeSection Created conf users <$> M.lookup Created incomesByStatus - , incomeSection Edited conf users <$> M.lookup Edited incomesByStatus - , incomeSection Deleted conf users <$> M.lookup Deleted incomesByStatus - ] + if M.null paymentsByStatus && M.null incomesByStatus + then + getMessage K.WeeklyReportEmpty + else + T.intercalate "\n\n" . catMaybes . concat $ + [ map (\s -> paymentSection s conf users <$> M.lookup s paymentsByStatus) statuses + , map (\s -> incomeSection s conf users <$> M.lookup s incomesByStatus) statuses + ] paymentSection :: Status -> Conf -> [Entity User] -> [Payment] -> Text paymentSection status conf users payments = |