fix(occurrences): room occurrence form works now

This commit is contained in:
Steffen Jost 2024-10-07 18:31:02 +02:00
parent 72b2b6876b
commit f642b9cccf
4 changed files with 19 additions and 22 deletions

View File

@ -27,7 +27,7 @@ instance Hashable LiteralType
instance Binary LiteralType instance Binary LiteralType
instance NFData LiteralType instance NFData LiteralType
deriving instance Generic PersistValue deriving instance Generic PersistValue
instance Hashable PersistValue instance Hashable PersistValue

View File

@ -16,16 +16,12 @@ import Utils.Form
import Utils.Files import Utils.Files
import Handler.Utils.Form.Types import Handler.Utils.Form.Types
import Handler.Utils.Pandoc import Handler.Utils.Pandoc
import Handler.Utils.DateTime import Handler.Utils.DateTime
import Handler.Utils.I18n import Handler.Utils.I18n
import Handler.Utils.Files import Handler.Utils.Files
import Handler.Utils.Exam import Handler.Utils.Exam
import Handler.Utils.Memcached
import Utils.Term import Utils.Term
@ -2352,10 +2348,11 @@ roomReferenceSimpleField =
roomReferenceSimpleSuggestions :: HandlerFor UniWorX (OptionList Text) roomReferenceSimpleSuggestions :: HandlerFor UniWorX (OptionList Text)
roomReferenceSimpleSuggestions = do roomReferenceSimpleSuggestions = do
suggsRaw <- runDB [sqlQQ| suggsRaw :: [Text] <- $(memcachedByHere) (Just $ Right $ 30 * diffSecond) ("rooms-recently-used"::Text) (E.unSingle <<$>> runDB
[sqlQQ|
SELECT room FROM ( SELECT room FROM (
SELECT DISTINCT ON (room) SELECT DISTINCT ON (room)
j.value #> '{room,text}' AS room j.value #>> '{room,text}' AS room
, t.@{TutorialLastChanged} AS changed , t.@{TutorialLastChanged} AS changed
FROM ^{Tutorial} AS t FROM ^{Tutorial} AS t
, jsonb_array_elements((@{TutorialTime}->'exceptions') || (@{TutorialTime}->'scheduled')) AS j , jsonb_array_elements((@{TutorialTime}->'exceptions') || (@{TutorialTime}->'scheduled')) AS j
@ -2364,8 +2361,9 @@ roomReferenceSimpleSuggestions = do
WHERE room IS NOT NULL WHERE room IS NOT NULL
ORDER BY changed DESC ORDER BY changed DESC
LIMIT 7; 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 -- suggs <- liftHandler $ runDBRead $ E.select $ do
-- tut <- E.from $ E.table @Tutorial -- tut <- E.from $ E.table @Tutorial
-- return $ tut E.^. tutorialTime E.#>>. ["scheduled","1","room","text"] -- 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 Nothing -> pure Nothing
Just RoomReferenceSimple' -> wFormToAForm $ do Just RoomReferenceSimple' -> wFormToAForm $ do
MsgRenderer mr <- getMsgRenderer 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 Just RoomReferenceLink' -> wFormToAForm $ do
MsgRenderer mr <- getMsgRenderer MsgRenderer mr <- getMsgRenderer
roomRefLink' <- wpreq urlField (fslI MsgRoomReferenceLinkLink & addPlaceholder (mr MsgRoomReferenceLinkLinkPlaceholder) & maybe id (\n -> addName $ n <> "__link") (fsName fs)) (mPrev ^? _Just . _Just . _roomRefLink) roomRefLink' <- wpreq urlField (fslI MsgRoomReferenceLinkLink & addPlaceholder (mr MsgRoomReferenceLinkLinkPlaceholder) & maybe id (\n -> addName $ n <> "__link") (fsName fs)) (mPrev ^? _Just . _Just . _roomRefLink)

View File

@ -1,4 +1,4 @@
-- SPDX-FileCopyrightText: 2022 Gregor Kleen <gregor.kleen@ifi.lmu.de>,Sarah Vaupel <vaupel.sarah@campus.lmu.de>,Winnie Ros <winnie.ros@campus.lmu.de> -- SPDX-FileCopyrightText: 2022-24 Gregor Kleen <gregor.kleen@ifi.lmu.de>,Sarah Vaupel <vaupel.sarah@campus.lmu.de>,Winnie Ros <winnie.ros@campus.lmu.de>,Steffen Jost <s.jost@fraport.de>
-- --
-- SPDX-License-Identifier: AGPL-3.0-or-later -- 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 (selectField' Nothing optionsFinite) (fslI MsgOccurrenceWeekDay & addName (nudge "occur-week-day")) Nothing
<*> apreq timeFieldTypeTime (fslI MsgOccurrenceStart & addName (nudge "occur-start")) Nothing <*> apreq timeFieldTypeTime (fslI MsgOccurrenceStart & addName (nudge "occur-start")) Nothing
<*> apreq timeFieldTypeTime (fslI MsgOccurrenceEnd & addName (nudge "occur-end")) Nothing <*> apreq timeFieldTypeTime (fslI MsgOccurrenceEnd & addName (nudge "occur-end")) Nothing
-- DEBUG TODO <*> roomReferenceForm' Nothing (fslI MsgTableTutorialRoom & addName (nudge "occur-room")) Nothing
-- <*> roomReferenceFormOpt (fslI MsgTableTutorialRoom) Nothing -- <*> aopt roomReferenceSimpleField (fslI MsgTableTutorialRoom & addName (nudge "occur-room")) (Just Nothing)
<*> aopt roomReferenceSimpleField (fslI MsgTableTutorialRoom) Nothing
) )
] ]
) (fslI MsgScheduleRegularKind & addName (nudge "kind")) 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 dayField (fslI MsgDay & addName (nudge "occur-day")) Nothing
<*> apreq timeFieldTypeTime (fslI MsgOccurrenceStart & addName (nudge "occur-start")) Nothing <*> apreq timeFieldTypeTime (fslI MsgOccurrenceStart & addName (nudge "occur-start")) Nothing
<*> apreq timeFieldTypeTime (fslI MsgOccurrenceEnd & addName (nudge "occur-end")) Nothing <*> apreq timeFieldTypeTime (fslI MsgOccurrenceEnd & addName (nudge "occur-end")) Nothing
-- DEBUG TODO <*> roomReferenceForm' Nothing (fslI MsgTableTutorialRoom & addName (nudge "occur-room")) Nothing
-- <*> roomReferenceFormOpt (fslI MsgTableTutorialRoom) (Just Nothing) -- still does not work -- <*> aopt roomReferenceSimpleField (fslI MsgTableTutorialRoom & addName (nudge "occur-room")) Nothing
<*> aopt roomReferenceSimpleField (fslI MsgTableTutorialRoom) Nothing
) )
, ( ExceptionKindNoOccur , ( ExceptionKindNoOccur
, ExceptNoOccur , ExceptNoOccur

View File

@ -16,8 +16,8 @@ module Utils.DateTime
, mkDateTimeFormatter , mkDateTimeFormatter
, nominalHour, nominalMinute , nominalHour, nominalMinute
, minNominalYear, avgNominalYear , minNominalYear, avgNominalYear
, diffMinute, diffHour, diffDay , diffSecond, diffMinute, diffHour, diffDay
, module Zones , module Zones
, day , day
, utctDayMidnight , utctDayMidnight
) where ) where
@ -86,7 +86,7 @@ timeLocaleMap extra@((_, defLocale):_) = do
letE [localeMap'] (varE localeMap) letE [localeMap'] (varE localeMap)
compileTime :: ExpQ -- Type UTCTime compileTime :: ExpQ -- Type UTCTime
compileTime = do compileTime = do
now <- runIO getCurrentTime now <- runIO getCurrentTime
[e|now|] [e|now|]
@ -166,7 +166,8 @@ avgNominalYear = fromRational $ 365.2425 * toRational nominalDay
-- DiffTime -- -- DiffTime --
-------------- --------------
diffMinute, diffHour, diffDay :: DiffTime diffSecond, diffMinute, diffHour, diffDay :: DiffTime
diffSecond = 1
diffMinute = 60 diffMinute = 60
diffHour = 3600 diffHour = 3600
diffDay = 86400 diffDay = 86400