From 564488d5fa81f0c5e3e6cc1ba00a11ce457c3e71 Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Mon, 25 Nov 2024 11:45:12 +0100 Subject: [PATCH] chore(day): attempt to fix participant note suggestions --- src/Handler/School/DayTasks.hs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Handler/School/DayTasks.hs b/src/Handler/School/DayTasks.hs index 58b916f86..3fdf78ee0 100644 --- a/src/Handler/School/DayTasks.hs +++ b/src/Handler/School/DayTasks.hs @@ -296,17 +296,24 @@ colParticipantNoteField = sortable (Just "note-tutorial") (i18nCell MsgTutorialN mopt (textField & cfStrip & addDatalist (suggsParticipantNote cid tid)) (fsUniq mkUnique "note-tutorial") (Just note) ) +-- deriving instance (Generic a) => Generic (OptionList a) +-- deriving instance (Binary a, Generic a) => Binary (OptionList a) +-- deriving instance Generic (OptionList Text) +-- deriving instance Binary (OptionList Text) +deriving instance Generic (Option Text) +deriving instance Binary (Option Text) + suggsParticipantNote :: CourseId -> TutorialId -> Handler (OptionList Text) -suggsParticipantNote cid tid = memcachedByHere (Just . Right $ 12 * diffSecond) (cid,tid) $ do -- TODO: better memcached key - let qry = do - (prio, tpn) <- E.from $ TutorialParticipant +suggsParticipantNote cid tid = $(memcachedByHere) (Just . Right $ 12 * diffSecond) (cid,tid) $ runDB $ do -- TODO: better memcached key + let qry :: E.SqlQuery (E.SqlExpr (E.Value Text)) = do + (prio, tpn) <- E.from $ ( do tpa <- E.from $ E.table @TutorialParticipant E.distinct $ pure () E.where_ $ E.isJust (tpa E.^. TutorialParticipantNote) E.&&. tpa E.^. TutorialParticipantTutorial E.==. E.val tid E.limit maxSuggestions - pure (E.val 1, tpa E.^. TutorialParticipantNote) + pure (E.val (1 :: Int64), tpa E.^. TutorialParticipantNote) ) `E.unionAll_` ( do (tpa :& tut) <- E.from $ E.table @TutorialParticipant @@ -328,8 +335,8 @@ suggsParticipantNote cid tid = memcachedByHere (Just . Right $ 12 * diffSecond) ) E.orderBy [E.asc prio, E.asc tpn] E.limit maxSuggestions - pure tpn - mkOptionsE qry E.unValue (text2message . E.unValue) (toPathPiece . E.unValue) + pure $ E.coalesceDefault [tpn] $ E.val "" + mkOptionsE qry (pure . E.unValue) (pure . text2message . E.unValue) (pure . toPathPiece . E.unValue) suggsAttentionNote :: Handler (OptionList Textarea)