From f642b9cccfaa8a1bfb49243642ebfb56a552aa43 Mon Sep 17 00:00:00 2001 From: Steffen Date: Mon, 7 Oct 2024 18:31:02 +0200 Subject: [PATCH] fix(occurrences): room occurrence form works now --- src/Database/Persist/Types/Instances.hs | 2 +- src/Handler/Utils/Form.hs | 18 ++++++++---------- src/Handler/Utils/Form/Occurrences.hs | 12 +++++------- src/Utils/DateTime.hs | 9 +++++---- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/Database/Persist/Types/Instances.hs b/src/Database/Persist/Types/Instances.hs index e32ed5951..1cdf4a70a 100644 --- a/src/Database/Persist/Types/Instances.hs +++ b/src/Database/Persist/Types/Instances.hs @@ -27,7 +27,7 @@ instance Hashable LiteralType instance Binary LiteralType instance NFData LiteralType - + deriving instance Generic PersistValue instance Hashable PersistValue diff --git a/src/Handler/Utils/Form.hs b/src/Handler/Utils/Form.hs index e7713934c..93b707a70 100644 --- a/src/Handler/Utils/Form.hs +++ b/src/Handler/Utils/Form.hs @@ -16,16 +16,12 @@ import Utils.Form import Utils.Files import Handler.Utils.Form.Types - import Handler.Utils.Pandoc - import Handler.Utils.DateTime - import Handler.Utils.I18n - import Handler.Utils.Files - import Handler.Utils.Exam +import Handler.Utils.Memcached import Utils.Term @@ -2352,10 +2348,11 @@ roomReferenceSimpleField = roomReferenceSimpleSuggestions :: HandlerFor UniWorX (OptionList Text) roomReferenceSimpleSuggestions = do - suggsRaw <- runDB [sqlQQ| + suggsRaw :: [Text] <- $(memcachedByHere) (Just $ Right $ 30 * diffSecond) ("rooms-recently-used"::Text) (E.unSingle <<$>> runDB + [sqlQQ| SELECT room FROM ( SELECT DISTINCT ON (room) - j.value #> '{room,text}' AS room + j.value #>> '{room,text}' AS room , t.@{TutorialLastChanged} AS changed FROM ^{Tutorial} AS t , jsonb_array_elements((@{TutorialTime}->'exceptions') || (@{TutorialTime}->'scheduled')) AS j @@ -2364,8 +2361,9 @@ roomReferenceSimpleSuggestions = do WHERE room IS NOT NULL ORDER BY changed DESC LIMIT 7; - |] - return $ mkOptionList $ fmap (\(E.unSingle -> t) -> Option t t t) suggsRaw + |] ) + $logDebugS "Room" $ mconcat suggsRaw + return $ mkOptionList $ fmap (\t -> Option t t t) suggsRaw -- suggs <- liftHandler $ runDBRead $ E.select $ do -- tut <- E.from $ E.table @Tutorial -- return $ tut E.^. tutorialTime E.#>>. ["scheduled","1","room","text"] @@ -2406,7 +2404,7 @@ roomReferenceForm' noneOpt fs mPrev = multiActionAOpts opts opts' fs $ fmap clas Nothing -> pure Nothing Just RoomReferenceSimple' -> wFormToAForm $ do MsgRenderer mr <- getMsgRenderer - fmap (Just . RoomReferenceSimple) <$> wpreq (textField & cfStrip) (fslI MsgRoomReferenceSimpleText & addPlaceholder (mr MsgRoomReferenceSimpleTextPlaceholder) & maybe id (\n -> addName $ n <> "__text") (fsName fs)) (mPrev ^? _Just . _Just . _roomRefText) + fmap (Just . RoomReferenceSimple) <$> wpreq (textField & cfStrip & addDatalist roomReferenceSimpleSuggestions) (fslI MsgRoomReferenceSimpleText & addPlaceholder (mr MsgRoomReferenceSimpleTextPlaceholder) & maybe id (\n -> addName $ n <> "__text") (fsName fs)) (mPrev ^? _Just . _Just . _roomRefText) Just RoomReferenceLink' -> wFormToAForm $ do MsgRenderer mr <- getMsgRenderer roomRefLink' <- wpreq urlField (fslI MsgRoomReferenceLinkLink & addPlaceholder (mr MsgRoomReferenceLinkLinkPlaceholder) & maybe id (\n -> addName $ n <> "__link") (fsName fs)) (mPrev ^? _Just . _Just . _roomRefLink) diff --git a/src/Handler/Utils/Form/Occurrences.hs b/src/Handler/Utils/Form/Occurrences.hs index 9a70af25b..5bc3f5dff 100644 --- a/src/Handler/Utils/Form/Occurrences.hs +++ b/src/Handler/Utils/Form/Occurrences.hs @@ -1,4 +1,4 @@ --- SPDX-FileCopyrightText: 2022 Gregor Kleen ,Sarah Vaupel ,Winnie Ros +-- SPDX-FileCopyrightText: 2022-24 Gregor Kleen ,Sarah Vaupel ,Winnie Ros ,Steffen Jost -- -- SPDX-License-Identifier: AGPL-3.0-or-later @@ -61,9 +61,8 @@ occurrencesAForm (toPathPiece -> miIdent') mPrev = wFormToAForm $ do <$> apreq (selectField' Nothing optionsFinite) (fslI MsgOccurrenceWeekDay & addName (nudge "occur-week-day")) Nothing <*> apreq timeFieldTypeTime (fslI MsgOccurrenceStart & addName (nudge "occur-start")) Nothing <*> apreq timeFieldTypeTime (fslI MsgOccurrenceEnd & addName (nudge "occur-end")) Nothing - -- DEBUG TODO - -- <*> roomReferenceFormOpt (fslI MsgTableTutorialRoom) Nothing - <*> aopt roomReferenceSimpleField (fslI MsgTableTutorialRoom) Nothing + <*> roomReferenceForm' Nothing (fslI MsgTableTutorialRoom & addName (nudge "occur-room")) Nothing + -- <*> aopt roomReferenceSimpleField (fslI MsgTableTutorialRoom & addName (nudge "occur-room")) (Just Nothing) ) ] ) (fslI MsgScheduleRegularKind & addName (nudge "kind")) Nothing @@ -100,9 +99,8 @@ occurrencesAForm (toPathPiece -> miIdent') mPrev = wFormToAForm $ do <$> apreq dayField (fslI MsgDay & addName (nudge "occur-day")) Nothing <*> apreq timeFieldTypeTime (fslI MsgOccurrenceStart & addName (nudge "occur-start")) Nothing <*> apreq timeFieldTypeTime (fslI MsgOccurrenceEnd & addName (nudge "occur-end")) Nothing - -- DEBUG TODO - -- <*> roomReferenceFormOpt (fslI MsgTableTutorialRoom) (Just Nothing) -- still does not work - <*> aopt roomReferenceSimpleField (fslI MsgTableTutorialRoom) Nothing + <*> roomReferenceForm' Nothing (fslI MsgTableTutorialRoom & addName (nudge "occur-room")) Nothing + -- <*> aopt roomReferenceSimpleField (fslI MsgTableTutorialRoom & addName (nudge "occur-room")) Nothing ) , ( ExceptionKindNoOccur , ExceptNoOccur diff --git a/src/Utils/DateTime.hs b/src/Utils/DateTime.hs index 27ba25ecb..5ad9e2de6 100644 --- a/src/Utils/DateTime.hs +++ b/src/Utils/DateTime.hs @@ -16,8 +16,8 @@ module Utils.DateTime , mkDateTimeFormatter , nominalHour, nominalMinute , minNominalYear, avgNominalYear - , diffMinute, diffHour, diffDay - , module Zones + , diffSecond, diffMinute, diffHour, diffDay + , module Zones , day , utctDayMidnight ) where @@ -86,7 +86,7 @@ timeLocaleMap extra@((_, defLocale):_) = do letE [localeMap'] (varE localeMap) compileTime :: ExpQ -- Type UTCTime -compileTime = do +compileTime = do now <- runIO getCurrentTime [e|now|] @@ -166,7 +166,8 @@ avgNominalYear = fromRational $ 365.2425 * toRational nominalDay -- DiffTime -- -------------- -diffMinute, diffHour, diffDay :: DiffTime +diffSecond, diffMinute, diffHour, diffDay :: DiffTime +diffSecond = 1 diffMinute = 60 diffHour = 3600 diffDay = 86400