feat(schedule): omit regular occurrences of inactive terms
This commit is contained in:
parent
2ea234259b
commit
38fc5fa986
@ -31,17 +31,18 @@ slotToDisplayTime t = formatTimeRangeW SelFormatTime (TimeOfDay t 0 0) $ Just $
|
||||
|
||||
|
||||
-- TODO: implement weekOffset
|
||||
weekSchedule :: UserId
|
||||
-> Maybe Int -- weekOffset
|
||||
-> Widget
|
||||
weekSchedule :: UserId -> Maybe Int -> Widget
|
||||
weekSchedule uid _weekOffset = do
|
||||
now <- liftIO getCurrentTime
|
||||
ata <- getSessionActiveAuthTags
|
||||
|
||||
-- TODO: single runDB for all fetches below?
|
||||
-- TODO: filter by activeTerm only for regular occurrences, i.e. not for exceptions
|
||||
|
||||
activeTerms <- liftHandler . runDB $ E.select $ E.from $ \term -> do
|
||||
E.where_ $ term E.^. TermActive
|
||||
return $ term E.^. TermId
|
||||
|
||||
-- TODO: fetch course events for this week only:
|
||||
-- TODO: fetch course events for this week only?
|
||||
courseEvents'' <- liftHandler . runDB $ E.select $ E.from $ \(course `E.InnerJoin` courseEvent) -> do
|
||||
E.on $ course E.^. CourseId E.==. courseEvent E.^. CourseEventCourse
|
||||
--E.where_ $ E.exists $ E.from $ \term -> E.where_ $
|
||||
@ -77,13 +78,16 @@ weekSchedule uid _weekOffset = do
|
||||
|
||||
let
|
||||
courseEventToScheduleEntries :: (Entity Course, Entity CourseEvent) -> [ScheduleEntry]
|
||||
courseEventToScheduleEntries (seCourse, Entity _ CourseEvent{courseEventType,courseEventRoom,courseEventTime=Occurrences{..}}) =
|
||||
let seType = SETCourseEvent { setceType = courseEventType }
|
||||
seRoom = Just courseEventRoom
|
||||
scheduleds = Set.toList occurrencesScheduled <&> \scheduled ->
|
||||
let seOccurrence = Right scheduled in ScheduleEntry{..}
|
||||
exceptions = Set.toList occurrencesExceptions <&> \exception ->
|
||||
let seOccurrence = Left exception in ScheduleEntry{..}
|
||||
courseEventToScheduleEntries (seCourse@(Entity _ Course{..}), Entity _ CourseEvent{courseEventType,courseEventRoom,courseEventTime=Occurrences{..}}) =
|
||||
let seType = SETCourseEvent { setceType = courseEventType }
|
||||
seRoom = Just courseEventRoom
|
||||
scheduleds
|
||||
-- omit regular occurrences if the course's term is not currently active
|
||||
| not (courseTerm `elem` (E.unValue <$> activeTerms)) = mempty
|
||||
| otherwise = Set.toList occurrencesScheduled <&> \scheduled ->
|
||||
let seOccurrence = Right scheduled in ScheduleEntry{..}
|
||||
exceptions = Set.toList occurrencesExceptions <&> \exception ->
|
||||
let seOccurrence = Left exception in ScheduleEntry{..}
|
||||
in scheduleds <> exceptions
|
||||
|
||||
seOccurrenceIsInSlot :: Day -> TimeSlot -> ScheduleEntryOccurrence -> Bool
|
||||
@ -144,7 +148,7 @@ weekSchedule uid _weekOffset = do
|
||||
, (MsgScheduleWeekDaySunday , "sun")
|
||||
]
|
||||
|
||||
formatOccurrenceW :: Either OccurrenceException OccurrenceSchedule -> Widget
|
||||
formatOccurrenceW :: ScheduleEntryOccurrence -> Widget
|
||||
formatOccurrenceW = \case
|
||||
Right ScheduleWeekly{..} -> [whamlet| _{MsgScheduleTime}: |] <> formatTimeRangeW SelFormatTime scheduleStart (Just scheduleEnd)
|
||||
Left ExceptOccur{..} -> [whamlet| _{MsgScheduleOccur}: |] <> formatTimeRangeW SelFormatDateTime (LocalTime exceptDay exceptStart) (Just (LocalTime exceptDay exceptEnd))
|
||||
|
||||
Reference in New Issue
Block a user