From 9b14a727c073b360cb3434c9cff4cbdd6513fdac Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Wed, 28 Sep 2022 16:02:42 +0200 Subject: [PATCH] chore(lms): fix lms filtering by composite notification date --- src/Handler/LMS.hs | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/src/Handler/LMS.hs b/src/Handler/LMS.hs index 5689c9a01..5830b030a 100644 --- a/src/Handler/LMS.hs +++ b/src/Handler/LMS.hs @@ -369,19 +369,24 @@ mkLmsTable (Entity qid quali) acts restrict cols psValidator = do , single ("lms-ident" , FilterColumn . E.mkContainsFilterWith (Just . LmsIdent) $ views (to queryLmsUser) (E.?. LmsUserIdent)) -- , single ("lms-status" , FilterColumn . E.mkExactFilterLast $ views (to queryLmsUser) ((E.>=. E.val nowaday) . (E.^. LmsUserStatus))) -- LmsStatus cannot be filtered easily within the DB , single ("validity" , FilterColumn . E.mkExactFilterLast $ views (to queryQualUser) ((E.>=. E.val nowaday) . (E.^. QualificationUserValidUntil))) - , single ("renewal-due" , FilterColumn $ \(view (to queryQualUser) -> quser) criterion -> + , single ("renewal-due" , FilterColumn $ \(queryQualUser -> quser) criterion -> if | Just renewal <- mbRenewal , Just True <- getLast criterion -> quser E.^. QualificationUserValidUntil E.<=. E.val renewal E.&&. quser E.^. QualificationUserValidUntil E.>=. E.val nowaday | otherwise -> E.true ) - , single ("lms-notified", FilterColumn . E.mkExactFilterLast $ views (to queryLmsUser) (E.isJust . (E.?. LmsUserNotified))) - --, single ("lms-notified", FilterColumn $ \(view (to queryLmsUser) -> luser) criterion -> - -- case getLast criterion of - -- Just True -> E.isJust $ luser E.?. LmsUserNotified - -- Just False -> E.isNothing $ luser E.?. LmsUserNotified - -- Nothing -> E.true - -- ) + -- , single ("lms-notified", FilterColumn . E.mkExactFilterLast $ views (to queryLmsUser) (E.isJust . (E.?. LmsUserNotified))) + , single ("lms-notified", FilterColumn $ \row criterion -> + let luser = queryLmsUser row + pjob = queryPrintJob row + in + case getLast criterion of + Just True -> E.isJust (luser E.?. LmsUserNotified) + E.&&. (E.isNothing (pjob E.?. PrintJobId) E.||. E.isJust (pjob E.?. PrintJobAcknowledged)) + Just False -> E.isNothing (luser E.?. LmsUserNotified) + E.||. (E.isJust (pjob E.?. PrintJobId) E.&&. E.isNothing (pjob E.?. PrintJobAcknowledged)) + Nothing -> E.true + ) ] dbtFilterUI mPrev = mconcat [ fltrUserNameEmailHdrUI MsgLmsUser mPrev @@ -478,14 +483,22 @@ postLmsR sid qsh = do , sortable (Just "lms-received") (i18nLms MsgTableLmsReceived) $ \(preview $ resultLmsUser . _entityVal . _lmsUserReceived -> d) -> foldMap dateTimeCell $ join d --, sortable (Just "lms-notified") (i18nLms MsgTableLmsNotified) $ \(preview $ resultLmsUser . _entityVal . _lmsUserNotified -> d) -> foldMap dateTimeCell $ join d , sortable (Just "lms-notified") (i18nLms MsgTableLmsNotified) $ \row -> - let notifyDate = row ^? resultLmsUser . _entityVal . _lmsUserNotified - letterSent = isJust (row ^? resultPrintJob . _entityKey) - letterDate = row ^? resultPrintJob . _entityVal . _printJobAcknowledged - cIcon = iconFixedCell $ iconLetterOrEmail letterSent - cDate = if letterSent - then foldMap dateTimeCell (join letterDate) - else foldMap dateTimeCell (join notifyDate) - in cIcon <> spacerCell <> cDate + -- 4 Cases: + -- - No notification: LmsUserNotified == Nothing + -- - Email sent : LmsUserNotified == Just _ && PrintJobId == Nothing + -- - Letter printed : LmsUserNotified == Just _ && PrintJobId == Just _ + -- - Letter sent : LmsUserNotified == Just _ && PrintJobId == Just _ && PrintJobAcknowledged == Just _ + let notifyDate = join $ row ^? resultLmsUser . _entityVal . _lmsUserNotified + letterDate = join $ row ^? resultPrintJob . _entityVal . _printJobAcknowledged + letterSent = isJust (row ^? resultPrintJob . _entityKey) -- note the difference to letterDate! + notNotified = isNothing notifyDate + cIcon = iconFixedCell $ iconLetterOrEmail letterSent + cDate = if letterSent + then foldMap dateTimeCell letterDate + else foldMap dateTimeCell notifyDate + in if notNotified + then mempty + else cIcon <> spacerCell <> cDate , sortable (Just "lms-ended") (i18nLms MsgTableLmsEnded) $ \(preview $ resultLmsUser . _entityVal . _lmsUserEnded -> d) -> foldMap dateTimeCell $ join d ] where